Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/petretiandrea/plugp100 into…
Browse files Browse the repository at this point in the history
… main
  • Loading branch information
petretiandrea committed Dec 10, 2023
2 parents 5359c12 + a12c335 commit 3a347e2
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 8 deletions.
2 changes: 1 addition & 1 deletion plugp100/api/hub/hub_device_tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class DeviceRemoved:

class HubConnectedDeviceTracker(StateTracker[Set[str], HubDeviceEvent]):
def __init__(self, logger: Logger = None):
super().__init__(logger)
super().__init__({}, logger)

def _compute_state_changes(
self, new_state: Set[str], last_state: Optional[Set[str]]
Expand Down
2 changes: 1 addition & 1 deletion plugp100/api/hub/s200b_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ async def _poll_event_logs(

class _EventLogsStateTracker(StateTracker[TriggerLogResponse[S200BEvent], S200BEvent]):
def __init__(self, debounce_millis: int, logger: Logger = None):
super().__init__(logger)
super().__init__(logger=logger)
self._debounce_millis = debounce_millis

def _compute_state_changes(
Expand Down
2 changes: 1 addition & 1 deletion plugp100/api/light_effect.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
class LightEffect:
id: str
name: str
brightness: int
display_colors: List[List[int]]
enable: int
brightness: int = (100,)
bAdjusted: Optional[int] = None
brightness_range: List[int] = dataclasses.field(default_factory=list)
backgrounds: List[List[int]] = dataclasses.field(default_factory=list)
Expand Down
4 changes: 2 additions & 2 deletions plugp100/common/state_tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@


class StateTracker(Generic[State, StateChange]):
def __init__(self, logger: Logger = None):
self._last_state: Optional[State] = None
def __init__(self, initial_state: Optional[State] = None, logger: Logger = None):
self._last_state: Optional[State] = initial_state
self._change_queue = asyncio.Queue()
self._logger = logger if logger is not None else logging.getLogger("StateTracker")

Expand Down
9 changes: 6 additions & 3 deletions plugp100/protocol/klap_protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ async def _send_request(
f"Query failed after succesful authentication at {time.time()}. Host is {self._host}, Available attempts count is {retry}, Sequence is {seq}, Response status is {response.status}, Request was {request}"
)
if response.status == 403:
self._klap_session.invalidate()
if self._klap_session is not None:
self._klap_session.invalidate()
return Failure(Exception("Forbidden error after completing handshake"))
else:
return Failure(
Expand All @@ -92,7 +93,8 @@ async def _send_request(
return TapoResponse.try_from_json(decrypted_response)

async def close(self):
self._klap_session.invalidate()
if self._klap_session is not None:
self._klap_session.invalidate()
await self._http_session.close()

async def perform_handshake(
Expand Down Expand Up @@ -215,7 +217,8 @@ async def perform_handshake2(
f"Handshake2 posted {time.time()}. Host is {self._host}, Response status is {response.status}, Request was {payload!r}"
)
if response.status != 200:
self._klap_session.invalidate()
if self._klap_session is not None:
self._klap_session.invalidate()
return Failure(
Exception("Device responded with %d to handshake2" % response.status)
)
Expand Down

0 comments on commit 3a347e2

Please sign in to comment.