Skip to content

Commit

Permalink
chore(device): improved authentication logs (#276)
Browse files Browse the repository at this point in the history
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

- **Enhancements**
- Improved logging functionality for the authentication and device
enabling processes, providing better visibility and traceability of
actions taken on devices.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
  • Loading branch information
rokam authored Aug 17, 2024
1 parent 84293bf commit 03425d7
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions midealocal/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
from enum import IntEnum, StrEnum
from typing import Any

from typing_extensions import deprecated

from .exceptions import CannotConnect, SocketException
from .message import (
MessageApplianceResponse,
Expand Down Expand Up @@ -245,6 +247,12 @@ def authenticate(self) -> None:
raise SocketException
self._socket.send(request)
response = self._socket.recv(512)
_LOGGER.debug(
"[%s] Received auth response with %d bytes: %s",
self._device_id,
len(response),
response.hex(),
)
if len(response) < MIN_AUTH_RESPONSE:
self.enable_device(False)
raise AuthException
Expand Down Expand Up @@ -460,13 +468,22 @@ def update_all(self, status: dict[str, Any]) -> None:
for update in self._updates:
update(status)

def enable_device(self, available: bool = True) -> None:
"""Enable device."""
_LOGGER.debug("[%s] Enabling device", self._device_id)
def set_available(self, available: bool = True) -> None:
"""Set available value."""
_LOGGER.debug(
"[%s] %s device",
self._device_id,
"Enabling" if available else "Disabling",
)
self._available = available
status = {"available": available}
self.update_all(status)

@deprecated("enable_device is replaced by set_available")
def enable_device(self, available: bool = True) -> None:
"""Enable device."""
self.set_available(available)

def open(self) -> None:
"""Open thread."""
if not self._is_run:
Expand Down

0 comments on commit 03425d7

Please sign in to comment.