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

Cleanup homematicip_cloud #13356

Merged
merged 6 commits into from Mar 23, 2018
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 11 additions & 5 deletions homeassistant/components/homematicip_cloud.py
Expand Up @@ -2,13 +2,14 @@
Support for HomematicIP components.

For more details about this component, please refer to the documentation at
https://home-assistant.io/components/homematicip/
https://home-assistant.io/components/homematicip_cloud/
"""

import logging
from socket import timeout

import voluptuous as vol

from homeassistant.core import callback
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.dispatcher import (dispatcher_send,
Expand Down Expand Up @@ -49,12 +50,14 @@
ATTR_LOW_BATTERY = 'low_battery'
ATTR_SABOTAGE = 'sabotage'
ATTR_RSSI = 'rssi'
ATTR_TYPE = 'type'


def setup(hass, config):
"""Set up the HomematicIP component."""
# pylint: disable=import-error, no-name-in-module
from homematicip.home import Home

hass.data.setdefault(DOMAIN, {})
homes = hass.data[DOMAIN]
accesspoints = config.get(DOMAIN, [])
Expand Down Expand Up @@ -100,19 +103,21 @@ def _update_event(events):
_LOGGER.info('HUB name: %s, id: %s', home.label, home.id)

for component in ['sensor']:
load_platform(hass, component, DOMAIN,
{'homeid': home.id}, config)
load_platform(hass, component, DOMAIN, {'homeid': home.id}, config)

return True


class HomematicipGenericDevice(Entity):
"""Representation of an HomematicIP generic device."""

def __init__(self, hass, home, device, signal=None):
def __init__(self, home, device):
"""Initialize the generic device."""
self.hass = hass
self._home = home
self._device = device

async def async_added_to_hass(self):
"""Register callbacks."""
async_dispatcher_connect(
self.hass, EVENT_DEVICE_CHANGED, self._device_changed)

Expand Down Expand Up @@ -162,6 +167,7 @@ def _generic_state_attributes(self):
ATTR_FIRMWARE_STATE: self._device.updateState.lower(),
ATTR_LOW_BATTERY: self._device.lowBat,
ATTR_RSSI: self._device.rssiDeviceValue,
ATTR_TYPE: self._device.modelType
}

@property
Expand Down
57 changes: 29 additions & 28 deletions homeassistant/components/sensor/homematicip_cloud.py
Expand Up @@ -2,14 +2,14 @@
Support for HomematicIP sensors.

For more details about this component, please refer to the documentation at
https://home-assistant.io/components/homematicip/
https://home-assistant.io/components/sensor.homematicip_cloud/
"""

import logging

from homeassistant.core import callback
from homeassistant.helpers.entity import Entity
from homeassistant.helpers.dispatcher import dispatcher_connect
from homeassistant.helpers.dispatcher import async_dispatcher_connect
from homeassistant.components.homematicip_cloud import (
HomematicipGenericDevice, DOMAIN, EVENT_HOME_CHANGED,
ATTR_HOME_LABEL, ATTR_HOME_ID, ATTR_LOW_BATTERY, ATTR_RSSI)
Expand Down Expand Up @@ -38,41 +38,43 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
HeatingThermostat, TemperatureHumiditySensorWithoutDisplay,
TemperatureHumiditySensorDisplay)

_LOGGER.info('Setting up HomeMaticIP accespoint & generic devices')
homeid = discovery_info['homeid']
home = hass.data[DOMAIN][homeid]
devices = [HomematicipAccesspoint(hass, home)]
if home.devices is None:
return
devices = [HomematicipAccesspoint(home)]

for device in home.devices:
devices.append(HomematicipDeviceStatus(hass, home, device))
devices.append(HomematicipDeviceStatus(home, device))
if isinstance(device, HeatingThermostat):
devices.append(HomematicipHeatingThermostat(hass, home, device))
devices.append(HomematicipHeatingThermostat(home, device))
if isinstance(device, TemperatureHumiditySensorWithoutDisplay):
devices.append(HomematicipSensorThermometer(hass, home, device))
devices.append(HomematicipSensorHumidity(hass, home, device))
devices.append(HomematicipSensorThermometer(home, device))
devices.append(HomematicipSensorHumidity(home, device))
if isinstance(device, TemperatureHumiditySensorDisplay):
devices.append(HomematicipSensorThermometer(hass, home, device))
devices.append(HomematicipSensorHumidity(hass, home, device))
add_devices(devices)
devices.append(HomematicipSensorThermometer(home, device))
devices.append(HomematicipSensorHumidity(home, device))

if home.devices:
add_devices(devices)


class HomematicipAccesspoint(Entity):
"""Representation of an HomeMaticIP access point."""

def __init__(self, hass, home):
def __init__(self, home):
"""Initialize the access point sensor."""
self.hass = hass
self._home = home
dispatcher_connect(
self.hass, EVENT_HOME_CHANGED, self._home_changed)
_LOGGER.debug('Setting up access point %s', home.label)

async def async_added_to_hass(self):
"""Register callbacks."""
async_dispatcher_connect(
self.hass, EVENT_HOME_CHANGED, self._home_changed)

@callback
def _home_changed(self, deviceid):
"""Handle device state changes."""
if deviceid is None or deviceid == self._home.id:
_LOGGER.debug('Event access point %s', self._home.label)
_LOGGER.debug('Event home %s', self._home.label)
self.async_schedule_update_ha_state()

@property
Expand Down Expand Up @@ -109,9 +111,9 @@ def device_state_attributes(self):
class HomematicipDeviceStatus(HomematicipGenericDevice):
"""Representation of an HomematicIP device status."""

def __init__(self, hass, home, device, signal=None):
def __init__(self, home, device):
"""Initialize the device."""
super().__init__(hass, home, device)
super().__init__(home, device)
_LOGGER.debug('Setting up sensor device status: %s', device.label)

@property
Expand Down Expand Up @@ -147,9 +149,9 @@ def state(self):
class HomematicipHeatingThermostat(HomematicipGenericDevice):
"""MomematicIP heating thermostat representation."""

def __init__(self, hass, home, device):
def __init__(self, home, device):
""""Initialize heating thermostat."""
super().__init__(hass, home, device)
super().__init__(home, device)
_LOGGER.debug('Setting up heating thermostat device: %s', device.label)

@property
Expand Down Expand Up @@ -185,11 +187,10 @@ def device_state_attributes(self):
class HomematicipSensorHumidity(HomematicipGenericDevice):
"""MomematicIP thermometer device."""

def __init__(self, hass, home, device):
def __init__(self, home, device):
""""Initialize the thermometer device."""
super().__init__(hass, home, device)
_LOGGER.debug('Setting up humidity device: %s',
device.label)
super().__init__(home, device)
_LOGGER.debug('Setting up humidity device: %s', device.label)

@property
def name(self):
Expand Down Expand Up @@ -223,9 +224,9 @@ def device_state_attributes(self):
class HomematicipSensorThermometer(HomematicipGenericDevice):
"""MomematicIP thermometer device."""

def __init__(self, hass, home, device):
def __init__(self, home, device):
""""Initialize the thermometer device."""
super().__init__(hass, home, device)
super().__init__(home, device)
_LOGGER.debug('Setting up thermometer device: %s', device.label)

@property
Expand Down