From a224446e29a17d3a39011a37f408aee2ae73e63a Mon Sep 17 00:00:00 2001 From: Jafar Atili Date: Fri, 5 May 2023 13:34:28 +0300 Subject: [PATCH] support VRF --- pyproject.toml | 2 +- src/switchbee/api/central_unit.py | 11 +++++------ src/switchbee/const.py | 2 ++ src/switchbee/device/__init__.py | 3 ++- 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 5b2baa9..b8384ed 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -5,7 +5,7 @@ build-backend = "setuptools.build_meta" [project] name = "pyswitchbee" -version = "1.7.23" +version = "1.7.24" description = "SwitchBee Python Integration." readme = "README.md" authors = [{ name = "Jafar Atili", email = "at.jafar@outlook.com" }] diff --git a/src/switchbee/api/central_unit.py b/src/switchbee/api/central_unit.py index cbff9ef..0fcc963 100644 --- a/src/switchbee/api/central_unit.py +++ b/src/switchbee/api/central_unit.py @@ -192,7 +192,6 @@ async def _login(self) -> None: raise NotImplementedError def _update_login(self, resp: dict[str, Any]) -> None: - self._login_count += 1 self._token = resp[ApiAttribute.DATA][ApiAttribute.TOKEN] # instead of dealing with time synchronization issue, we @@ -207,6 +206,8 @@ async def get_configuration(self) -> dict: async def get_multiple_states(self, ids: list) -> dict: """returns JSON {'status': 'OK', 'data': [{'id': 212, 'state': 'OFF'}, {'id': 343, 'state': 'OFF'}]}""" await self.login_if_needed() + if not len(ids): + return {} return await self._send_request(ApiCommand.GET_MULTI_STATES, ids) async def get_state(self, id: int) -> dict: @@ -251,7 +252,6 @@ async def fetch_configuration( for zone in data[ApiAttribute.DATA][ApiAttribute.ZONES]: for item in zone[ApiAttribute.ITEMS]: - try: device_type = DeviceType(item[ApiAttribute.TYPE]) except ValueError: @@ -366,7 +366,7 @@ async def fetch_configuration( type=device_type, ) - elif device_type == DeviceType.Thermostat: + elif device_type in [DeviceType.Thermostat, DeviceType.VRFAC]: self._devices_map[item[ApiAttribute.ID]] = SwitchBeeThermostat( id=device_id, name=device_name, @@ -374,7 +374,7 @@ async def fetch_configuration( hardware=device_hw, type=device_type, modes=item[ApiAttribute.MODES], - unit=item[ApiAttribute.TEMPERATURE_UNITS], + temperature_unit=item[ApiAttribute.TEMPERATURE_UNITS], ) # add rolling scenario @@ -434,7 +434,6 @@ async def fetch_configuration( async def fetch_states( self, ) -> None: - states = await self.get_multiple_states( [ dev @@ -449,6 +448,7 @@ async def fetch_states( DeviceType.TimedPowerSwitch, DeviceType.Thermostat, DeviceType.TimedSwitch, + DeviceType.VRFAC, ] ] ) @@ -484,7 +484,6 @@ def update_device_state(self, device_id: int, new_state: str | int | dict) -> bo SwitchBeeTimerSwitch, ), ): - assert isinstance(new_state, (int, str)) device.state = new_state diff --git a/src/switchbee/const.py b/src/switchbee/const.py index ecd1ac5..16592d3 100644 --- a/src/switchbee/const.py +++ b/src/switchbee/const.py @@ -52,6 +52,7 @@ class ApiAttribute: class ApiStateCommand: ON = "ON" OFF = "OFF" + OFFLINE = "OFFLINE" # SwitchBee device hardware @@ -87,6 +88,7 @@ class ApiDeviceType: LOUVERED_SHUTTER = "LOUVERED_SHUTTER" SOMFY = "SOMFY" ROLLING_SCENARIO = "ROLLING_SCENARIO" + VRF_AC = "VRF_AC" class ThermostatMode: diff --git a/src/switchbee/device/__init__.py b/src/switchbee/device/__init__.py index 97a0a60..77d98ac 100644 --- a/src/switchbee/device/__init__.py +++ b/src/switchbee/device/__init__.py @@ -27,6 +27,7 @@ class DeviceType(Enum): Somfy = ApiDeviceType.SOMFY, "Somfy" IrDevice = ApiDeviceType.IR_DEVICE, "Infra Red Device" RollingScenario = ApiDeviceType.ROLLING_SCENARIO, "Rolling Scenario" + VRFAC = ApiDeviceType.VRF_AC, "VRF Unit" def __new__(cls, *args: Any, **kwds: Any): # type: ignore obj = object.__new__(cls) @@ -176,7 +177,7 @@ def minutes_left(self) -> int: @dataclass class SwitchBeeBaseThermostat(ABC): modes: List[str] - unit: str + temperature_unit: str mode: str = field(init=False) fan: str = field(init=False) target_temperature: int = field(init=False)