diff --git a/homeassistant/components/homematicip_cloud/alarm_control_panel.py b/homeassistant/components/homematicip_cloud/alarm_control_panel.py index dc249775e3d..efa1ea1f46e 100644 --- a/homeassistant/components/homematicip_cloud/alarm_control_panel.py +++ b/homeassistant/components/homematicip_cloud/alarm_control_panel.py @@ -42,7 +42,7 @@ class HomematicipSecurityZone(HomematicipGenericDevice, AlarmControlPanel): def __init__(self, home, device): """Initialize the security zone group.""" device.modelType = 'Group-SecurityZone' - device.windowState = '' + device.windowState = None super().__init__(home, device) @property @@ -52,7 +52,8 @@ class HomematicipSecurityZone(HomematicipGenericDevice, AlarmControlPanel): if self._device.active: if (self._device.sabotage or self._device.motionDetected or - self._device.windowState == WindowState.OPEN): + self._device.windowState == WindowState.OPEN or + self._device.windowState == WindowState.TILTED): return STATE_ALARM_TRIGGERED active = self._home.get_security_zones_activation() diff --git a/homeassistant/components/homematicip_cloud/binary_sensor.py b/homeassistant/components/homematicip_cloud/binary_sensor.py index 9ed9d29ad39..4b82a500bde 100644 --- a/homeassistant/components/homematicip_cloud/binary_sensor.py +++ b/homeassistant/components/homematicip_cloud/binary_sensor.py @@ -9,6 +9,14 @@ DEPENDENCIES = ['homematicip_cloud'] _LOGGER = logging.getLogger(__name__) +ATTR_MOTIONDETECTED = 'motion detected' +ATTR_PRESENCEDETECTED = 'presence detected' +ATTR_POWERMAINSFAILURE = 'power mains failure' +ATTR_WINDOWSTATE = 'window state' +ATTR_MOISTUREDETECTED = 'moisture detected' +ATTR_WATERLEVELDETECTED = 'water level detected' +ATTR_SMOKEDETECTORALARM = 'smoke detector alarm' + async def async_setup_platform( hass, config, async_add_entities, discovery_info=None): @@ -23,6 +31,9 @@ async def async_setup_entry(hass, config_entry, async_add_entities): AsyncWaterSensor, AsyncRotaryHandleSensor, AsyncMotionDetectorPushButton) + from homematicip.group import ( + SecurityGroup, SecurityZoneGroup) + home = hass.data[HMIPC_DOMAIN][config_entry.data[HMIPC_HAPID]].home devices = [] for device in home.devices: @@ -36,6 +47,12 @@ async def async_setup_entry(hass, config_entry, async_add_entities): elif isinstance(device, AsyncWaterSensor): devices.append(HomematicipWaterDetector(home, device)) + for group in home.groups: + if isinstance(group, SecurityGroup): + devices.append(HomematicipSecuritySensorGroup(home, group)) + elif isinstance(group, SecurityZoneGroup): + devices.append(HomematicipSecurityZoneSensorGroup(home, group)) + if devices: async_add_entities(devices) @@ -104,3 +121,91 @@ class HomematicipWaterDetector(HomematicipGenericDevice, BinarySensorDevice): def is_on(self): """Return true if moisture or waterlevel is detected.""" return self._device.moistureDetected or self._device.waterlevelDetected + + +class HomematicipSecurityZoneSensorGroup(HomematicipGenericDevice, + BinarySensorDevice): + """Representation of a HomematicIP Cloud security zone group.""" + + def __init__(self, home, device, post='SecurityZone'): + """Initialize security zone group.""" + device.modelType = 'HmIP-{}'.format(post) + super().__init__(home, device, post) + + @property + def device_class(self): + """Return the class of this sensor.""" + return 'safety' + + @property + def device_state_attributes(self): + """Return the state attributes of the security zone group.""" + attr = super().device_state_attributes + + if self._device.motionDetected: + attr.update({ATTR_MOTIONDETECTED: True}) + if self._device.presenceDetected: + attr.update({ATTR_PRESENCEDETECTED: True}) + from homematicip.base.enums import WindowState + if self._device.windowState is not None and \ + self._device.windowState != WindowState.CLOSED: + attr.update({ATTR_WINDOWSTATE: str(self._device.windowState)}) + + return attr + + @property + def is_on(self): + """Return true if security issue detected.""" + if self._device.motionDetected or \ + self._device.presenceDetected: + return True + from homematicip.base.enums import WindowState + if self._device.windowState is not None and \ + self._device.windowState != WindowState.CLOSED: + return True + return False + + +class HomematicipSecuritySensorGroup(HomematicipSecurityZoneSensorGroup, + BinarySensorDevice): + """Representation of a HomematicIP security group.""" + + def __init__(self, home, device): + """Initialize security group.""" + super().__init__(home, device, 'Sensors') + + @property + def device_state_attributes(self): + """Return the state attributes of the security group.""" + attr = super().device_state_attributes + + if self._device.powerMainsFailure: + attr.update({ATTR_POWERMAINSFAILURE: True}) + if self._device.moistureDetected: + attr.update({ATTR_MOISTUREDETECTED: True}) + if self._device.waterlevelDetected: + attr.update({ATTR_WATERLEVELDETECTED: True}) + from homematicip.base.enums import SmokeDetectorAlarmType + if self._device.smokeDetectorAlarmType is not None and \ + self._device.smokeDetectorAlarmType != \ + SmokeDetectorAlarmType.IDLE_OFF: + attr.update({ATTR_SMOKEDETECTORALARM: str( + self._device.smokeDetectorAlarmType)}) + + return attr + + @property + def is_on(self): + """Return true if security issue detected.""" + parent_is_on = super().is_on + from homematicip.base.enums import SmokeDetectorAlarmType + if parent_is_on or \ + self._device.powerMainsFailure or \ + self._device.moistureDetected or \ + self._device.waterlevelDetected: + return True + if self._device.smokeDetectorAlarmType is not None and \ + self._device.smokeDetectorAlarmType != \ + SmokeDetectorAlarmType.IDLE_OFF: + return True + return False diff --git a/homeassistant/components/homematicip_cloud/switch.py b/homeassistant/components/homematicip_cloud/switch.py index ad378074621..057673d8f9b 100644 --- a/homeassistant/components/homematicip_cloud/switch.py +++ b/homeassistant/components/homematicip_cloud/switch.py @@ -29,6 +29,8 @@ async def async_setup_entry(hass, config_entry, async_add_entities): FullFlushSwitchMeasuring, ) + from homematicip.group import SwitchingGroup + home = hass.data[HMIPC_DOMAIN][config_entry.data[HMIPC_HAPID]].home devices = [] for device in home.devices: @@ -43,6 +45,11 @@ async def async_setup_entry(hass, config_entry, async_add_entities): elif isinstance(device, PlugableSwitch): devices.append(HomematicipSwitch(home, device)) + for group in home.groups: + if isinstance(group, SwitchingGroup): + devices.append( + HomematicipGroupSwitch(home, group)) + if devices: async_add_entities(devices) @@ -68,6 +75,28 @@ class HomematicipSwitch(HomematicipGenericDevice, SwitchDevice): await self._device.turn_off() +class HomematicipGroupSwitch(HomematicipGenericDevice, SwitchDevice): + """representation of a HomematicIP switching group.""" + + def __init__(self, home, device, post='Group'): + """Initialize switching group.""" + device.modelType = 'HmIP-{}'.format(post) + super().__init__(home, device, post) + + @property + def is_on(self): + """Return true if group is on.""" + return self._device.on + + async def async_turn_on(self, **kwargs): + """Turn the group on.""" + await self._device.turn_on() + + async def async_turn_off(self, **kwargs): + """Turn the group off.""" + await self._device.turn_off() + + class HomematicipSwitchMeasuring(HomematicipSwitch): """Representation of a HomematicIP measuring switch device."""