mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 21:27:38 +00:00
Fix group-switch availability for Homematic IP (#21640)
* Add available=True to groups * Added unreach to stateattributes * Fixed comments * added missing sabotage check * added missing lowBat check * fix typo * apply suggestion Co-Authored-By: SukramJ <markus@mm-jankowski.de> * apply suggestion Co-Authored-By: SukramJ <markus@mm-jankowski.de> * applied suggiestions * readded lost str() * fix comment
This commit is contained in:
parent
a46458d04f
commit
1891d5bf22
@ -4,6 +4,8 @@ import logging
|
|||||||
from homeassistant.components.binary_sensor import BinarySensorDevice
|
from homeassistant.components.binary_sensor import BinarySensorDevice
|
||||||
from homeassistant.components.homematicip_cloud import (
|
from homeassistant.components.homematicip_cloud import (
|
||||||
DOMAIN as HMIPC_DOMAIN, HMIPC_HAPID, HomematicipGenericDevice)
|
DOMAIN as HMIPC_DOMAIN, HMIPC_HAPID, HomematicipGenericDevice)
|
||||||
|
from homeassistant.components.homematicip_cloud.device import (
|
||||||
|
ATTR_GROUP_MEMBER_UNREACHABLE)
|
||||||
|
|
||||||
DEPENDENCIES = ['homematicip_cloud']
|
DEPENDENCIES = ['homematicip_cloud']
|
||||||
|
|
||||||
@ -31,8 +33,8 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
|
|||||||
AsyncWaterSensor, AsyncRotaryHandleSensor,
|
AsyncWaterSensor, AsyncRotaryHandleSensor,
|
||||||
AsyncMotionDetectorPushButton)
|
AsyncMotionDetectorPushButton)
|
||||||
|
|
||||||
from homematicip.group import (
|
from homematicip.aio.group import (
|
||||||
SecurityGroup, SecurityZoneGroup)
|
AsyncSecurityGroup, AsyncSecurityZoneGroup)
|
||||||
|
|
||||||
home = hass.data[HMIPC_DOMAIN][config_entry.data[HMIPC_HAPID]].home
|
home = hass.data[HMIPC_DOMAIN][config_entry.data[HMIPC_HAPID]].home
|
||||||
devices = []
|
devices = []
|
||||||
@ -48,9 +50,9 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
|
|||||||
devices.append(HomematicipWaterDetector(home, device))
|
devices.append(HomematicipWaterDetector(home, device))
|
||||||
|
|
||||||
for group in home.groups:
|
for group in home.groups:
|
||||||
if isinstance(group, SecurityGroup):
|
if isinstance(group, AsyncSecurityGroup):
|
||||||
devices.append(HomematicipSecuritySensorGroup(home, group))
|
devices.append(HomematicipSecuritySensorGroup(home, group))
|
||||||
elif isinstance(group, SecurityZoneGroup):
|
elif isinstance(group, AsyncSecurityZoneGroup):
|
||||||
devices.append(HomematicipSecurityZoneSensorGroup(home, group))
|
devices.append(HomematicipSecurityZoneSensorGroup(home, group))
|
||||||
|
|
||||||
if devices:
|
if devices:
|
||||||
@ -137,27 +139,37 @@ class HomematicipSecurityZoneSensorGroup(HomematicipGenericDevice,
|
|||||||
"""Return the class of this sensor."""
|
"""Return the class of this sensor."""
|
||||||
return 'safety'
|
return 'safety'
|
||||||
|
|
||||||
|
@property
|
||||||
|
def available(self):
|
||||||
|
"""Security-Group available."""
|
||||||
|
# A security-group must be available, and should not be affected by
|
||||||
|
# the individual availability of group members.
|
||||||
|
return True
|
||||||
|
|
||||||
@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."""
|
||||||
attr = super().device_state_attributes
|
attr = super().device_state_attributes
|
||||||
|
|
||||||
if self._device.motionDetected:
|
if self._device.motionDetected:
|
||||||
attr.update({ATTR_MOTIONDETECTED: True})
|
attr[ATTR_MOTIONDETECTED] = True
|
||||||
if self._device.presenceDetected:
|
if self._device.presenceDetected:
|
||||||
attr.update({ATTR_PRESENCEDETECTED: True})
|
attr[ATTR_PRESENCEDETECTED] = True
|
||||||
from homematicip.base.enums import WindowState
|
from homematicip.base.enums import WindowState
|
||||||
if self._device.windowState is not None and \
|
if self._device.windowState is not None and \
|
||||||
self._device.windowState != WindowState.CLOSED:
|
self._device.windowState != WindowState.CLOSED:
|
||||||
attr.update({ATTR_WINDOWSTATE: str(self._device.windowState)})
|
attr[ATTR_WINDOWSTATE] = str(self._device.windowState)
|
||||||
|
if self._device.unreach:
|
||||||
|
attr[ATTR_GROUP_MEMBER_UNREACHABLE] = True
|
||||||
return attr
|
return attr
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_on(self):
|
def is_on(self):
|
||||||
"""Return true if security issue detected."""
|
"""Return true if security issue detected."""
|
||||||
if self._device.motionDetected or \
|
if self._device.motionDetected or \
|
||||||
self._device.presenceDetected:
|
self._device.presenceDetected or \
|
||||||
|
self._device.unreach or \
|
||||||
|
self._device.sabotage:
|
||||||
return True
|
return True
|
||||||
from homematicip.base.enums import WindowState
|
from homematicip.base.enums import WindowState
|
||||||
if self._device.windowState is not None and \
|
if self._device.windowState is not None and \
|
||||||
@ -180,29 +192,30 @@ class HomematicipSecuritySensorGroup(HomematicipSecurityZoneSensorGroup,
|
|||||||
attr = super().device_state_attributes
|
attr = super().device_state_attributes
|
||||||
|
|
||||||
if self._device.powerMainsFailure:
|
if self._device.powerMainsFailure:
|
||||||
attr.update({ATTR_POWERMAINSFAILURE: True})
|
attr[ATTR_POWERMAINSFAILURE] = True
|
||||||
if self._device.moistureDetected:
|
if self._device.moistureDetected:
|
||||||
attr.update({ATTR_MOISTUREDETECTED: True})
|
attr[ATTR_MOISTUREDETECTED] = True
|
||||||
if self._device.waterlevelDetected:
|
if self._device.waterlevelDetected:
|
||||||
attr.update({ATTR_WATERLEVELDETECTED: True})
|
attr[ATTR_WATERLEVELDETECTED] = True
|
||||||
from homematicip.base.enums import SmokeDetectorAlarmType
|
from homematicip.base.enums import SmokeDetectorAlarmType
|
||||||
if self._device.smokeDetectorAlarmType is not None and \
|
if self._device.smokeDetectorAlarmType is not None and \
|
||||||
self._device.smokeDetectorAlarmType != \
|
self._device.smokeDetectorAlarmType != \
|
||||||
SmokeDetectorAlarmType.IDLE_OFF:
|
SmokeDetectorAlarmType.IDLE_OFF:
|
||||||
attr.update({ATTR_SMOKEDETECTORALARM: str(
|
attr[ATTR_SMOKEDETECTORALARM] = \
|
||||||
self._device.smokeDetectorAlarmType)})
|
str(self._device.smokeDetectorAlarmType)
|
||||||
|
|
||||||
return attr
|
return attr
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_on(self):
|
def is_on(self):
|
||||||
"""Return true if security issue detected."""
|
"""Return true if safety issue detected."""
|
||||||
parent_is_on = super().is_on
|
parent_is_on = super().is_on
|
||||||
from homematicip.base.enums import SmokeDetectorAlarmType
|
from homematicip.base.enums import SmokeDetectorAlarmType
|
||||||
if parent_is_on or \
|
if parent_is_on or \
|
||||||
self._device.powerMainsFailure or \
|
self._device.powerMainsFailure or \
|
||||||
self._device.moistureDetected or \
|
self._device.moistureDetected or \
|
||||||
self._device.waterlevelDetected:
|
self._device.waterlevelDetected or \
|
||||||
|
self._device.lowBat:
|
||||||
return True
|
return True
|
||||||
if self._device.smokeDetectorAlarmType is not None and \
|
if self._device.smokeDetectorAlarmType is not None and \
|
||||||
self._device.smokeDetectorAlarmType != \
|
self._device.smokeDetectorAlarmType != \
|
||||||
|
@ -21,6 +21,7 @@ ATTR_OPERATION_LOCK = 'operation_lock'
|
|||||||
ATTR_SABOTAGE = 'sabotage'
|
ATTR_SABOTAGE = 'sabotage'
|
||||||
ATTR_STATUS_UPDATE = 'status_update'
|
ATTR_STATUS_UPDATE = 'status_update'
|
||||||
ATTR_UNREACHABLE = 'unreachable'
|
ATTR_UNREACHABLE = 'unreachable'
|
||||||
|
ATTR_GROUP_MEMBER_UNREACHABLE = 'group_member_unreachable'
|
||||||
|
|
||||||
|
|
||||||
class HomematicipGenericDevice(Entity):
|
class HomematicipGenericDevice(Entity):
|
||||||
|
@ -3,6 +3,8 @@ import logging
|
|||||||
|
|
||||||
from homeassistant.components.homematicip_cloud import (
|
from homeassistant.components.homematicip_cloud import (
|
||||||
DOMAIN as HMIPC_DOMAIN, HMIPC_HAPID, HomematicipGenericDevice)
|
DOMAIN as HMIPC_DOMAIN, HMIPC_HAPID, HomematicipGenericDevice)
|
||||||
|
from homeassistant.components.homematicip_cloud.device import (
|
||||||
|
ATTR_GROUP_MEMBER_UNREACHABLE)
|
||||||
from homeassistant.components.switch import SwitchDevice
|
from homeassistant.components.switch import SwitchDevice
|
||||||
|
|
||||||
DEPENDENCIES = ['homematicip_cloud']
|
DEPENDENCIES = ['homematicip_cloud']
|
||||||
@ -30,7 +32,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
|
|||||||
AsyncOpenCollector8Module,
|
AsyncOpenCollector8Module,
|
||||||
)
|
)
|
||||||
|
|
||||||
from homematicip.group import SwitchingGroup
|
from homematicip.aio.group import AsyncSwitchingGroup
|
||||||
|
|
||||||
home = hass.data[HMIPC_DOMAIN][config_entry.data[HMIPC_HAPID]].home
|
home = hass.data[HMIPC_DOMAIN][config_entry.data[HMIPC_HAPID]].home
|
||||||
devices = []
|
devices = []
|
||||||
@ -50,7 +52,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
|
|||||||
devices.append(HomematicipMultiSwitch(home, device, channel))
|
devices.append(HomematicipMultiSwitch(home, device, channel))
|
||||||
|
|
||||||
for group in home.groups:
|
for group in home.groups:
|
||||||
if isinstance(group, SwitchingGroup):
|
if isinstance(group, AsyncSwitchingGroup):
|
||||||
devices.append(
|
devices.append(
|
||||||
HomematicipGroupSwitch(home, group))
|
HomematicipGroupSwitch(home, group))
|
||||||
|
|
||||||
@ -92,6 +94,23 @@ class HomematicipGroupSwitch(HomematicipGenericDevice, SwitchDevice):
|
|||||||
"""Return true if group is on."""
|
"""Return true if group is on."""
|
||||||
return self._device.on
|
return self._device.on
|
||||||
|
|
||||||
|
@property
|
||||||
|
def available(self):
|
||||||
|
"""Switch-Group available."""
|
||||||
|
# A switch-group must be available, and should not be affected by the
|
||||||
|
# individual availability of group members.
|
||||||
|
# This allows switching even when individual group members
|
||||||
|
# are not available.
|
||||||
|
return True
|
||||||
|
|
||||||
|
@property
|
||||||
|
def device_state_attributes(self):
|
||||||
|
"""Return the state attributes of the switch-group."""
|
||||||
|
attr = {}
|
||||||
|
if self._device.unreach:
|
||||||
|
attr[ATTR_GROUP_MEMBER_UNREACHABLE] = True
|
||||||
|
return attr
|
||||||
|
|
||||||
async def async_turn_on(self, **kwargs):
|
async def async_turn_on(self, **kwargs):
|
||||||
"""Turn the group on."""
|
"""Turn the group on."""
|
||||||
await self._device.turn_on()
|
await self._device.turn_on()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user