Skip to content

Commit

Permalink
device: add support for older devices
Browse files Browse the repository at this point in the history
Some (older) devices do not provide name, mode(s), air_demand or floor_demand parameters.

Signed-off-by: Álvaro Fernández Rojas <[email protected]>
  • Loading branch information
Noltari committed Dec 28, 2022
1 parent a6e9978 commit 8a99508
Showing 1 changed file with 27 additions and 9 deletions.
36 changes: 27 additions & 9 deletions aioairzone/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ class Zone:

def __init__(self, system: System, zone: dict[str, Any]):
"""Zone init."""
self.air_demand = bool(zone[API_AIR_DEMAND])
self.air_demand: bool | None = None
self.cold_angle: GrilleAngle | None = None
self.cold_stage: AirzoneStages | None = None
self.cold_stages: list[AirzoneStages] = []
Expand All @@ -347,7 +347,7 @@ def __init__(self, system: System, zone: dict[str, Any]):
self.cool_temp_set: float | None = None
self.double_set_point: bool = False
self.errors: list[str] = []
self.floor_demand = bool(zone[API_FLOOR_DEMAND])
self.floor_demand: bool | None = None
self.heat_angle: GrilleAngle | None = None
self.heat_temp_max: float | None = None
self.heat_temp_min: float | None = None
Expand All @@ -357,9 +357,7 @@ def __init__(self, system: System, zone: dict[str, Any]):
self.humidity: int | None = None
self.id = int(zone[API_ZONE_ID])
self.master = bool(API_MODES in zone)
self.mode = OperationMode(zone[API_MODE])
self.modes: list[OperationMode] = []
self.name = str(zone[API_NAME])
self.on = bool(zone[API_ON])
self.sleep: SleepTimeout | None = None
self.speed: int | None = None
Expand All @@ -373,6 +371,11 @@ def __init__(self, system: System, zone: dict[str, Any]):
self.thermostat = Thermostat(zone)
self.system = system

if API_AIR_DEMAND in zone:
self.air_demand = bool(zone[API_AIR_DEMAND])
if API_FLOOR_DEMAND in zone:
self.floor_demand = bool(zone[API_FLOOR_DEMAND])

if API_HUMIDITY in zone:
self.humidity = int(zone[API_HUMIDITY])

Expand Down Expand Up @@ -420,6 +423,18 @@ def __init__(self, system: System, zone: dict[str, Any]):
for key, val in error.items():
self.add_error(key, val)

if API_MODE in zone:
self.mode = OperationMode(zone[API_MODE])
else:
self.master = True
self.mode = OperationMode.AUTO
self.modes.append(self.mode)

if API_NAME in zone:
self.name = str(zone[API_NAME])
else:
self.name = f"Airzone {zone[API_SYSTEM_ID]}:{zone[API_ZONE_ID]}"

if API_SLEEP in zone:
self.sleep = SleepTimeout(zone[API_SLEEP])

Expand All @@ -433,8 +448,9 @@ def __init__(self, system: System, zone: dict[str, Any]):
self.temp_step = float(zone[API_TEMP_STEP])

if self.master:
for mode in zone[API_MODES]:
self.modes.append(OperationMode(mode))
if API_MODES in zone:
for mode in zone[API_MODES]:
self.modes.append(OperationMode(mode))
self.system.set_mode(self.mode)
self.system.set_modes(self.modes)
if OperationMode.STOP not in self.modes:
Expand Down Expand Up @@ -568,7 +584,7 @@ def add_error(self, key: str, val: str) -> None:

def get_air_demand(self) -> bool | None:
"""Return zone air demand."""
if self.is_stage_supported(AirzoneStages.Air):
if self.air_demand is not None and self.is_stage_supported(AirzoneStages.Air):
return self.air_demand
return None

Expand Down Expand Up @@ -612,7 +628,7 @@ def get_cool_temp_set(self) -> float | None:

def get_demand(self) -> bool:
"""Return zone demand."""
return self.air_demand or self.floor_demand
return bool(self.air_demand) or bool(self.floor_demand)

def get_double_set_point(self) -> bool:
"""Return zone double set point."""
Expand All @@ -624,7 +640,9 @@ def get_errors(self) -> list[str]:

def get_floor_demand(self) -> bool | None:
"""Return zone floor demand."""
if self.is_stage_supported(AirzoneStages.Radiant):
if self.floor_demand is not None and self.is_stage_supported(
AirzoneStages.Radiant
):
return self.floor_demand
return None

Expand Down

0 comments on commit 8a99508

Please sign in to comment.