Use shorthand attributes for Daikin (#99225)
Co-authored-by: Robert Resch <robert@resch.dev>
This commit is contained in:
parent
e911b73b61
commit
bd04cafb91
3 changed files with 18 additions and 55 deletions
|
@ -124,14 +124,16 @@ class DaikinClimate(ClimateEntity):
|
|||
_attr_name = None
|
||||
_attr_has_entity_name = True
|
||||
_attr_temperature_unit = UnitOfTemperature.CELSIUS
|
||||
_attr_hvac_modes = list(HA_STATE_TO_DAIKIN)
|
||||
_attr_target_temperature_step = 1
|
||||
|
||||
def __init__(self, api: DaikinApi) -> None:
|
||||
"""Initialize the climate device."""
|
||||
|
||||
self._api = api
|
||||
self._attr_hvac_modes = list(HA_STATE_TO_DAIKIN)
|
||||
self._attr_fan_modes = self._api.device.fan_rate
|
||||
self._attr_swing_modes = self._api.device.swing_modes
|
||||
self._attr_fan_modes = api.device.fan_rate
|
||||
self._attr_swing_modes = api.device.swing_modes
|
||||
self._attr_device_info = api.device_info
|
||||
self._list = {
|
||||
ATTR_HVAC_MODE: self._attr_hvac_modes,
|
||||
ATTR_FAN_MODE: self._attr_fan_modes,
|
||||
|
@ -140,16 +142,13 @@ class DaikinClimate(ClimateEntity):
|
|||
|
||||
self._attr_supported_features = ClimateEntityFeature.TARGET_TEMPERATURE
|
||||
|
||||
if (
|
||||
self._api.device.support_away_mode
|
||||
or self._api.device.support_advanced_modes
|
||||
):
|
||||
if api.device.support_away_mode or api.device.support_advanced_modes:
|
||||
self._attr_supported_features |= ClimateEntityFeature.PRESET_MODE
|
||||
|
||||
if self._api.device.support_fan_rate:
|
||||
if api.device.support_fan_rate:
|
||||
self._attr_supported_features |= ClimateEntityFeature.FAN_MODE
|
||||
|
||||
if self._api.device.support_swing_mode:
|
||||
if api.device.support_swing_mode:
|
||||
self._attr_supported_features |= ClimateEntityFeature.SWING_MODE
|
||||
|
||||
async def _set(self, settings):
|
||||
|
@ -195,11 +194,6 @@ class DaikinClimate(ClimateEntity):
|
|||
"""Return the temperature we try to reach."""
|
||||
return self._api.device.target_temperature
|
||||
|
||||
@property
|
||||
def target_temperature_step(self):
|
||||
"""Return the supported step of target temperature."""
|
||||
return 1
|
||||
|
||||
async def async_set_temperature(self, **kwargs: Any) -> None:
|
||||
"""Set new target temperature."""
|
||||
await self._set(kwargs)
|
||||
|
@ -310,8 +304,3 @@ class DaikinClimate(ClimateEntity):
|
|||
await self._api.device.set(
|
||||
{HA_ATTR_TO_DAIKIN[ATTR_HVAC_MODE]: HA_STATE_TO_DAIKIN[HVACMode.OFF]}
|
||||
)
|
||||
|
||||
@property
|
||||
def device_info(self):
|
||||
"""Return a device description for device registry."""
|
||||
return self._api.device_info
|
||||
|
|
|
@ -21,7 +21,6 @@ from homeassistant.const import (
|
|||
UnitOfTemperature,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.device_registry import DeviceInfo
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
||||
|
||||
|
@ -192,13 +191,10 @@ class DaikinSensor(SensorEntity):
|
|||
) -> None:
|
||||
"""Initialize the sensor."""
|
||||
self.entity_description = description
|
||||
self._attr_device_info = api.device_info
|
||||
self._attr_unique_id = f"{api.device.mac}-{description.key}"
|
||||
self._api = api
|
||||
|
||||
@property
|
||||
def unique_id(self) -> str:
|
||||
"""Return a unique ID."""
|
||||
return f"{self._api.device.mac}-{self.entity_description.key}"
|
||||
|
||||
@property
|
||||
def native_value(self) -> float | None:
|
||||
"""Return the state of the sensor."""
|
||||
|
@ -207,8 +203,3 @@ class DaikinSensor(SensorEntity):
|
|||
async def async_update(self) -> None:
|
||||
"""Retrieve latest state."""
|
||||
await self._api.async_update()
|
||||
|
||||
@property
|
||||
def device_info(self) -> DeviceInfo:
|
||||
"""Return a device description for device registry."""
|
||||
return self._api.device_info
|
||||
|
|
|
@ -6,7 +6,6 @@ from typing import Any
|
|||
from homeassistant.components.switch import SwitchEntity
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.device_registry import DeviceInfo
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
||||
|
||||
|
@ -59,15 +58,12 @@ class DaikinZoneSwitch(SwitchEntity):
|
|||
_attr_icon = ZONE_ICON
|
||||
_attr_has_entity_name = True
|
||||
|
||||
def __init__(self, daikin_api: DaikinApi, zone_id) -> None:
|
||||
def __init__(self, api: DaikinApi, zone_id) -> None:
|
||||
"""Initialize the zone."""
|
||||
self._api = daikin_api
|
||||
self._api = api
|
||||
self._zone_id = zone_id
|
||||
|
||||
@property
|
||||
def unique_id(self) -> str:
|
||||
"""Return a unique ID."""
|
||||
return f"{self._api.device.mac}-zone{self._zone_id}"
|
||||
self._attr_device_info = api.device_info
|
||||
self._attr_unique_id = f"{api.device.mac}-zone{zone_id}"
|
||||
|
||||
@property
|
||||
def name(self) -> str:
|
||||
|
@ -79,11 +75,6 @@ class DaikinZoneSwitch(SwitchEntity):
|
|||
"""Return the state of the sensor."""
|
||||
return self._api.device.zones[self._zone_id][1] == "1"
|
||||
|
||||
@property
|
||||
def device_info(self) -> DeviceInfo:
|
||||
"""Return a device description for device registry."""
|
||||
return self._api.device_info
|
||||
|
||||
async def async_update(self) -> None:
|
||||
"""Retrieve latest state."""
|
||||
await self._api.async_update()
|
||||
|
@ -104,14 +95,11 @@ class DaikinStreamerSwitch(SwitchEntity):
|
|||
_attr_name = "Streamer"
|
||||
_attr_has_entity_name = True
|
||||
|
||||
def __init__(self, daikin_api: DaikinApi) -> None:
|
||||
def __init__(self, api: DaikinApi) -> None:
|
||||
"""Initialize streamer switch."""
|
||||
self._api = daikin_api
|
||||
|
||||
@property
|
||||
def unique_id(self) -> str:
|
||||
"""Return a unique ID."""
|
||||
return f"{self._api.device.mac}-streamer"
|
||||
self._api = api
|
||||
self._attr_device_info = api.device_info
|
||||
self._attr_unique_id = f"{api.device.mac}-streamer"
|
||||
|
||||
@property
|
||||
def is_on(self) -> bool:
|
||||
|
@ -120,11 +108,6 @@ class DaikinStreamerSwitch(SwitchEntity):
|
|||
DAIKIN_ATTR_STREAMER in self._api.device.represent(DAIKIN_ATTR_ADVANCED)[1]
|
||||
)
|
||||
|
||||
@property
|
||||
def device_info(self) -> DeviceInfo:
|
||||
"""Return a device description for device registry."""
|
||||
return self._api.device_info
|
||||
|
||||
async def async_update(self) -> None:
|
||||
"""Retrieve latest state."""
|
||||
await self._api.async_update()
|
||||
|
|
Loading…
Add table
Reference in a new issue