Add HomematicIP HmIP-OC8 module (#21401)
* Add support for HmIP-OC8 module * Fix line lenghtpull/20204/head
parent
7bae76843c
commit
42e691c194
|
@ -22,11 +22,12 @@ async def async_setup_platform(
|
||||||
|
|
||||||
async def async_setup_entry(hass, config_entry, async_add_entities):
|
async def async_setup_entry(hass, config_entry, async_add_entities):
|
||||||
"""Set up the HomematicIP switch from a config entry."""
|
"""Set up the HomematicIP switch from a config entry."""
|
||||||
from homematicip.device import (
|
from homematicip.aio.device import (
|
||||||
PlugableSwitch,
|
AsyncPlugableSwitch,
|
||||||
PlugableSwitchMeasuring,
|
AsyncPlugableSwitchMeasuring,
|
||||||
BrandSwitchMeasuring,
|
AsyncBrandSwitchMeasuring,
|
||||||
FullFlushSwitchMeasuring,
|
AsyncFullFlushSwitchMeasuring,
|
||||||
|
AsyncOpenCollector8Module,
|
||||||
)
|
)
|
||||||
|
|
||||||
from homematicip.group import SwitchingGroup
|
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
|
home = hass.data[HMIPC_DOMAIN][config_entry.data[HMIPC_HAPID]].home
|
||||||
devices = []
|
devices = []
|
||||||
for device in home.devices:
|
for device in home.devices:
|
||||||
if isinstance(device, BrandSwitchMeasuring):
|
if isinstance(device, AsyncBrandSwitchMeasuring):
|
||||||
# BrandSwitchMeasuring inherits PlugableSwitchMeasuring
|
# BrandSwitchMeasuring inherits PlugableSwitchMeasuring
|
||||||
# This device is implemented in the light platform and will
|
# This device is implemented in the light platform and will
|
||||||
# not be added in the switch platform
|
# not be added in the switch platform
|
||||||
pass
|
pass
|
||||||
elif isinstance(device, (PlugableSwitchMeasuring,
|
elif isinstance(device, (AsyncPlugableSwitchMeasuring,
|
||||||
FullFlushSwitchMeasuring)):
|
AsyncFullFlushSwitchMeasuring)):
|
||||||
devices.append(HomematicipSwitchMeasuring(home, device))
|
devices.append(HomematicipSwitchMeasuring(home, device))
|
||||||
elif isinstance(device, PlugableSwitch):
|
elif isinstance(device, AsyncPlugableSwitch):
|
||||||
devices.append(HomematicipSwitch(home, device))
|
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:
|
for group in home.groups:
|
||||||
if isinstance(group, SwitchingGroup):
|
if isinstance(group, SwitchingGroup):
|
||||||
|
@ -111,3 +115,31 @@ class HomematicipSwitchMeasuring(HomematicipSwitch):
|
||||||
if self._device.energyCounter is None:
|
if self._device.energyCounter is None:
|
||||||
return 0
|
return 0
|
||||||
return round(self._device.energyCounter)
|
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)
|
||||||
|
|
Loading…
Reference in New Issue