Add more homematicip cloud components (#14084)
* Add support for shutter contact and motion detector device * Add support for power switch devices * Add support for light switch device * Cleanup binary_switch and light platform * Update comment
This commit is contained in:
parent
ba7333e804
commit
230bd3929c
4 changed files with 249 additions and 1 deletions
85
homeassistant/components/binary_sensor/homematicip_cloud.py
Normal file
85
homeassistant/components/binary_sensor/homematicip_cloud.py
Normal file
|
@ -0,0 +1,85 @@
|
|||
"""
|
||||
Support for HomematicIP binary sensor.
|
||||
|
||||
For more details about this component, please refer to the documentation at
|
||||
https://home-assistant.io/components/binary_sensor.homematicip_cloud/
|
||||
"""
|
||||
|
||||
import logging
|
||||
|
||||
from homeassistant.components.binary_sensor import BinarySensorDevice
|
||||
from homeassistant.components.homematicip_cloud import (
|
||||
HomematicipGenericDevice, DOMAIN as HOMEMATICIP_CLOUD_DOMAIN,
|
||||
ATTR_HOME_ID)
|
||||
|
||||
DEPENDENCIES = ['homematicip_cloud']
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
ATTR_WINDOW_STATE = 'window_state'
|
||||
ATTR_EVENT_DELAY = 'event_delay'
|
||||
ATTR_MOTION_DETECTED = 'motion_detected'
|
||||
ATTR_ILLUMINATION = 'illumination'
|
||||
|
||||
HMIP_OPEN = 'open'
|
||||
|
||||
|
||||
async def async_setup_platform(hass, config, async_add_devices,
|
||||
discovery_info=None):
|
||||
"""Set up the HomematicIP binary sensor devices."""
|
||||
from homematicip.device import (ShutterContact, MotionDetectorIndoor)
|
||||
|
||||
if discovery_info is None:
|
||||
return
|
||||
home = hass.data[HOMEMATICIP_CLOUD_DOMAIN][discovery_info[ATTR_HOME_ID]]
|
||||
devices = []
|
||||
for device in home.devices:
|
||||
if isinstance(device, ShutterContact):
|
||||
devices.append(HomematicipShutterContact(home, device))
|
||||
elif isinstance(device, MotionDetectorIndoor):
|
||||
devices.append(HomematicipMotionDetector(home, device))
|
||||
|
||||
if devices:
|
||||
async_add_devices(devices)
|
||||
|
||||
|
||||
class HomematicipShutterContact(HomematicipGenericDevice, BinarySensorDevice):
|
||||
"""HomematicIP shutter contact."""
|
||||
|
||||
def __init__(self, home, device):
|
||||
"""Initialize the shutter contact."""
|
||||
super().__init__(home, device)
|
||||
|
||||
@property
|
||||
def device_class(self):
|
||||
"""Return the class of this sensor."""
|
||||
return 'door'
|
||||
|
||||
@property
|
||||
def is_on(self):
|
||||
"""Return true if the shutter contact is on/open."""
|
||||
if self._device.sabotage:
|
||||
return True
|
||||
if self._device.windowState is None:
|
||||
return None
|
||||
return self._device.windowState.lower() == HMIP_OPEN
|
||||
|
||||
|
||||
class HomematicipMotionDetector(HomematicipGenericDevice, BinarySensorDevice):
|
||||
"""MomematicIP motion detector."""
|
||||
|
||||
def __init__(self, home, device):
|
||||
"""Initialize the shutter contact."""
|
||||
super().__init__(home, device)
|
||||
|
||||
@property
|
||||
def device_class(self):
|
||||
"""Return the class of this sensor."""
|
||||
return 'motion'
|
||||
|
||||
@property
|
||||
def is_on(self):
|
||||
"""Return true if motion is detected."""
|
||||
if self._device.sabotage:
|
||||
return True
|
||||
return self._device.motionDetected
|
|
@ -24,7 +24,10 @@ _LOGGER = logging.getLogger(__name__)
|
|||
DOMAIN = 'homematicip_cloud'
|
||||
|
||||
COMPONENTS = [
|
||||
'sensor'
|
||||
'sensor',
|
||||
'binary_sensor',
|
||||
'switch',
|
||||
'light'
|
||||
]
|
||||
|
||||
CONF_NAME = 'name'
|
||||
|
|
76
homeassistant/components/light/homematicip_cloud.py
Normal file
76
homeassistant/components/light/homematicip_cloud.py
Normal file
|
@ -0,0 +1,76 @@
|
|||
"""
|
||||
Support for HomematicIP light.
|
||||
|
||||
For more details about this component, please refer to the documentation at
|
||||
https://home-assistant.io/components/light.homematicip_cloud/
|
||||
"""
|
||||
|
||||
import logging
|
||||
|
||||
from homeassistant.components.light import Light
|
||||
from homeassistant.components.homematicip_cloud import (
|
||||
HomematicipGenericDevice, DOMAIN as HOMEMATICIP_CLOUD_DOMAIN,
|
||||
ATTR_HOME_ID)
|
||||
|
||||
DEPENDENCIES = ['homematicip_cloud']
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
ATTR_POWER_CONSUMPTION = 'power_consumption'
|
||||
ATTR_ENERGIE_COUNTER = 'energie_counter'
|
||||
ATTR_PROFILE_MODE = 'profile_mode'
|
||||
|
||||
|
||||
async def async_setup_platform(hass, config, async_add_devices,
|
||||
discovery_info=None):
|
||||
"""Set up the HomematicIP light devices."""
|
||||
from homematicip.device import (
|
||||
BrandSwitchMeasuring)
|
||||
|
||||
if discovery_info is None:
|
||||
return
|
||||
home = hass.data[HOMEMATICIP_CLOUD_DOMAIN][discovery_info[ATTR_HOME_ID]]
|
||||
devices = []
|
||||
for device in home.devices:
|
||||
if isinstance(device, BrandSwitchMeasuring):
|
||||
devices.append(HomematicipLightMeasuring(home, device))
|
||||
|
||||
if devices:
|
||||
async_add_devices(devices)
|
||||
|
||||
|
||||
class HomematicipLight(HomematicipGenericDevice, Light):
|
||||
"""MomematicIP light device."""
|
||||
|
||||
def __init__(self, home, device):
|
||||
"""Initialize the light device."""
|
||||
super().__init__(home, device)
|
||||
|
||||
@property
|
||||
def is_on(self):
|
||||
"""Return true if device is on."""
|
||||
return self._device.on
|
||||
|
||||
async def async_turn_on(self, **kwargs):
|
||||
"""Turn the device on."""
|
||||
await self._device.turn_on()
|
||||
|
||||
async def async_turn_off(self, **kwargs):
|
||||
"""Turn the device off."""
|
||||
await self._device.turn_off()
|
||||
|
||||
|
||||
class HomematicipLightMeasuring(HomematicipLight):
|
||||
"""MomematicIP measuring light device."""
|
||||
|
||||
@property
|
||||
def current_power_w(self):
|
||||
"""Return the current power usage in W."""
|
||||
return self._device.currentPowerConsumption
|
||||
|
||||
@property
|
||||
def today_energy_kwh(self):
|
||||
"""Return the today total energy usage in kWh."""
|
||||
if self._device.energyCounter is None:
|
||||
return 0
|
||||
return round(self._device.energyCounter)
|
84
homeassistant/components/switch/homematicip_cloud.py
Normal file
84
homeassistant/components/switch/homematicip_cloud.py
Normal file
|
@ -0,0 +1,84 @@
|
|||
"""
|
||||
Support for HomematicIP switch.
|
||||
|
||||
For more details about this component, please refer to the documentation at
|
||||
https://home-assistant.io/components/switch.homematicip_cloud/
|
||||
"""
|
||||
|
||||
import logging
|
||||
|
||||
from homeassistant.components.switch import SwitchDevice
|
||||
from homeassistant.components.homematicip_cloud import (
|
||||
HomematicipGenericDevice, DOMAIN as HOMEMATICIP_CLOUD_DOMAIN,
|
||||
ATTR_HOME_ID)
|
||||
|
||||
DEPENDENCIES = ['homematicip_cloud']
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
ATTR_POWER_CONSUMPTION = 'power_consumption'
|
||||
ATTR_ENERGIE_COUNTER = 'energie_counter'
|
||||
ATTR_PROFILE_MODE = 'profile_mode'
|
||||
|
||||
|
||||
async def async_setup_platform(hass, config, async_add_devices,
|
||||
discovery_info=None):
|
||||
"""Set up the HomematicIP switch devices."""
|
||||
from homematicip.device import (
|
||||
PlugableSwitch, PlugableSwitchMeasuring,
|
||||
BrandSwitchMeasuring)
|
||||
|
||||
if discovery_info is None:
|
||||
return
|
||||
home = hass.data[HOMEMATICIP_CLOUD_DOMAIN][discovery_info[ATTR_HOME_ID]]
|
||||
devices = []
|
||||
for device in home.devices:
|
||||
if isinstance(device, BrandSwitchMeasuring):
|
||||
# BrandSwitchMeasuring inherits PlugableSwitchMeasuring
|
||||
# This device is implemented in the light platform and will
|
||||
# not be added in the switch platform
|
||||
pass
|
||||
elif isinstance(device, PlugableSwitchMeasuring):
|
||||
devices.append(HomematicipSwitchMeasuring(home, device))
|
||||
elif isinstance(device, PlugableSwitch):
|
||||
devices.append(HomematicipSwitch(home, device))
|
||||
|
||||
if devices:
|
||||
async_add_devices(devices)
|
||||
|
||||
|
||||
class HomematicipSwitch(HomematicipGenericDevice, SwitchDevice):
|
||||
"""MomematicIP switch device."""
|
||||
|
||||
def __init__(self, home, device):
|
||||
"""Initialize the switch device."""
|
||||
super().__init__(home, device)
|
||||
|
||||
@property
|
||||
def is_on(self):
|
||||
"""Return true if device is on."""
|
||||
return self._device.on
|
||||
|
||||
async def async_turn_on(self, **kwargs):
|
||||
"""Turn the device on."""
|
||||
await self._device.turn_on()
|
||||
|
||||
async def async_turn_off(self, **kwargs):
|
||||
"""Turn the device off."""
|
||||
await self._device.turn_off()
|
||||
|
||||
|
||||
class HomematicipSwitchMeasuring(HomematicipSwitch):
|
||||
"""MomematicIP measuring switch device."""
|
||||
|
||||
@property
|
||||
def current_power_w(self):
|
||||
"""Return the current power usage in W."""
|
||||
return self._device.currentPowerConsumption
|
||||
|
||||
@property
|
||||
def today_energy_kwh(self):
|
||||
"""Return the today total energy usage in kWh."""
|
||||
if self._device.energyCounter is None:
|
||||
return 0
|
||||
return round(self._device.energyCounter)
|
Loading…
Add table
Add a link
Reference in a new issue