Skip to content

Commit 470cea3

Browse files
committed
Add StickInitShortResponse
1 parent 7e036cc commit 470cea3

1 file changed

Lines changed: 54 additions & 21 deletions

File tree

plugwise_usb/messages/responses.py

Lines changed: 54 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -409,8 +409,45 @@ def __init__(self, timestamp: datetime | None = None) -> None:
409409
self._params += [self.image_timestamp]
410410

411411

412+
class StickInitShortResponse(PlugwiseResponse):
413+
"""Returns the configuration and status of the USB-Stick - no network.
414+
415+
Supported protocols : 1.0, 2.0
416+
Response to request : StickInitRequest
417+
"""
418+
419+
def __init__(self) -> None:
420+
"""Initialize StickInitShortResponse message object."""
421+
super().__init__(b"0011")
422+
self._unknown1 = Int(0, length=2)
423+
self._network_online = Int(0, length=2)
424+
self._params += [
425+
self._unknown1,
426+
self._network_online,
427+
]
428+
429+
@property
430+
def mac_network_controller(self) -> str | None:
431+
"""Return the mac of the network controller (Circle+)."""
432+
return None
433+
434+
@property
435+
def network_id(self) -> int | None:
436+
"""Return network ID."""
437+
return None
438+
439+
@property
440+
def network_online(self) -> bool:
441+
"""Return state of network."""
442+
return self._network_online.value == 1
443+
444+
def __repr__(self) -> str:
445+
"""Convert request into writable str."""
446+
return f"{super().__repr__()[:-1]}, network_controller={self.mac_network_controller}, network_online={self.network_online})"
447+
448+
412449
class StickInitResponse(PlugwiseResponse):
413-
"""Returns the configuration and status of the USB-Stick.
450+
"""Returns the configuration and status of the USB-Stick - network online.
414451
415452
Optional:
416453
- circle_plus_mac
@@ -426,37 +463,26 @@ def __init__(self) -> None:
426463
super().__init__(b"0011")
427464
self._unknown1 = Int(0, length=2)
428465
self._network_online = Int(0, length=2)
466+
self._mac_nc = String(None, length=16)
467+
self._network_id = Int(0, 4, False)
468+
self._unknown2 = Int(0, length=2)
429469
self._params += [
430470
self._unknown1,
431471
self._network_online,
472+
self._mac_nc,
473+
self._network_id,
474+
self._unknown2,
432475
]
433-
self._mac_nc = None
434-
self._network_id = None
435-
# if self._network_online == 1:
436-
# self._mac_nc = String(None, length=16)
437-
# self._network_id = Int(0, 4, False)
438-
# self._unknown2 = Int(0, length=2)
439-
# self._params += [
440-
# self._unknown1,
441-
# self._network_online,
442-
# self._mac_nc,
443-
# self._network_id,
444-
# self._unknown2,
445-
# ]
446476

447477
@property
448-
def mac_network_controller(self) -> str | None:
478+
def mac_network_controller(self) -> str:
449479
"""Return the mac of the network controller (Circle+)."""
450480
# Replace first 2 characters by 00 for mac of circle+ node
451-
if self._mac_nc is None:
452-
return None
453481
return "00" + self._mac_nc.value[2:]
454482

455483
@property
456-
def network_id(self) -> int | None:
484+
def network_id(self) -> int:
457485
"""Return network ID."""
458-
if self._network_id is None:
459-
return None
460486
return self._network_id.value
461487

462488
@property
@@ -1003,8 +1029,15 @@ def get_message_object( # noqa: C901 PLR0911 PLR0912
10031029
return NodePingResponse()
10041030
if identifier == b"0010":
10051031
return NodeImageValidationResponse()
1032+
1033+
# 0011 has two formats
10061034
if identifier == b"0011":
1007-
return StickInitResponse()
1035+
if length == 20:
1036+
return StickInitShortResponse()
1037+
if length == 42:
1038+
return StickInitResponse()
1039+
return None
1040+
10081041
if identifier == b"0013":
10091042
return CirclePowerUsageResponse()
10101043
if identifier == b"0015":

0 commit comments

Comments
 (0)