Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/pyvesync/devices/vesyncpurifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,10 @@ async def set_light_detection(self, toggle: bool) -> bool:

async def toggle_light_detection(self, toggle: bool | None = None) -> bool:
"""Enable/Disable Light Detection Feature."""
if bool(self.state.light_detection_status) == toggle:
_LOGGER.debug('Light detection is already %s', self.state.light_detection_status)
return True

if toggle is None:
toggle = not bool(self.state.light_detection_status)
payload_data = {"lightDetectionSwitch": int(toggle)}
Expand All @@ -536,8 +540,7 @@ async def toggle_light_detection(self, toggle: bool | None = None) -> bool:
if r is None:
return False

self.state.light_detection_switch = DeviceStatus.ON if toggle \
else DeviceStatus.OFF
self.state.light_detection_switch = DeviceStatus.from_bool(toggle)
self.state.connection_status = ConnectionStatus.ONLINE
return True

Expand Down Expand Up @@ -587,6 +590,10 @@ async def toggle_child_lock(self, toggle: bool | None = None) -> bool:
return True

async def toggle_display(self, mode: bool) -> bool:
if bool(self.state.light_detection_status):
_LOGGER.error('Cannot set display when light detection is enabled')
return False

if bool(self.state.display_set_status) == mode:
_LOGGER.debug('Display is already %s', mode)
return True
Expand Down
6 changes: 3 additions & 3 deletions src/pyvesync/vesync.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ async def get_devices(self) -> bool:

return proc_return

async def login(self) -> bool: # pylint: disable=W9006 # pylint mult docstring raises
async def login(self) -> None: # pylint: disable=W9006 # pylint mult docstring raises
"""Log into VeSync server.

Username and password are provided when class is instantiated.
Expand Down Expand Up @@ -364,7 +364,7 @@ async def _login_token(
self,
auth_code: str | None = None,
region_change_token: str | None = None,
) -> bool: # pylint: disable=W9006 # pylint mult docstring raises
) -> None: # pylint: disable=W9006 # pylint mult docstring raises
"""Exchanges the authorization code for a token.

This completes the login process. If the initial call fails with
Expand Down Expand Up @@ -407,7 +407,7 @@ async def _login_token(
if error_info.error_type == ErrorTypes.CROSS_REGION: # cross region error
result = response_model.result
self.country_code = result.countryCode
await self._login_token(region_change_token=result.bizToken)
return await self._login_token(region_change_token=result.bizToken)
resp_message = resp_dict.get('msg')
if resp_message is not None:
error_info.message = f'{error_info.message} ({resp_message})'
Expand Down