Skip to content

Commit

Permalink
fixed invalid state recv by thermostat
Browse files Browse the repository at this point in the history
  • Loading branch information
jafar-atili committed May 6, 2023
1 parent 91d39a1 commit db1cbc1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "pyswitchbee"
version = "1.7.30"
version = "1.7.32"
description = "SwitchBee Python Integration."
readme = "README.md"
authors = [{ name = "Jafar Atili", email = "[email protected]" }]
Expand Down
17 changes: 12 additions & 5 deletions src/switchbee/api/central_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def __init__(self, version: str) -> None:

self._initialize(version)

def _initialize(self, version) -> None:
def _initialize(self, version: str) -> None:
if match := re.match(r"(\d+|\S)\.(\d+)\.(\d+)\((\d+)\)$", version):
self.major = match.group(1)
self.minor = int(match.group(2))
Expand Down Expand Up @@ -460,7 +460,6 @@ async def fetch_states(

for device_state in states[ApiAttribute.DATA]:
device_id = device_state[ApiAttribute.ID]

self.update_device_state(device_id, device_state[ApiAttribute.STATE])

def update_device_state(self, device_id: int, new_state: str | int | dict) -> bool:
Expand Down Expand Up @@ -493,12 +492,20 @@ def update_device_state(self, device_id: int, new_state: str | int | dict) -> bo
device.state = new_state

elif isinstance(device, SwitchBeeThermostat):
logger.error(f'Thermostat: {new_state}')

if not isinstance(new_state, dict):
logger.warning(
"%s: Received invalid state from CU, keeping the old one: %s",
device.name,
new_state,
)

return False

try:
assert isinstance(new_state, dict)
device.state = new_state[ApiAttribute.POWER]
except TypeError:
logger.error(
logger.warning(
"%s: Received invalid state from CU, keeping the old one: %s",
device.name,
new_state,
Expand Down

0 comments on commit db1cbc1

Please sign in to comment.