mirror of
https://github.com/home-assistant/core.git
synced 2025-07-15 17:27:10 +00:00
Cleanup homematicip_cloud (#13356)
* Cleanup and proposed changes from MartinHjelmare * Removed coroutine decorator from async_added_to_hass * Added blank line * Fix of component url * Fix of component url * Fix url of the sensor component
This commit is contained in:
parent
2497dd5e33
commit
df8596e896
@ -2,13 +2,14 @@
|
|||||||
Support for HomematicIP components.
|
Support for HomematicIP components.
|
||||||
|
|
||||||
For more details about this component, please refer to the documentation at
|
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
|
import logging
|
||||||
from socket import timeout
|
from socket import timeout
|
||||||
|
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.core import callback
|
from homeassistant.core import callback
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
from homeassistant.helpers.dispatcher import (dispatcher_send,
|
from homeassistant.helpers.dispatcher import (dispatcher_send,
|
||||||
@ -49,12 +50,14 @@ ATTR_FIRMWARE_STATE = 'firmware_state'
|
|||||||
ATTR_LOW_BATTERY = 'low_battery'
|
ATTR_LOW_BATTERY = 'low_battery'
|
||||||
ATTR_SABOTAGE = 'sabotage'
|
ATTR_SABOTAGE = 'sabotage'
|
||||||
ATTR_RSSI = 'rssi'
|
ATTR_RSSI = 'rssi'
|
||||||
|
ATTR_TYPE = 'type'
|
||||||
|
|
||||||
|
|
||||||
def setup(hass, config):
|
def setup(hass, config):
|
||||||
"""Set up the HomematicIP component."""
|
"""Set up the HomematicIP component."""
|
||||||
# pylint: disable=import-error, no-name-in-module
|
# pylint: disable=import-error, no-name-in-module
|
||||||
from homematicip.home import Home
|
from homematicip.home import Home
|
||||||
|
|
||||||
hass.data.setdefault(DOMAIN, {})
|
hass.data.setdefault(DOMAIN, {})
|
||||||
homes = hass.data[DOMAIN]
|
homes = hass.data[DOMAIN]
|
||||||
accesspoints = config.get(DOMAIN, [])
|
accesspoints = config.get(DOMAIN, [])
|
||||||
@ -100,19 +103,21 @@ def setup(hass, config):
|
|||||||
_LOGGER.info('HUB name: %s, id: %s', home.label, home.id)
|
_LOGGER.info('HUB name: %s, id: %s', home.label, home.id)
|
||||||
|
|
||||||
for component in ['sensor']:
|
for component in ['sensor']:
|
||||||
load_platform(hass, component, DOMAIN,
|
load_platform(hass, component, DOMAIN, {'homeid': home.id}, config)
|
||||||
{'homeid': home.id}, config)
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
class HomematicipGenericDevice(Entity):
|
class HomematicipGenericDevice(Entity):
|
||||||
"""Representation of an HomematicIP generic device."""
|
"""Representation of an HomematicIP generic device."""
|
||||||
|
|
||||||
def __init__(self, hass, home, device, signal=None):
|
def __init__(self, home, device):
|
||||||
"""Initialize the generic device."""
|
"""Initialize the generic device."""
|
||||||
self.hass = hass
|
|
||||||
self._home = home
|
self._home = home
|
||||||
self._device = device
|
self._device = device
|
||||||
|
|
||||||
|
async def async_added_to_hass(self):
|
||||||
|
"""Register callbacks."""
|
||||||
async_dispatcher_connect(
|
async_dispatcher_connect(
|
||||||
self.hass, EVENT_DEVICE_CHANGED, self._device_changed)
|
self.hass, EVENT_DEVICE_CHANGED, self._device_changed)
|
||||||
|
|
||||||
@ -162,6 +167,7 @@ class HomematicipGenericDevice(Entity):
|
|||||||
ATTR_FIRMWARE_STATE: self._device.updateState.lower(),
|
ATTR_FIRMWARE_STATE: self._device.updateState.lower(),
|
||||||
ATTR_LOW_BATTERY: self._device.lowBat,
|
ATTR_LOW_BATTERY: self._device.lowBat,
|
||||||
ATTR_RSSI: self._device.rssiDeviceValue,
|
ATTR_RSSI: self._device.rssiDeviceValue,
|
||||||
|
ATTR_TYPE: self._device.modelType
|
||||||
}
|
}
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
@ -2,14 +2,14 @@
|
|||||||
Support for HomematicIP sensors.
|
Support for HomematicIP sensors.
|
||||||
|
|
||||||
For more details about this component, please refer to the documentation at
|
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
|
import logging
|
||||||
|
|
||||||
from homeassistant.core import callback
|
from homeassistant.core import callback
|
||||||
from homeassistant.helpers.entity import Entity
|
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 (
|
from homeassistant.components.homematicip_cloud import (
|
||||||
HomematicipGenericDevice, DOMAIN, EVENT_HOME_CHANGED,
|
HomematicipGenericDevice, DOMAIN, EVENT_HOME_CHANGED,
|
||||||
ATTR_HOME_LABEL, ATTR_HOME_ID, ATTR_LOW_BATTERY, ATTR_RSSI)
|
ATTR_HOME_LABEL, ATTR_HOME_ID, ATTR_LOW_BATTERY, ATTR_RSSI)
|
||||||
@ -38,41 +38,43 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
|||||||
HeatingThermostat, TemperatureHumiditySensorWithoutDisplay,
|
HeatingThermostat, TemperatureHumiditySensorWithoutDisplay,
|
||||||
TemperatureHumiditySensorDisplay)
|
TemperatureHumiditySensorDisplay)
|
||||||
|
|
||||||
_LOGGER.info('Setting up HomeMaticIP accespoint & generic devices')
|
|
||||||
homeid = discovery_info['homeid']
|
homeid = discovery_info['homeid']
|
||||||
home = hass.data[DOMAIN][homeid]
|
home = hass.data[DOMAIN][homeid]
|
||||||
devices = [HomematicipAccesspoint(hass, home)]
|
devices = [HomematicipAccesspoint(home)]
|
||||||
if home.devices is None:
|
|
||||||
return
|
|
||||||
for device in home.devices:
|
for device in home.devices:
|
||||||
devices.append(HomematicipDeviceStatus(hass, home, device))
|
devices.append(HomematicipDeviceStatus(home, device))
|
||||||
if isinstance(device, HeatingThermostat):
|
if isinstance(device, HeatingThermostat):
|
||||||
devices.append(HomematicipHeatingThermostat(hass, home, device))
|
devices.append(HomematicipHeatingThermostat(home, device))
|
||||||
if isinstance(device, TemperatureHumiditySensorWithoutDisplay):
|
if isinstance(device, TemperatureHumiditySensorWithoutDisplay):
|
||||||
devices.append(HomematicipSensorThermometer(hass, home, device))
|
devices.append(HomematicipSensorThermometer(home, device))
|
||||||
devices.append(HomematicipSensorHumidity(hass, home, device))
|
devices.append(HomematicipSensorHumidity(home, device))
|
||||||
if isinstance(device, TemperatureHumiditySensorDisplay):
|
if isinstance(device, TemperatureHumiditySensorDisplay):
|
||||||
devices.append(HomematicipSensorThermometer(hass, home, device))
|
devices.append(HomematicipSensorThermometer(home, device))
|
||||||
devices.append(HomematicipSensorHumidity(hass, home, device))
|
devices.append(HomematicipSensorHumidity(home, device))
|
||||||
|
|
||||||
|
if home.devices:
|
||||||
add_devices(devices)
|
add_devices(devices)
|
||||||
|
|
||||||
|
|
||||||
class HomematicipAccesspoint(Entity):
|
class HomematicipAccesspoint(Entity):
|
||||||
"""Representation of an HomeMaticIP access point."""
|
"""Representation of an HomeMaticIP access point."""
|
||||||
|
|
||||||
def __init__(self, hass, home):
|
def __init__(self, home):
|
||||||
"""Initialize the access point sensor."""
|
"""Initialize the access point sensor."""
|
||||||
self.hass = hass
|
|
||||||
self._home = home
|
self._home = home
|
||||||
dispatcher_connect(
|
|
||||||
self.hass, EVENT_HOME_CHANGED, self._home_changed)
|
|
||||||
_LOGGER.debug('Setting up access point %s', home.label)
|
_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
|
@callback
|
||||||
def _home_changed(self, deviceid):
|
def _home_changed(self, deviceid):
|
||||||
"""Handle device state changes."""
|
"""Handle device state changes."""
|
||||||
if deviceid is None or deviceid == self._home.id:
|
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()
|
self.async_schedule_update_ha_state()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@ -109,9 +111,9 @@ class HomematicipAccesspoint(Entity):
|
|||||||
class HomematicipDeviceStatus(HomematicipGenericDevice):
|
class HomematicipDeviceStatus(HomematicipGenericDevice):
|
||||||
"""Representation of an HomematicIP device status."""
|
"""Representation of an HomematicIP device status."""
|
||||||
|
|
||||||
def __init__(self, hass, home, device, signal=None):
|
def __init__(self, home, device):
|
||||||
"""Initialize the device."""
|
"""Initialize the device."""
|
||||||
super().__init__(hass, home, device)
|
super().__init__(home, device)
|
||||||
_LOGGER.debug('Setting up sensor device status: %s', device.label)
|
_LOGGER.debug('Setting up sensor device status: %s', device.label)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@ -147,9 +149,9 @@ class HomematicipDeviceStatus(HomematicipGenericDevice):
|
|||||||
class HomematicipHeatingThermostat(HomematicipGenericDevice):
|
class HomematicipHeatingThermostat(HomematicipGenericDevice):
|
||||||
"""MomematicIP heating thermostat representation."""
|
"""MomematicIP heating thermostat representation."""
|
||||||
|
|
||||||
def __init__(self, hass, home, device):
|
def __init__(self, home, device):
|
||||||
""""Initialize heating thermostat."""
|
""""Initialize heating thermostat."""
|
||||||
super().__init__(hass, home, device)
|
super().__init__(home, device)
|
||||||
_LOGGER.debug('Setting up heating thermostat device: %s', device.label)
|
_LOGGER.debug('Setting up heating thermostat device: %s', device.label)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@ -185,11 +187,10 @@ class HomematicipHeatingThermostat(HomematicipGenericDevice):
|
|||||||
class HomematicipSensorHumidity(HomematicipGenericDevice):
|
class HomematicipSensorHumidity(HomematicipGenericDevice):
|
||||||
"""MomematicIP thermometer device."""
|
"""MomematicIP thermometer device."""
|
||||||
|
|
||||||
def __init__(self, hass, home, device):
|
def __init__(self, home, device):
|
||||||
""""Initialize the thermometer device."""
|
""""Initialize the thermometer device."""
|
||||||
super().__init__(hass, home, device)
|
super().__init__(home, device)
|
||||||
_LOGGER.debug('Setting up humidity device: %s',
|
_LOGGER.debug('Setting up humidity device: %s', device.label)
|
||||||
device.label)
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
@ -223,9 +224,9 @@ class HomematicipSensorHumidity(HomematicipGenericDevice):
|
|||||||
class HomematicipSensorThermometer(HomematicipGenericDevice):
|
class HomematicipSensorThermometer(HomematicipGenericDevice):
|
||||||
"""MomematicIP thermometer device."""
|
"""MomematicIP thermometer device."""
|
||||||
|
|
||||||
def __init__(self, hass, home, device):
|
def __init__(self, home, device):
|
||||||
""""Initialize the thermometer device."""
|
""""Initialize the thermometer device."""
|
||||||
super().__init__(hass, home, device)
|
super().__init__(home, device)
|
||||||
_LOGGER.debug('Setting up thermometer device: %s', device.label)
|
_LOGGER.debug('Setting up thermometer device: %s', device.label)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
Loading…
x
Reference in New Issue
Block a user