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