Skip to content

Commit d930691

Browse files
committed
simply again, separation between state and group is not for the module solve
1 parent 753b93f commit d930691

File tree

5 files changed

+19
-39
lines changed

5 files changed

+19
-39
lines changed

plugwise_usb/api.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,7 @@ class NodeFeature(str, Enum):
5353
RELAY = "relay"
5454
RELAY_INIT = "relay_init"
5555
RELAY_LOCK = "relay_lock"
56-
SWITCH_GROUP_1 = "switch_group_1"
57-
SWITCH_GROUP_2 = "switch_group_2"
56+
SWITCH = "switch"
5857
SENSE = "sense"
5958
TEMPERATURE = "temperature"
6059

@@ -87,8 +86,7 @@ class NodeType(Enum):
8786
NodeFeature.MOTION_CONFIG,
8887
NodeFeature.TEMPERATURE,
8988
NodeFeature.SENSE,
90-
NodeFeature.SWITCH_GROUP_1,
91-
NodeFeature.SWITCH_GROUP_2,
89+
NodeFeature.SWITCH,
9290
)
9391

9492

plugwise_usb/nodes/helpers/firmware.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,7 @@ class SupportedVersions(NamedTuple):
168168
NodeFeature.RELAY_LOCK: 2.0,
169169
NodeFeature.MOTION: 2.0,
170170
NodeFeature.MOTION_CONFIG: 2.0,
171-
NodeFeature.SWITCH_GROUP_1: 2.0,
172-
NodeFeature.SWITCH_GROUP_2: 2.0,
171+
NodeFeature.SWITCH: 2.0,
173172
}
174173

175174
# endregion

plugwise_usb/nodes/node.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ def relay_lock(self) -> RelayLock:
315315
@raise_not_loaded
316316
def switch(self) -> bool:
317317
"""Switch button value."""
318-
if NodeFeature.SWITCH_GROUP_1 not in self._features:
318+
if NodeFeature.SWITCH not in self._features:
319319
raise FeatureError(f"Switch value is not supported for node {self.mac}")
320320
raise NotImplementedError()
321321

plugwise_usb/nodes/switch.py

Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@ def __init__(
3636
"""Initialize Scan Device."""
3737
super().__init__(mac, address, controller, loaded_callback)
3838
self._switch_subscription: Callable[[], None] | None = None
39-
self._switch_group_1 = SwitchGroup()
40-
self._switch_group_2 = SwitchGroup()
39+
self._switch = SwitchGroup()
4140

4241
async def load(self) -> bool:
4342
"""Load and activate Switch node features."""
@@ -55,8 +54,7 @@ async def load(self) -> bool:
5554
NodeFeature.BATTERY,
5655
NodeFeature.INFO,
5756
NodeFeature.PING,
58-
NodeFeature.SWITCH_GROUP_1,
59-
NodeFeature.SWITCH_GROUP_2,
57+
NodeFeature.SWITCH,
6058
),
6159
)
6260
if await self.initialize():
@@ -91,7 +89,7 @@ async def unload(self) -> None:
9189
@raise_not_loaded
9290
def switch(self) -> bool:
9391
"""Current state of switch."""
94-
return bool(self._switch_group_1.state)
92+
return bool(self._switch.state)
9593

9694
# endregion
9795

@@ -118,22 +116,13 @@ async def _switch_state_update(
118116
self.name,
119117
switch_state,
120118
)
121-
if switch_group == 1:
122-
self._switch_group_1.state = switch_state
123-
self._switch_group_1.group = switch_group
124-
self._switch_group_1.timestampe = timestamp
119+
self._switch.state = switch_state
120+
self._switch.group = switch_group
121+
self._switch.timestampe = timestamp
125122

126-
await self.publish_feature_update_to_subscribers(
127-
NodeFeature.SWITCH_GROUP_1, self._switch_group_1
128-
)
129-
elif switch_group == 2:
130-
self._switch_group_2.state = switch_state
131-
self._switch_group_2.group = switch_group
132-
self._switch_group_2.timestampe = timestamp
133-
134-
await self.publish_feature_update_to_subscribers(
135-
NodeFeature.SWITCH_GROUP_2, self._switch_group_2
136-
)
123+
await self.publish_feature_update_to_subscribers(
124+
NodeFeature.SWITCH, self._switch
125+
)
137126

138127
@raise_not_loaded
139128
async def get_state(self, features: tuple[NodeFeature]) -> dict[NodeFeature, Any]:
@@ -152,10 +141,8 @@ async def get_state(self, features: tuple[NodeFeature]) -> dict[NodeFeature, Any
152141
)
153142

154143
match feature:
155-
case NodeFeature.SWITCH_GROUP_1:
156-
states[NodeFeature.SWITCH_GROUP_1] = self._switch_group_1
157-
case NodeFeature.SWITCH_GROUP_2:
158-
states[NodeFeature.SWITCH_GROUP_2] = self._switch_group_2
144+
case NodeFeature.SWITCH:
145+
states[NodeFeature.SWITCH] = self._switch
159146
case _:
160147
state_result = await super().get_state((feature,))
161148
states[feature] = state_result[feature]

tests/test_usb.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2363,8 +2363,7 @@ async def load_callback(event: pw_api.NodeEvent, mac: str) -> None: # type: ign
23632363
pw_api.NodeFeature.BATTERY,
23642364
pw_api.NodeFeature.INFO,
23652365
pw_api.NodeFeature.PING,
2366-
pw_api.NodeFeature.SWITCH_GROUP_1,
2367-
pw_api.NodeFeature.SWITCH_GROUP_2,
2366+
pw_api.NodeFeature.SWITCH,
23682367
)
23692368
)
23702369

@@ -2373,8 +2372,7 @@ async def load_callback(event: pw_api.NodeEvent, mac: str) -> None: # type: ign
23732372
pw_api.NodeFeature.AVAILABLE,
23742373
pw_api.NodeFeature.BATTERY,
23752374
pw_api.NodeFeature.INFO,
2376-
pw_api.NodeFeature.SWITCH_GROUP_1,
2377-
pw_api.NodeFeature.SWITCH_GROUP_2,
2375+
pw_api.NodeFeature.SWITCH,
23782376
)
23792377
)
23802378
assert not state[pw_api.NodeFeature.AVAILABLE].state
@@ -2635,17 +2633,15 @@ async def test_node_discovery_and_load( # noqa: PLR0915
26352633
pw_api.NodeFeature.BATTERY,
26362634
pw_api.NodeFeature.INFO,
26372635
pw_api.NodeFeature.PING,
2638-
pw_api.NodeFeature.SWITCH_GROUP_1,
2639-
pw_api.NodeFeature.SWITCH_GROUP_2,
2636+
pw_api.NodeFeature.SWITCH,
26402637
)
26412638
)
26422639
state = await stick.nodes["8888888888888888"].get_state(
26432640
(
26442641
pw_api.NodeFeature.AVAILABLE,
26452642
pw_api.NodeFeature.BATTERY,
26462643
pw_api.NodeFeature.INFO,
2647-
pw_api.NodeFeature.SWITCH_GROUP_1,
2648-
pw_api.NodeFeature.SWITCH_GROUP_2,
2644+
pw_api.NodeFeature.SWITCH,
26492645
)
26502646
)
26512647
assert state[pw_api.NodeFeature.AVAILABLE].state

0 commit comments

Comments
 (0)