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:
Mattias Welponer 2018-07-18 12:19:08 +02:00 committed by Paulus Schoutsen
parent e427f9ee38
commit 9c5bbfe96d
3 changed files with 24 additions and 20 deletions

View File

@ -20,7 +20,6 @@ DEPENDENCIES = ['homematicip_cloud']
_LOGGER = logging.getLogger(__name__)
HMIP_OPEN = 'OPEN'
HMIP_ZONE_AWAY = 'EXTERNAL'
HMIP_ZONE_HOME = 'INTERNAL'
@ -57,14 +56,18 @@ class HomematicipSecurityZone(HomematicipGenericDevice, AlarmControlPanel):
@property
def state(self):
"""Return the state of the device."""
from homematicip.base.enums import WindowState
if self._device.active:
if (self._device.sabotage or self._device.motionDetected or
self._device.windowState == HMIP_OPEN):
self._device.windowState == WindowState.OPEN):
return STATE_ALARM_TRIGGERED
if self._device.label == HMIP_ZONE_HOME:
return STATE_ALARM_ARMED_HOME
active = self._home.get_security_zones_activation()
if active == (True, True):
return STATE_ALARM_ARMED_AWAY
elif active == (False, True):
return STATE_ALARM_ARMED_HOME
return STATE_ALARM_DISARMED
@ -79,10 +82,3 @@ class HomematicipSecurityZone(HomematicipGenericDevice, AlarmControlPanel):
async def async_alarm_arm_away(self, code=None):
"""Send arm away command."""
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

View File

@ -62,10 +62,21 @@ class HomematicipGenericDevice(Entity):
"""Device available."""
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
def device_state_attributes(self):
"""Return the state attributes of the generic device."""
return {
ATTR_LOW_BATTERY: self._device.lowBat,
ATTR_MODEL_TYPE: self._device.modelType
}
attr = {ATTR_MODEL_TYPE: self._device.modelType}
if hasattr(self._device, 'lowBat') and self._device.lowBat:
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

View File

@ -80,11 +80,6 @@ class HomematicipAccesspointStatus(HomematicipGenericDevice):
"""Return the unit this state is expressed in."""
return '%'
@property
def device_state_attributes(self):
"""Return the state attributes of the access point."""
return {}
class HomematicipHeatingThermostat(HomematicipGenericDevice):
"""MomematicIP heating thermostat representation."""
@ -98,6 +93,8 @@ class HomematicipHeatingThermostat(HomematicipGenericDevice):
"""Return the icon."""
from homematicip.base.enums import ValveState
if super().icon:
return super().icon
if self._device.valveState != ValveState.ADAPTION_DONE:
return 'mdi:alert'
return 'mdi:radiator'