mirror of
https://github.com/home-assistant/core.git
synced 2025-07-24 21:57:51 +00:00
Cleanup of HomematicIP Cloud code (#15475)
* Check if device supports lowBat and shows it only if battery is low * Show empty battery icon if lowBat is true * Default return None * Sabotage attribute and icon if device has this feature * Bug fix and cleanup * Use dedicated function for security state * Cleanup of sensor attributes and icons * Empty
This commit is contained in:
parent
e427f9ee38
commit
9c5bbfe96d
@ -20,7 +20,6 @@ DEPENDENCIES = ['homematicip_cloud']
|
|||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
HMIP_OPEN = 'OPEN'
|
|
||||||
HMIP_ZONE_AWAY = 'EXTERNAL'
|
HMIP_ZONE_AWAY = 'EXTERNAL'
|
||||||
HMIP_ZONE_HOME = 'INTERNAL'
|
HMIP_ZONE_HOME = 'INTERNAL'
|
||||||
|
|
||||||
@ -57,14 +56,18 @@ class HomematicipSecurityZone(HomematicipGenericDevice, AlarmControlPanel):
|
|||||||
@property
|
@property
|
||||||
def state(self):
|
def state(self):
|
||||||
"""Return the state of the device."""
|
"""Return the state of the device."""
|
||||||
|
from homematicip.base.enums import WindowState
|
||||||
|
|
||||||
if self._device.active:
|
if self._device.active:
|
||||||
if (self._device.sabotage or self._device.motionDetected or
|
if (self._device.sabotage or self._device.motionDetected or
|
||||||
self._device.windowState == HMIP_OPEN):
|
self._device.windowState == WindowState.OPEN):
|
||||||
return STATE_ALARM_TRIGGERED
|
return STATE_ALARM_TRIGGERED
|
||||||
|
|
||||||
if self._device.label == HMIP_ZONE_HOME:
|
active = self._home.get_security_zones_activation()
|
||||||
return STATE_ALARM_ARMED_HOME
|
if active == (True, True):
|
||||||
return STATE_ALARM_ARMED_AWAY
|
return STATE_ALARM_ARMED_AWAY
|
||||||
|
elif active == (False, True):
|
||||||
|
return STATE_ALARM_ARMED_HOME
|
||||||
|
|
||||||
return STATE_ALARM_DISARMED
|
return STATE_ALARM_DISARMED
|
||||||
|
|
||||||
@ -79,10 +82,3 @@ class HomematicipSecurityZone(HomematicipGenericDevice, AlarmControlPanel):
|
|||||||
async def async_alarm_arm_away(self, code=None):
|
async def async_alarm_arm_away(self, code=None):
|
||||||
"""Send arm away command."""
|
"""Send arm away command."""
|
||||||
await self._home.set_security_zones_activation(True, True)
|
await self._home.set_security_zones_activation(True, True)
|
||||||
|
|
||||||
@property
|
|
||||||
def device_state_attributes(self):
|
|
||||||
"""Return the state attributes of the alarm control device."""
|
|
||||||
# The base class is loading the battery property, but device doesn't
|
|
||||||
# have this property - base class needs clean-up.
|
|
||||||
return None
|
|
||||||
|
@ -62,10 +62,21 @@ class HomematicipGenericDevice(Entity):
|
|||||||
"""Device available."""
|
"""Device available."""
|
||||||
return not self._device.unreach
|
return not self._device.unreach
|
||||||
|
|
||||||
|
@property
|
||||||
|
def icon(self):
|
||||||
|
"""Return the icon."""
|
||||||
|
if hasattr(self._device, 'lowBat') and self._device.lowBat:
|
||||||
|
return 'mdi:battery-outline'
|
||||||
|
if hasattr(self._device, 'sabotage') and self._device.sabotage:
|
||||||
|
return 'mdi:alert'
|
||||||
|
return None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
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."""
|
||||||
return {
|
attr = {ATTR_MODEL_TYPE: self._device.modelType}
|
||||||
ATTR_LOW_BATTERY: self._device.lowBat,
|
if hasattr(self._device, 'lowBat') and self._device.lowBat:
|
||||||
ATTR_MODEL_TYPE: self._device.modelType
|
attr.update({ATTR_LOW_BATTERY: self._device.lowBat})
|
||||||
}
|
if hasattr(self._device, 'sabotage') and self._device.sabotage:
|
||||||
|
attr.update({ATTR_SABOTAGE: self._device.sabotage})
|
||||||
|
return attr
|
||||||
|
@ -80,11 +80,6 @@ class HomematicipAccesspointStatus(HomematicipGenericDevice):
|
|||||||
"""Return the unit this state is expressed in."""
|
"""Return the unit this state is expressed in."""
|
||||||
return '%'
|
return '%'
|
||||||
|
|
||||||
@property
|
|
||||||
def device_state_attributes(self):
|
|
||||||
"""Return the state attributes of the access point."""
|
|
||||||
return {}
|
|
||||||
|
|
||||||
|
|
||||||
class HomematicipHeatingThermostat(HomematicipGenericDevice):
|
class HomematicipHeatingThermostat(HomematicipGenericDevice):
|
||||||
"""MomematicIP heating thermostat representation."""
|
"""MomematicIP heating thermostat representation."""
|
||||||
@ -98,6 +93,8 @@ class HomematicipHeatingThermostat(HomematicipGenericDevice):
|
|||||||
"""Return the icon."""
|
"""Return the icon."""
|
||||||
from homematicip.base.enums import ValveState
|
from homematicip.base.enums import ValveState
|
||||||
|
|
||||||
|
if super().icon:
|
||||||
|
return super().icon
|
||||||
if self._device.valveState != ValveState.ADAPTION_DONE:
|
if self._device.valveState != ValveState.ADAPTION_DONE:
|
||||||
return 'mdi:alert'
|
return 'mdi:alert'
|
||||||
return 'mdi:radiator'
|
return 'mdi:radiator'
|
||||||
|
Loading…
x
Reference in New Issue
Block a user