Cleanup handling of attributes for HomematicIP Cloud (#27331)

* Cleanup handling of attributes for HomematicIP Cloud

* Remove special climate handling
This commit is contained in:
SukramJ 2019-10-08 19:52:43 +02:00 committed by Martin Hjelmare
parent 0ba4ee1398
commit 55e10d552e
5 changed files with 28 additions and 10 deletions

View File

@ -40,7 +40,7 @@ from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from . import DOMAIN as HMIPC_DOMAIN, HMIPC_HAPID, HomematicipGenericDevice 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__) _LOGGER = logging.getLogger(__name__)
@ -60,7 +60,6 @@ ATTR_WINDOW_STATE = "window_state"
GROUP_ATTRIBUTES = { GROUP_ATTRIBUTES = {
"lowBat": ATTR_LOW_BATTERY, "lowBat": ATTR_LOW_BATTERY,
"modelType": ATTR_MODEL_TYPE,
"moistureDetected": ATTR_MOISTURE_DETECTED, "moistureDetected": ATTR_MOISTURE_DETECTED,
"motionDetected": ATTR_MOTION_DETECTED, "motionDetected": ATTR_MOTION_DETECTED,
"powerMainsFailure": ATTR_POWER_MAINS_FAILURE, "powerMainsFailure": ATTR_POWER_MAINS_FAILURE,
@ -353,7 +352,7 @@ class HomematicipSecurityZoneSensorGroup(HomematicipGenericDevice, BinarySensorD
@property @property
def device_state_attributes(self): def device_state_attributes(self):
"""Return the state attributes of the security zone group.""" """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(): for attr, attr_key in GROUP_ATTRIBUTES.items():
attr_value = getattr(self._device, attr, None) attr_value = getattr(self._device, attr, None)

View File

@ -3,6 +3,7 @@ import logging
from typing import Optional from typing import Optional
from homematicip.aio.device import AsyncDevice from homematicip.aio.device import AsyncDevice
from homematicip.aio.group import AsyncGroup
from homematicip.aio.home import AsyncHome from homematicip.aio.home import AsyncHome
from homeassistant.components import homematicip_cloud from homeassistant.components import homematicip_cloud
@ -13,6 +14,7 @@ from homeassistant.helpers.entity import Entity
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
ATTR_MODEL_TYPE = "model_type" ATTR_MODEL_TYPE = "model_type"
ATTR_GROUP_ID = "group_id"
ATTR_ID = "id" ATTR_ID = "id"
ATTR_IS_GROUP = "is_group" ATTR_IS_GROUP = "is_group"
# RSSI HAP -> Device # RSSI HAP -> Device
@ -35,15 +37,17 @@ DEVICE_ATTRIBUTE_ICONS = {
DEVICE_ATTRIBUTES = { DEVICE_ATTRIBUTES = {
"modelType": ATTR_MODEL_TYPE, "modelType": ATTR_MODEL_TYPE,
"id": ATTR_ID,
"sabotage": ATTR_SABOTAGE, "sabotage": ATTR_SABOTAGE,
"rssiDeviceValue": ATTR_RSSI_DEVICE, "rssiDeviceValue": ATTR_RSSI_DEVICE,
"rssiPeerValue": ATTR_RSSI_PEER, "rssiPeerValue": ATTR_RSSI_PEER,
"deviceOverheated": ATTR_DEVICE_OVERHEATED, "deviceOverheated": ATTR_DEVICE_OVERHEATED,
"deviceOverloaded": ATTR_DEVICE_OVERLOADED, "deviceOverloaded": ATTR_DEVICE_OVERLOADED,
"deviceUndervoltage": ATTR_DEVICE_UNTERVOLTAGE, "deviceUndervoltage": ATTR_DEVICE_UNTERVOLTAGE,
"id": ATTR_ID,
} }
GROUP_ATTRIBUTES = {"modelType": ATTR_MODEL_TYPE, "id": ATTR_GROUP_ID}
class HomematicipGenericDevice(Entity): class HomematicipGenericDevice(Entity):
"""Representation of an HomematicIP generic device.""" """Representation of an HomematicIP generic device."""
@ -173,6 +177,7 @@ class HomematicipGenericDevice(Entity):
def device_state_attributes(self): def device_state_attributes(self):
"""Return the state attributes of the generic device.""" """Return the state attributes of the generic device."""
state_attr = {} state_attr = {}
if isinstance(self._device, AsyncDevice): if isinstance(self._device, AsyncDevice):
for attr, attr_key in DEVICE_ATTRIBUTES.items(): for attr, attr_key in DEVICE_ATTRIBUTES.items():
attr_value = getattr(self._device, attr, None) attr_value = getattr(self._device, attr, None)
@ -181,4 +186,12 @@ class HomematicipGenericDevice(Entity):
state_attr[ATTR_IS_GROUP] = False 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 return state_attr

View File

@ -115,7 +115,6 @@ class HomematicipAccesspointStatus(HomematicipGenericDevice):
def __init__(self, home: AsyncHome) -> None: def __init__(self, home: AsyncHome) -> None:
"""Initialize access point device.""" """Initialize access point device."""
home.modelType = "HmIP-HAP"
super().__init__(home, home) super().__init__(home, home)
@property @property
@ -152,7 +151,12 @@ class HomematicipAccesspointStatus(HomematicipGenericDevice):
@property @property
def device_state_attributes(self): def device_state_attributes(self):
"""Return the state attributes of the access point.""" """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): class HomematicipHeatingThermostat(HomematicipGenericDevice):
@ -316,7 +320,7 @@ class HomematicipWindspeedSensor(HomematicipGenericDevice):
state_attr = super().device_state_attributes state_attr = super().device_state_attributes
wind_direction = getattr(self._device, "windDirection", None) 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) state_attr[ATTR_WIND_DIRECTION] = _get_wind_direction(wind_direction)
wind_direction_variation = getattr(self._device, "windDirectionVariation", None) wind_direction_variation = getattr(self._device, "windDirectionVariation", None)

View File

@ -19,7 +19,7 @@ from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from . import DOMAIN as HMIPC_DOMAIN, HMIPC_HAPID, HomematicipGenericDevice 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__) _LOGGER = logging.getLogger(__name__)
@ -113,9 +113,11 @@ class HomematicipGroupSwitch(HomematicipGenericDevice, SwitchDevice):
@property @property
def device_state_attributes(self): def device_state_attributes(self):
"""Return the state attributes of the switch-group.""" """Return the state attributes of the switch-group."""
state_attr = {ATTR_IS_GROUP: True} state_attr = super().device_state_attributes
if self._device.unreach: if self._device.unreach:
state_attr[ATTR_GROUP_MEMBER_UNREACHABLE] = True state_attr[ATTR_GROUP_MEMBER_UNREACHABLE] = True
return state_attr return state_attr
async def async_turn_on(self, **kwargs): async def async_turn_on(self, **kwargs):

View File

@ -123,7 +123,7 @@ class HomematicipHomeWeather(HomematicipGenericDevice, WeatherEntity):
def __init__(self, home: AsyncHome) -> None: def __init__(self, home: AsyncHome) -> None:
"""Initialize the home weather.""" """Initialize the home weather."""
home.weather.modelType = "HmIP-Home-Weather" home.modelType = "HmIP-Home-Weather"
super().__init__(home, home) super().__init__(home, home)
@property @property