Cleanup handling of attributes for HomematicIP Cloud (#27331)
* Cleanup handling of attributes for HomematicIP Cloud * Remove special climate handling
This commit is contained in:
parent
0ba4ee1398
commit
55e10d552e
5 changed files with 28 additions and 10 deletions
|
@ -40,7 +40,7 @@ from homeassistant.config_entries import ConfigEntry
|
|||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from . import DOMAIN as HMIPC_DOMAIN, HMIPC_HAPID, HomematicipGenericDevice
|
||||
from .device import ATTR_GROUP_MEMBER_UNREACHABLE, ATTR_IS_GROUP, ATTR_MODEL_TYPE
|
||||
from .device import ATTR_GROUP_MEMBER_UNREACHABLE
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
@ -60,7 +60,6 @@ ATTR_WINDOW_STATE = "window_state"
|
|||
|
||||
GROUP_ATTRIBUTES = {
|
||||
"lowBat": ATTR_LOW_BATTERY,
|
||||
"modelType": ATTR_MODEL_TYPE,
|
||||
"moistureDetected": ATTR_MOISTURE_DETECTED,
|
||||
"motionDetected": ATTR_MOTION_DETECTED,
|
||||
"powerMainsFailure": ATTR_POWER_MAINS_FAILURE,
|
||||
|
@ -353,7 +352,7 @@ class HomematicipSecurityZoneSensorGroup(HomematicipGenericDevice, BinarySensorD
|
|||
@property
|
||||
def device_state_attributes(self):
|
||||
"""Return the state attributes of the security zone group."""
|
||||
state_attr = {ATTR_MODEL_TYPE: self._device.modelType, ATTR_IS_GROUP: True}
|
||||
state_attr = super().device_state_attributes
|
||||
|
||||
for attr, attr_key in GROUP_ATTRIBUTES.items():
|
||||
attr_value = getattr(self._device, attr, None)
|
||||
|
|
|
@ -3,6 +3,7 @@ import logging
|
|||
from typing import Optional
|
||||
|
||||
from homematicip.aio.device import AsyncDevice
|
||||
from homematicip.aio.group import AsyncGroup
|
||||
from homematicip.aio.home import AsyncHome
|
||||
|
||||
from homeassistant.components import homematicip_cloud
|
||||
|
@ -13,6 +14,7 @@ from homeassistant.helpers.entity import Entity
|
|||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
ATTR_MODEL_TYPE = "model_type"
|
||||
ATTR_GROUP_ID = "group_id"
|
||||
ATTR_ID = "id"
|
||||
ATTR_IS_GROUP = "is_group"
|
||||
# RSSI HAP -> Device
|
||||
|
@ -35,15 +37,17 @@ DEVICE_ATTRIBUTE_ICONS = {
|
|||
|
||||
DEVICE_ATTRIBUTES = {
|
||||
"modelType": ATTR_MODEL_TYPE,
|
||||
"id": ATTR_ID,
|
||||
"sabotage": ATTR_SABOTAGE,
|
||||
"rssiDeviceValue": ATTR_RSSI_DEVICE,
|
||||
"rssiPeerValue": ATTR_RSSI_PEER,
|
||||
"deviceOverheated": ATTR_DEVICE_OVERHEATED,
|
||||
"deviceOverloaded": ATTR_DEVICE_OVERLOADED,
|
||||
"deviceUndervoltage": ATTR_DEVICE_UNTERVOLTAGE,
|
||||
"id": ATTR_ID,
|
||||
}
|
||||
|
||||
GROUP_ATTRIBUTES = {"modelType": ATTR_MODEL_TYPE, "id": ATTR_GROUP_ID}
|
||||
|
||||
|
||||
class HomematicipGenericDevice(Entity):
|
||||
"""Representation of an HomematicIP generic device."""
|
||||
|
@ -173,6 +177,7 @@ class HomematicipGenericDevice(Entity):
|
|||
def device_state_attributes(self):
|
||||
"""Return the state attributes of the generic device."""
|
||||
state_attr = {}
|
||||
|
||||
if isinstance(self._device, AsyncDevice):
|
||||
for attr, attr_key in DEVICE_ATTRIBUTES.items():
|
||||
attr_value = getattr(self._device, attr, None)
|
||||
|
@ -181,4 +186,12 @@ class HomematicipGenericDevice(Entity):
|
|||
|
||||
state_attr[ATTR_IS_GROUP] = False
|
||||
|
||||
if isinstance(self._device, AsyncGroup):
|
||||
for attr, attr_key in GROUP_ATTRIBUTES.items():
|
||||
attr_value = getattr(self._device, attr, None)
|
||||
if attr_value:
|
||||
state_attr[attr_key] = attr_value
|
||||
|
||||
state_attr[ATTR_IS_GROUP] = True
|
||||
|
||||
return state_attr
|
||||
|
|
|
@ -115,7 +115,6 @@ class HomematicipAccesspointStatus(HomematicipGenericDevice):
|
|||
|
||||
def __init__(self, home: AsyncHome) -> None:
|
||||
"""Initialize access point device."""
|
||||
home.modelType = "HmIP-HAP"
|
||||
super().__init__(home, home)
|
||||
|
||||
@property
|
||||
|
@ -152,7 +151,12 @@ class HomematicipAccesspointStatus(HomematicipGenericDevice):
|
|||
@property
|
||||
def device_state_attributes(self):
|
||||
"""Return the state attributes of the access point."""
|
||||
return {ATTR_MODEL_TYPE: self._device.modelType, ATTR_IS_GROUP: False}
|
||||
state_attr = super().device_state_attributes
|
||||
|
||||
state_attr[ATTR_MODEL_TYPE] = "HmIP-HAP"
|
||||
state_attr[ATTR_IS_GROUP] = False
|
||||
|
||||
return state_attr
|
||||
|
||||
|
||||
class HomematicipHeatingThermostat(HomematicipGenericDevice):
|
||||
|
@ -316,7 +320,7 @@ class HomematicipWindspeedSensor(HomematicipGenericDevice):
|
|||
state_attr = super().device_state_attributes
|
||||
|
||||
wind_direction = getattr(self._device, "windDirection", None)
|
||||
if wind_direction:
|
||||
if wind_direction is not None:
|
||||
state_attr[ATTR_WIND_DIRECTION] = _get_wind_direction(wind_direction)
|
||||
|
||||
wind_direction_variation = getattr(self._device, "windDirectionVariation", None)
|
||||
|
|
|
@ -19,7 +19,7 @@ from homeassistant.config_entries import ConfigEntry
|
|||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from . import DOMAIN as HMIPC_DOMAIN, HMIPC_HAPID, HomematicipGenericDevice
|
||||
from .device import ATTR_GROUP_MEMBER_UNREACHABLE, ATTR_IS_GROUP
|
||||
from .device import ATTR_GROUP_MEMBER_UNREACHABLE
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
@ -113,9 +113,11 @@ class HomematicipGroupSwitch(HomematicipGenericDevice, SwitchDevice):
|
|||
@property
|
||||
def device_state_attributes(self):
|
||||
"""Return the state attributes of the switch-group."""
|
||||
state_attr = {ATTR_IS_GROUP: True}
|
||||
state_attr = super().device_state_attributes
|
||||
|
||||
if self._device.unreach:
|
||||
state_attr[ATTR_GROUP_MEMBER_UNREACHABLE] = True
|
||||
|
||||
return state_attr
|
||||
|
||||
async def async_turn_on(self, **kwargs):
|
||||
|
|
|
@ -123,7 +123,7 @@ class HomematicipHomeWeather(HomematicipGenericDevice, WeatherEntity):
|
|||
|
||||
def __init__(self, home: AsyncHome) -> None:
|
||||
"""Initialize the home weather."""
|
||||
home.weather.modelType = "HmIP-Home-Weather"
|
||||
home.modelType = "HmIP-Home-Weather"
|
||||
super().__init__(home, home)
|
||||
|
||||
@property
|
||||
|
|
Loading…
Add table
Reference in a new issue