Add HomematicIP HmIP-OC8 module (#21401)

* Add support for HmIP-OC8 module

* Fix line lenght
pull/20204/head
Mattias Welponer 2019-02-26 23:48:19 +01:00 committed by Paulus Schoutsen
parent 7bae76843c
commit 42e691c194
1 changed files with 41 additions and 9 deletions

View File

@ -22,11 +22,12 @@ async def async_setup_platform(
async def async_setup_entry(hass, config_entry, async_add_entities):
"""Set up the HomematicIP switch from a config entry."""
from homematicip.device import (
PlugableSwitch,
PlugableSwitchMeasuring,
BrandSwitchMeasuring,
FullFlushSwitchMeasuring,
from homematicip.aio.device import (
AsyncPlugableSwitch,
AsyncPlugableSwitchMeasuring,
AsyncBrandSwitchMeasuring,
AsyncFullFlushSwitchMeasuring,
AsyncOpenCollector8Module,
)
from homematicip.group import SwitchingGroup
@ -34,16 +35,19 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
home = hass.data[HMIPC_DOMAIN][config_entry.data[HMIPC_HAPID]].home
devices = []
for device in home.devices:
if isinstance(device, BrandSwitchMeasuring):
if isinstance(device, AsyncBrandSwitchMeasuring):
# 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,
FullFlushSwitchMeasuring)):
elif isinstance(device, (AsyncPlugableSwitchMeasuring,
AsyncFullFlushSwitchMeasuring)):
devices.append(HomematicipSwitchMeasuring(home, device))
elif isinstance(device, PlugableSwitch):
elif isinstance(device, AsyncPlugableSwitch):
devices.append(HomematicipSwitch(home, device))
elif isinstance(device, AsyncOpenCollector8Module):
for channel in range(1, 9):
devices.append(HomematicipMultiSwitch(home, device, channel))
for group in home.groups:
if isinstance(group, SwitchingGroup):
@ -111,3 +115,31 @@ class HomematicipSwitchMeasuring(HomematicipSwitch):
if self._device.energyCounter is None:
return 0
return round(self._device.energyCounter)
class HomematicipMultiSwitch(HomematicipGenericDevice, SwitchDevice):
"""Representation of a HomematicIP Cloud multi switch device."""
def __init__(self, home, device, channel):
"""Initialize the multi switch device."""
self.channel = channel
super().__init__(home, device, 'Channel{}'.format(channel))
@property
def unique_id(self):
"""Return a unique ID."""
return "{}_{}_{}".format(self.__class__.__name__,
self.post, self._device.id)
@property
def is_on(self):
"""Return true if device is on."""
return self._device.functionalChannels[self.channel].on
async def async_turn_on(self, **kwargs):
"""Turn the device on."""
await self._device.turn_on(self.channel)
async def async_turn_off(self, **kwargs):
"""Turn the device off."""
await self._device.turn_off(self.channel)