Skip to content

Commit

Permalink
support VRF
Browse files Browse the repository at this point in the history
  • Loading branch information
jafar-atili committed May 5, 2023
1 parent 1aa538a commit a224446
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 8 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.23"
version = "1.7.24"
description = "SwitchBee Python Integration."
readme = "README.md"
authors = [{ name = "Jafar Atili", email = "[email protected]" }]
Expand Down
11 changes: 5 additions & 6 deletions src/switchbee/api/central_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -366,15 +366,15 @@ 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,
zone=zone[ApiAttribute.NAME],
hardware=device_hw,
type=device_type,
modes=item[ApiAttribute.MODES],
unit=item[ApiAttribute.TEMPERATURE_UNITS],
temperature_unit=item[ApiAttribute.TEMPERATURE_UNITS],
)

# add rolling scenario
Expand Down Expand Up @@ -434,7 +434,6 @@ async def fetch_configuration(
async def fetch_states(
self,
) -> None:

states = await self.get_multiple_states(
[
dev
Expand All @@ -449,6 +448,7 @@ async def fetch_states(
DeviceType.TimedPowerSwitch,
DeviceType.Thermostat,
DeviceType.TimedSwitch,
DeviceType.VRFAC,
]
]
)
Expand Down Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions src/switchbee/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class ApiAttribute:
class ApiStateCommand:
ON = "ON"
OFF = "OFF"
OFFLINE = "OFFLINE"


# SwitchBee device hardware
Expand Down Expand Up @@ -87,6 +88,7 @@ class ApiDeviceType:
LOUVERED_SHUTTER = "LOUVERED_SHUTTER"
SOMFY = "SOMFY"
ROLLING_SCENARIO = "ROLLING_SCENARIO"
VRF_AC = "VRF_AC"


class ThermostatMode:
Expand Down
3 changes: 2 additions & 1 deletion src/switchbee/device/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit a224446

Please sign in to comment.