pull/45618/head^2
Daniel Hjelseth Høyer 2021-10-17 20:56:03 +02:00 committed by GitHub
parent 284861c8bb
commit f390812183
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 22 additions and 41 deletions

View File

@ -39,8 +39,11 @@ async def async_setup_entry(
)
async_add_entities(
AdaxDevice(room, adax_data_handler)
for room in await adax_data_handler.get_rooms()
(
AdaxDevice(room, adax_data_handler)
for room in await adax_data_handler.get_rooms()
),
True,
)
@ -56,7 +59,7 @@ class AdaxDevice(ClimateEntity):
def __init__(self, heater_data: dict[str, Any], adax_data_handler: Adax) -> None:
"""Initialize the heater."""
self._heater_data = heater_data
self._device_id = heater_data["id"]
self._adax_data_handler = adax_data_handler
self._attr_unique_id = f"{heater_data['homeId']}_{heater_data['id']}"
@ -66,64 +69,42 @@ class AdaxDevice(ClimateEntity):
manufacturer="Adax",
)
@property
def name(self) -> str:
"""Return the name of the device, if any."""
return self._heater_data["name"]
@property
def hvac_mode(self) -> str:
"""Return hvac operation ie. heat, cool mode."""
if self._heater_data["heatingEnabled"]:
return HVAC_MODE_HEAT
return HVAC_MODE_OFF
@property
def icon(self) -> str:
"""Return nice icon for heater."""
if self.hvac_mode == HVAC_MODE_HEAT:
return "mdi:radiator"
return "mdi:radiator-off"
async def async_set_hvac_mode(self, hvac_mode: str) -> None:
"""Set hvac mode."""
if hvac_mode == HVAC_MODE_HEAT:
temperature = max(
self.min_temp, self._heater_data.get("targetTemperature", self.min_temp)
)
temperature = max(self.min_temp, self.target_temperature or self.min_temp)
await self._adax_data_handler.set_room_target_temperature(
self._heater_data["id"], temperature, True
self._device_id, temperature, True
)
elif hvac_mode == HVAC_MODE_OFF:
await self._adax_data_handler.set_room_target_temperature(
self._heater_data["id"], self.min_temp, False
self._device_id, self.min_temp, False
)
else:
return
await self._adax_data_handler.update()
@property
def current_temperature(self) -> float | None:
"""Return the current temperature."""
return self._heater_data.get("temperature")
@property
def target_temperature(self) -> int | None:
"""Return the temperature we try to reach."""
return self._heater_data.get("targetTemperature")
async def async_set_temperature(self, **kwargs: Any) -> None:
"""Set new target temperature."""
temperature = kwargs.get(ATTR_TEMPERATURE)
if temperature is None:
return
await self._adax_data_handler.set_room_target_temperature(
self._heater_data["id"], temperature, True
self._device_id, temperature, True
)
async def async_update(self) -> None:
"""Get the latest data."""
for room in await self._adax_data_handler.get_rooms():
if room["id"] == self._heater_data["id"]:
self._heater_data = room
return
if room["id"] != self._device_id:
continue
self._attr_name = room["name"]
self._attr_current_temperature = room.get("temperature")
self._attr_target_temperature = room.get("targetTemperature")
if room["heatingEnabled"]:
self._attr_hvac_mode = HVAC_MODE_HEAT
self._attr_icon = "mdi:radiator"
else:
self._attr_hvac_mode = HVAC_MODE_OFF
self._attr_icon = "mdi:radiator-off"
return