Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reorg Homematic IP Cloud imports and minor fixes #23330

Merged
merged 7 commits into from
Apr 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
"""Support for HomematicIP Cloud alarm control panel."""
import logging

from homematicip.aio.group import AsyncSecurityZoneGroup
from homematicip.base.enums import WindowState

from homeassistant.components.alarm_control_panel import AlarmControlPanel
from homeassistant.const import (
STATE_ALARM_ARMED_AWAY, STATE_ALARM_ARMED_HOME, STATE_ALARM_DISARMED,
Expand All @@ -18,9 +21,7 @@ async def async_setup_platform(


async def async_setup_entry(hass, config_entry, async_add_entities):
"""Set up the HomematicIP alarm control panel from a config entry."""
from homematicip.aio.group import AsyncSecurityZoneGroup

"""Set up the HomematicIP alrm control panel from a config entry."""
home = hass.data[HMIPC_DOMAIN][config_entry.data[HMIPC_HAPID]].home
devices = []
for group in home.groups:
Expand All @@ -43,8 +44,6 @@ def __init__(self, home, device):
@property
def state(self):
"""Return the state of the device."""
from homematicip.base.enums import WindowState

if self._device.active:
if (self._device.sabotage or self._device.motionDetected or
self._device.windowState == WindowState.OPEN or
Expand Down
27 changes: 11 additions & 16 deletions homeassistant/components/homematicip_cloud/binary_sensor.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
"""Support for HomematicIP Cloud binary sensor."""
import logging

from homematicip.aio.device import (
AsyncDevice, AsyncMotionDetectorIndoor, AsyncMotionDetectorOutdoor,
AsyncMotionDetectorPushButton, AsyncRotaryHandleSensor,
AsyncShutterContact, AsyncSmokeDetector, AsyncWaterSensor,
AsyncWeatherSensor, AsyncWeatherSensorPlus, AsyncWeatherSensorPro)
from homematicip.aio.group import AsyncSecurityGroup, AsyncSecurityZoneGroup
from homematicip.base.enums import SmokeDetectorAlarmType, WindowState

from homeassistant.components.binary_sensor import BinarySensorDevice

from . import DOMAIN as HMIPC_DOMAIN, HMIPC_HAPID, HomematicipGenericDevice
Expand All @@ -26,15 +34,6 @@ async def async_setup_platform(

async def async_setup_entry(hass, config_entry, async_add_entities):
"""Set up the HomematicIP Cloud binary sensor from a config entry."""
from homematicip.aio.device import (
AsyncDevice, AsyncShutterContact, AsyncMotionDetectorIndoor,
AsyncMotionDetectorOutdoor, AsyncSmokeDetector, AsyncWaterSensor,
AsyncRotaryHandleSensor, AsyncMotionDetectorPushButton,
AsyncWeatherSensor, AsyncWeatherSensorPlus, AsyncWeatherSensorPro)

from homematicip.aio.group import (
AsyncSecurityGroup, AsyncSecurityZoneGroup)

home = hass.data[HMIPC_DOMAIN][config_entry.data[HMIPC_HAPID]].home
devices = []
for device in home.devices:
Expand Down Expand Up @@ -79,8 +78,6 @@ def device_class(self):
@property
def is_on(self):
"""Return true if the shutter contact is on/open."""
from homematicip.base.enums import WindowState

if self._device.sabotage:
return True
if self._device.windowState is None:
Expand Down Expand Up @@ -115,7 +112,6 @@ def device_class(self):
@property
def is_on(self):
"""Return true if smoke is detected."""
from homematicip.base.enums import SmokeDetectorAlarmType
return (self._device.smokeDetectorAlarmType
!= SmokeDetectorAlarmType.IDLE_OFF)

Expand Down Expand Up @@ -246,7 +242,7 @@ def device_state_attributes(self):
attr[ATTR_MOTIONDETECTED] = True
if self._device.presenceDetected:
attr[ATTR_PRESENCEDETECTED] = True
from homematicip.base.enums import WindowState

if self._device.windowState is not None and \
self._device.windowState != WindowState.CLOSED:
attr[ATTR_WINDOWSTATE] = str(self._device.windowState)
Expand All @@ -262,7 +258,7 @@ def is_on(self):
self._device.unreach or \
self._device.sabotage:
return True
from homematicip.base.enums import WindowState

if self._device.windowState is not None and \
self._device.windowState != WindowState.CLOSED:
return True
Expand All @@ -288,7 +284,7 @@ def device_state_attributes(self):
attr[ATTR_MOISTUREDETECTED] = True
if self._device.waterlevelDetected:
attr[ATTR_WATERLEVELDETECTED] = True
from homematicip.base.enums import SmokeDetectorAlarmType

if self._device.smokeDetectorAlarmType is not None and \
self._device.smokeDetectorAlarmType != \
SmokeDetectorAlarmType.IDLE_OFF:
Expand All @@ -301,7 +297,6 @@ def device_state_attributes(self):
def is_on(self):
"""Return true if safety 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 \
Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/homematicip_cloud/climate.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
"""Support for HomematicIP Cloud climate devices."""
import logging

from homematicip.group import HeatingGroup

from homeassistant.components.climate import ClimateDevice
from homeassistant.components.climate.const import (
STATE_AUTO, STATE_MANUAL, SUPPORT_TARGET_TEMPERATURE)
Expand All @@ -26,8 +28,6 @@ async def async_setup_platform(

async def async_setup_entry(hass, config_entry, async_add_entities):
"""Set up the HomematicIP climate from a config entry."""
from homematicip.group import HeatingGroup

home = hass.data[HMIPC_DOMAIN][config_entry.data[HMIPC_HAPID]].home
devices = []
for device in home.groups:
Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/homematicip_cloud/cover.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
"""Support for HomematicIP Cloud cover devices."""
import logging

from homematicip.aio.device import AsyncFullFlushShutter

from homeassistant.components.cover import ATTR_POSITION, CoverDevice

from . import DOMAIN as HMIPC_DOMAIN, HMIPC_HAPID, HomematicipGenericDevice
Expand All @@ -19,8 +21,6 @@ async def async_setup_platform(

async def async_setup_entry(hass, config_entry, async_add_entities):
"""Set up the HomematicIP cover from a config entry."""
from homematicip.aio.device import AsyncFullFlushShutter

home = hass.data[HMIPC_DOMAIN][config_entry.data[HMIPC_HAPID]].home
devices = []
for device in home.devices:
Expand Down
3 changes: 2 additions & 1 deletion homeassistant/components/homematicip_cloud/device.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
"""Generic device for the HomematicIP Cloud component."""
import logging

from homematicip.aio.device import AsyncDevice

from homeassistant.components import homematicip_cloud
from homeassistant.helpers.entity import Entity

Expand Down Expand Up @@ -29,7 +31,6 @@ def __init__(self, home, device, post=None):
@property
def device_info(self):
"""Return device specific attributes."""
from homematicip.aio.device import AsyncDevice
# Only physical devices should be HA devices.
if isinstance(self._device, AsyncDevice):
return {
Expand Down
20 changes: 5 additions & 15 deletions homeassistant/components/homematicip_cloud/hap.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
import asyncio
import logging

from homematicip.aio.auth import AsyncAuth
from homematicip.aio.home import AsyncHome
from homematicip.base.base_connection import HmipConnectionError

from homeassistant.core import callback
from homeassistant.exceptions import ConfigEntryNotReady
from homeassistant.helpers.aiohttp_client import async_get_clientsession
Expand Down Expand Up @@ -36,17 +40,13 @@ async def async_setup(self):

async def async_checkbutton(self):
"""Check blue butten has been pressed."""
from homematicip.base.base_connection import HmipConnectionError

try:
return await self.auth.isRequestAcknowledged()
except HmipConnectionError:
return False

async def async_register(self):
"""Register client at HomematicIP."""
from homematicip.base.base_connection import HmipConnectionError

try:
authtoken = await self.auth.requestAuthToken()
await self.auth.confirmAuthToken(authtoken)
Expand All @@ -56,9 +56,6 @@ async def async_register(self):

async def get_auth(self, hass, hapid, pin):
"""Create a HomematicIP access point object."""
from homematicip.aio.auth import AsyncAuth
from homematicip.base.base_connection import HmipConnectionError

auth = AsyncAuth(hass.loop, async_get_clientsession(hass))
try:
await auth.init(hapid)
Expand Down Expand Up @@ -138,8 +135,6 @@ async def get_state(self):

def get_state_finished(self, future):
"""Execute when get_state coroutine has finished."""
from homematicip.base.base_connection import HmipConnectionError

try:
future.result()
except HmipConnectionError:
Expand All @@ -162,8 +157,6 @@ def update_all(self):

async def async_connect(self):
"""Start WebSocket connection."""
from homematicip.base.base_connection import HmipConnectionError

tries = 0
while True:
retry_delay = 2 ** min(tries, 8)
Expand Down Expand Up @@ -203,11 +196,8 @@ async def async_reset(self):
self.config_entry, component)
return True

async def get_hap(self, hass, hapid, authtoken, name):
async def get_hap(self, hass, hapid, authtoken, name) -> AsyncHome:
"""Create a HomematicIP access point object."""
from homematicip.aio.home import AsyncHome
from homematicip.base.base_connection import HmipConnectionError

home = AsyncHome(hass.loop, async_get_clientsession(hass))

home.name = name
Expand Down
41 changes: 23 additions & 18 deletions homeassistant/components/homematicip_cloud/light.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
"""Support for HomematicIP Cloud lights."""
import logging

from homematicip.base.enums import RGBColorState

from homeassistant.components.light import (
ATTR_BRIGHTNESS, ATTR_COLOR_NAME, ATTR_HS_COLOR, SUPPORT_BRIGHTNESS,
SUPPORT_COLOR, Light)
Expand Down Expand Up @@ -90,12 +92,15 @@ def __init__(self, home, device):
@property
def is_on(self):
"""Return true if device is on."""
return self._device.dimLevel != 0
return self._device.dimLevel is not None and \
self._device.dimLevel > 0.0

@property
def brightness(self):
"""Return the brightness of this light between 0..255."""
return int(self._device.dimLevel*255)
if self._device.dimLevel:
return int(self._device.dimLevel*255)
return 0

@property
def supported_features(self):
Expand All @@ -117,15 +122,14 @@ async def async_turn_off(self, **kwargs):
class HomematicipNotificationLight(HomematicipGenericDevice, Light):
"""Representation of HomematicIP Cloud dimmer light device."""

def __init__(self, home, device, channel_index):
def __init__(self, home, device, channel):
"""Initialize the dimmer light device."""
self._channel_index = channel_index
if self._channel_index == 2:
self.channel = channel
if self.channel == 2:
super().__init__(home, device, 'Top')
else:
super().__init__(home, device, 'Bottom')

from homematicip.base.enums import RGBColorState
self._color_switcher = {
RGBColorState.WHITE: [0.0, 0.0],
RGBColorState.RED: [0.0, 100.0],
Expand All @@ -137,31 +141,34 @@ def __init__(self, home, device, channel_index):
}

@property
def _channel(self):
return self._device.functionalChannels[self._channel_index]
def _func_channel(self):
return self._device.functionalChannels[self.channel]

@property
def is_on(self):
"""Return true if device is on."""
return self._channel.dimLevel > 0.0
return self._func_channel.dimLevel is not None and \
self._func_channel.dimLevel > 0.0

@property
def brightness(self):
"""Return the brightness of this light between 0..255."""
return int(self._channel.dimLevel * 255)
if self._func_channel.dimLevel:
return int(self._func_channel.dimLevel * 255)
return 0

@property
def hs_color(self):
"""Return the hue and saturation color value [float, float]."""
simple_rgb_color = self._channel.simpleRGBColorState
simple_rgb_color = self._func_channel.simpleRGBColorState
return self._color_switcher.get(simple_rgb_color, [0.0, 0.0])

@property
def device_state_attributes(self):
"""Return the state attributes of the generic device."""
attr = super().device_state_attributes
if self.is_on:
attr[ATTR_COLOR_NAME] = self._channel.simpleRGBColorState
attr[ATTR_COLOR_NAME] = self._func_channel.simpleRGBColorState
return attr

@property
Expand Down Expand Up @@ -201,27 +208,25 @@ async def async_turn_on(self, **kwargs):
dim_level = brightness / 255.0

await self._device.set_rgb_dim_level(
self._channel_index,
self.channel,
simple_rgb_color,
dim_level)

async def async_turn_off(self, **kwargs):
"""Turn the light off."""
simple_rgb_color = self._channel.simpleRGBColorState
simple_rgb_color = self._func_channel.simpleRGBColorState
await self._device.set_rgb_dim_level(
self._channel_index,
self.channel,
simple_rgb_color, 0.0)


def _convert_color(color):
def _convert_color(color) -> RGBColorState:
"""
Convert the given color to the reduced RGBColorState color.

RGBColorStat contains only 8 colors including white and black,
so a conversion is required.
"""
from homematicip.base.enums import RGBColorState

if color is None:
return RGBColorState.WHITE

Expand Down
Loading