Use EntityFeature in homematic (#69405)

* Use EntityFeature in homematic

* Use EntityFeature in homematicip_cloud
This commit is contained in:
epenet 2022-04-06 12:33:35 +02:00 committed by GitHub
parent ef14ae85c8
commit a661e06e25
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 28 additions and 45 deletions

View File

@ -1,7 +1,7 @@
"""Support for Homematic thermostats.""" """Support for Homematic thermostats."""
from __future__ import annotations from __future__ import annotations
from homeassistant.components.climate import ClimateEntity from homeassistant.components.climate import ClimateEntity, ClimateEntityFeature
from homeassistant.components.climate.const import ( from homeassistant.components.climate.const import (
HVAC_MODE_AUTO, HVAC_MODE_AUTO,
HVAC_MODE_HEAT, HVAC_MODE_HEAT,
@ -10,8 +10,6 @@ from homeassistant.components.climate.const import (
PRESET_COMFORT, PRESET_COMFORT,
PRESET_ECO, PRESET_ECO,
PRESET_NONE, PRESET_NONE,
SUPPORT_PRESET_MODE,
SUPPORT_TARGET_TEMPERATURE,
) )
from homeassistant.const import ATTR_TEMPERATURE, TEMP_CELSIUS from homeassistant.const import ATTR_TEMPERATURE, TEMP_CELSIUS
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
@ -34,8 +32,6 @@ HM_PRESET_MAP = {
HM_CONTROL_MODE = "CONTROL_MODE" HM_CONTROL_MODE = "CONTROL_MODE"
HMIP_CONTROL_MODE = "SET_POINT_MODE" HMIP_CONTROL_MODE = "SET_POINT_MODE"
SUPPORT_FLAGS = SUPPORT_TARGET_TEMPERATURE | SUPPORT_PRESET_MODE
def setup_platform( def setup_platform(
hass: HomeAssistant, hass: HomeAssistant,
@ -58,10 +54,9 @@ def setup_platform(
class HMThermostat(HMDevice, ClimateEntity): class HMThermostat(HMDevice, ClimateEntity):
"""Representation of a Homematic thermostat.""" """Representation of a Homematic thermostat."""
@property _attr_supported_features = (
def supported_features(self): ClimateEntityFeature.TARGET_TEMPERATURE | ClimateEntityFeature.PRESET_MODE
"""Return the list of supported features.""" )
return SUPPORT_FLAGS
@property @property
def temperature_unit(self): def temperature_unit(self):

View File

@ -10,9 +10,8 @@ from homeassistant.components.light import (
COLOR_MODE_BRIGHTNESS, COLOR_MODE_BRIGHTNESS,
COLOR_MODE_COLOR_TEMP, COLOR_MODE_COLOR_TEMP,
COLOR_MODE_HS, COLOR_MODE_HS,
SUPPORT_EFFECT,
SUPPORT_TRANSITION,
LightEntity, LightEntity,
LightEntityFeature,
) )
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.entity_platform import AddEntitiesCallback
@ -85,9 +84,9 @@ class HMLight(HMDevice, LightEntity):
@property @property
def supported_features(self): def supported_features(self):
"""Flag supported features.""" """Flag supported features."""
features = SUPPORT_TRANSITION features = LightEntityFeature.TRANSITION
if "PROGRAM" in self._hmdevice.WRITENODE: if "PROGRAM" in self._hmdevice.WRITENODE:
features |= SUPPORT_EFFECT features |= LightEntityFeature.EFFECT
return features return features
@property @property
@ -109,14 +108,14 @@ class HMLight(HMDevice, LightEntity):
@property @property
def effect_list(self): def effect_list(self):
"""Return the list of supported effects.""" """Return the list of supported effects."""
if not self.supported_features & SUPPORT_EFFECT: if not self.supported_features & LightEntityFeature.EFFECT:
return None return None
return self._hmdevice.get_effect_list() return self._hmdevice.get_effect_list()
@property @property
def effect(self): def effect(self):
"""Return the current color change program of the light.""" """Return the current color change program of the light."""
if not self.supported_features & SUPPORT_EFFECT: if not self.supported_features & LightEntityFeature.EFFECT:
return None return None
return self._hmdevice.get_effect() return self._hmdevice.get_effect()
@ -164,5 +163,5 @@ class HMLight(HMDevice, LightEntity):
if COLOR_MODE_HS in self.supported_color_modes: if COLOR_MODE_HS in self.supported_color_modes:
self._data.update({"COLOR": None}) self._data.update({"COLOR": None})
if self.supported_features & SUPPORT_EFFECT: if self.supported_features & LightEntityFeature.EFFECT:
self._data.update({"PROGRAM": None}) self._data.update({"PROGRAM": None})

View File

@ -1,7 +1,7 @@
"""Support for Homematic locks.""" """Support for Homematic locks."""
from __future__ import annotations from __future__ import annotations
from homeassistant.components.lock import SUPPORT_OPEN, LockEntity from homeassistant.components.lock import LockEntity, LockEntityFeature
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
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
@ -30,6 +30,8 @@ def setup_platform(
class HMLock(HMDevice, LockEntity): class HMLock(HMDevice, LockEntity):
"""Representation of a Homematic lock aka KeyMatic.""" """Representation of a Homematic lock aka KeyMatic."""
_attr_supported_features = LockEntityFeature.OPEN
@property @property
def is_locked(self): def is_locked(self):
"""Return true if the lock is locked.""" """Return true if the lock is locked."""
@ -51,8 +53,3 @@ class HMLock(HMDevice, LockEntity):
"""Generate the data dictionary (self._data) from metadata.""" """Generate the data dictionary (self._data) from metadata."""
self._state = "STATE" self._state = "STATE"
self._data.update({self._state: None}) self._data.update({self._state: None})
@property
def supported_features(self):
"""Flag supported features."""
return SUPPORT_OPEN

View File

@ -5,10 +5,9 @@ import logging
from homematicip.functionalHomes import SecurityAndAlarmHome from homematicip.functionalHomes import SecurityAndAlarmHome
from homeassistant.components.alarm_control_panel import AlarmControlPanelEntity from homeassistant.components.alarm_control_panel import (
from homeassistant.components.alarm_control_panel.const import ( AlarmControlPanelEntity,
SUPPORT_ALARM_ARM_AWAY, AlarmControlPanelEntityFeature,
SUPPORT_ALARM_ARM_HOME,
) )
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
from homeassistant.const import ( from homeassistant.const import (
@ -42,6 +41,11 @@ async def async_setup_entry(
class HomematicipAlarmControlPanelEntity(AlarmControlPanelEntity): class HomematicipAlarmControlPanelEntity(AlarmControlPanelEntity):
"""Representation of the HomematicIP alarm control panel.""" """Representation of the HomematicIP alarm control panel."""
_attr_supported_features = (
AlarmControlPanelEntityFeature.ARM_HOME
| AlarmControlPanelEntityFeature.ARM_AWAY
)
def __init__(self, hap: HomematicipHAP) -> None: def __init__(self, hap: HomematicipHAP) -> None:
"""Initialize the alarm control panel.""" """Initialize the alarm control panel."""
self._home: AsyncHome = hap.home self._home: AsyncHome = hap.home
@ -79,11 +83,6 @@ class HomematicipAlarmControlPanelEntity(AlarmControlPanelEntity):
def _security_and_alarm(self) -> SecurityAndAlarmHome: def _security_and_alarm(self) -> SecurityAndAlarmHome:
return self._home.get_functionalHome(SecurityAndAlarmHome) return self._home.get_functionalHome(SecurityAndAlarmHome)
@property
def supported_features(self) -> int:
"""Return the list of supported features."""
return SUPPORT_ALARM_ARM_HOME | SUPPORT_ALARM_ARM_AWAY
async def async_alarm_disarm(self, code=None) -> None: async def async_alarm_disarm(self, code=None) -> None:
"""Send disarm command.""" """Send disarm command."""
await self._home.set_security_zones_activation(False, False) await self._home.set_security_zones_activation(False, False)

View File

@ -9,7 +9,7 @@ from homematicip.base.enums import AbsenceType
from homematicip.device import Switch from homematicip.device import Switch
from homematicip.functionalHomes import IndoorClimateHome from homematicip.functionalHomes import IndoorClimateHome
from homeassistant.components.climate import ClimateEntity from homeassistant.components.climate import ClimateEntity, ClimateEntityFeature
from homeassistant.components.climate.const import ( from homeassistant.components.climate.const import (
CURRENT_HVAC_HEAT, CURRENT_HVAC_HEAT,
CURRENT_HVAC_IDLE, CURRENT_HVAC_IDLE,
@ -21,8 +21,6 @@ from homeassistant.components.climate.const import (
PRESET_BOOST, PRESET_BOOST,
PRESET_ECO, PRESET_ECO,
PRESET_NONE, PRESET_NONE,
SUPPORT_PRESET_MODE,
SUPPORT_TARGET_TEMPERATURE,
) )
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
from homeassistant.const import ATTR_TEMPERATURE, TEMP_CELSIUS from homeassistant.const import ATTR_TEMPERATURE, TEMP_CELSIUS
@ -68,6 +66,10 @@ class HomematicipHeatingGroup(HomematicipGenericEntity, ClimateEntity):
Cool mode is only available for floor heating systems, if basically enabled in the hmip app. Cool mode is only available for floor heating systems, if basically enabled in the hmip app.
""" """
_attr_supported_features = (
ClimateEntityFeature.PRESET_MODE | ClimateEntityFeature.TARGET_TEMPERATURE
)
def __init__(self, hap: HomematicipHAP, device: AsyncHeatingGroup) -> None: def __init__(self, hap: HomematicipHAP, device: AsyncHeatingGroup) -> None:
"""Initialize heating group.""" """Initialize heating group."""
device.modelType = "HmIP-Heating-Group" device.modelType = "HmIP-Heating-Group"
@ -92,11 +94,6 @@ class HomematicipHeatingGroup(HomematicipGenericEntity, ClimateEntity):
"""Return the unit of measurement.""" """Return the unit of measurement."""
return TEMP_CELSIUS return TEMP_CELSIUS
@property
def supported_features(self) -> int:
"""Return the list of supported features."""
return SUPPORT_PRESET_MODE | SUPPORT_TARGET_TEMPERATURE
@property @property
def target_temperature(self) -> float: def target_temperature(self) -> float:
"""Return the temperature we try to reach.""" """Return the temperature we try to reach."""

View File

@ -23,8 +23,8 @@ from homeassistant.components.light import (
COLOR_MODE_BRIGHTNESS, COLOR_MODE_BRIGHTNESS,
COLOR_MODE_HS, COLOR_MODE_HS,
COLOR_MODE_ONOFF, COLOR_MODE_ONOFF,
SUPPORT_TRANSITION,
LightEntity, LightEntity,
LightEntityFeature,
) )
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
@ -154,6 +154,7 @@ class HomematicipNotificationLight(HomematicipGenericEntity, LightEntity):
_attr_color_mode = COLOR_MODE_HS _attr_color_mode = COLOR_MODE_HS
_attr_supported_color_modes = {COLOR_MODE_HS} _attr_supported_color_modes = {COLOR_MODE_HS}
_attr_supported_features = LightEntityFeature.TRANSITION
def __init__(self, hap: HomematicipHAP, device, channel: int) -> None: def __init__(self, hap: HomematicipHAP, device, channel: int) -> None:
"""Initialize the notification light entity.""" """Initialize the notification light entity."""
@ -209,11 +210,6 @@ class HomematicipNotificationLight(HomematicipGenericEntity, LightEntity):
return state_attr return state_attr
@property
def supported_features(self) -> int:
"""Flag supported features."""
return SUPPORT_TRANSITION
@property @property
def unique_id(self) -> str: def unique_id(self) -> str:
"""Return a unique ID.""" """Return a unique ID."""