Re-implement HomematicIP cloud to async (#13468)
* Recode to async version of homematicip-rest-api * Remove blank line * Cleanup of access point status class * Fix to loong line * Fix import errors * Bugfix missing wait the _retry_task for sleep command * Update comment * Updates after review * Small updates of logging and property name * Fix DOMAIN and revert back to lowercase snakecase strings * Fix intention and tripple double quotes * Fix travis build * Remove unnecessary state attributes * Fix optional name in configuration * Further reduction of state attributes
This commit is contained in:
parent
241a0793bb
commit
8c2dedab52
3 changed files with 159 additions and 206 deletions
|
@ -7,13 +7,10 @@ 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 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)
|
||||
from homeassistant.const import TEMP_CELSIUS, STATE_OK
|
||||
HomematicipGenericDevice, DOMAIN as HOMEMATICIP_CLOUD_DOMAIN,
|
||||
ATTR_HOME_ID)
|
||||
from homeassistant.const import TEMP_CELSIUS
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
@ -21,68 +18,49 @@ DEPENDENCIES = ['homematicip_cloud']
|
|||
|
||||
ATTR_VALVE_STATE = 'valve_state'
|
||||
ATTR_VALVE_POSITION = 'valve_position'
|
||||
ATTR_TEMPERATURE = 'temperature'
|
||||
ATTR_TEMPERATURE_OFFSET = 'temperature_offset'
|
||||
ATTR_HUMIDITY = 'humidity'
|
||||
|
||||
HMIP_UPTODATE = 'up_to_date'
|
||||
HMIP_VALVE_DONE = 'adaption_done'
|
||||
HMIP_SABOTAGE = 'sabotage'
|
||||
|
||||
STATE_OK = 'ok'
|
||||
STATE_LOW_BATTERY = 'low_battery'
|
||||
STATE_SABOTAGE = 'sabotage'
|
||||
|
||||
|
||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||
async def async_setup_platform(hass, config, async_add_devices,
|
||||
discovery_info=None):
|
||||
"""Set up the HomematicIP sensors devices."""
|
||||
# pylint: disable=import-error, no-name-in-module
|
||||
from homematicip.device import (
|
||||
HeatingThermostat, TemperatureHumiditySensorWithoutDisplay,
|
||||
TemperatureHumiditySensorDisplay)
|
||||
|
||||
homeid = discovery_info['homeid']
|
||||
home = hass.data[DOMAIN][homeid]
|
||||
devices = [HomematicipAccesspoint(home)]
|
||||
if discovery_info is None:
|
||||
return
|
||||
home = hass.data[HOMEMATICIP_CLOUD_DOMAIN][discovery_info[ATTR_HOME_ID]]
|
||||
devices = [HomematicipAccesspointStatus(home)]
|
||||
|
||||
for device in home.devices:
|
||||
devices.append(HomematicipDeviceStatus(home, device))
|
||||
if isinstance(device, HeatingThermostat):
|
||||
devices.append(HomematicipHeatingThermostat(home, device))
|
||||
if isinstance(device, TemperatureHumiditySensorWithoutDisplay):
|
||||
devices.append(HomematicipSensorThermometer(home, device))
|
||||
devices.append(HomematicipSensorHumidity(home, device))
|
||||
if isinstance(device, TemperatureHumiditySensorDisplay):
|
||||
devices.append(HomematicipSensorThermometer(home, device))
|
||||
devices.append(HomematicipSensorHumidity(home, device))
|
||||
if isinstance(device, (TemperatureHumiditySensorDisplay,
|
||||
TemperatureHumiditySensorWithoutDisplay)):
|
||||
devices.append(HomematicipTemperatureSensor(home, device))
|
||||
devices.append(HomematicipHumiditySensor(home, device))
|
||||
|
||||
if home.devices:
|
||||
add_devices(devices)
|
||||
if devices:
|
||||
async_add_devices(devices)
|
||||
|
||||
|
||||
class HomematicipAccesspoint(Entity):
|
||||
class HomematicipAccesspointStatus(HomematicipGenericDevice):
|
||||
"""Representation of an HomeMaticIP access point."""
|
||||
|
||||
def __init__(self, home):
|
||||
"""Initialize the access point sensor."""
|
||||
self._home = home
|
||||
_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 home %s', self._home.label)
|
||||
self.async_schedule_update_ha_state()
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
"""Return the name of the access point device."""
|
||||
if self._home.label == '':
|
||||
return 'Access Point Status'
|
||||
return '{} Access Point Status'.format(self._home.label)
|
||||
"""Initialize access point device."""
|
||||
super().__init__(home, home)
|
||||
|
||||
@property
|
||||
def icon(self):
|
||||
|
@ -102,24 +80,15 @@ class HomematicipAccesspoint(Entity):
|
|||
@property
|
||||
def device_state_attributes(self):
|
||||
"""Return the state attributes of the access point."""
|
||||
return {
|
||||
ATTR_HOME_LABEL: self._home.label,
|
||||
ATTR_HOME_ID: self._home.id,
|
||||
}
|
||||
return {}
|
||||
|
||||
|
||||
class HomematicipDeviceStatus(HomematicipGenericDevice):
|
||||
"""Representation of an HomematicIP device status."""
|
||||
|
||||
def __init__(self, home, device):
|
||||
"""Initialize the device."""
|
||||
super().__init__(home, device)
|
||||
_LOGGER.debug('Setting up sensor device status: %s', device.label)
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
"""Return the name of the device."""
|
||||
return self._name('Status')
|
||||
"""Initialize generic status device."""
|
||||
super().__init__(home, device, 'Status')
|
||||
|
||||
@property
|
||||
def icon(self):
|
||||
|
@ -150,9 +119,8 @@ class HomematicipHeatingThermostat(HomematicipGenericDevice):
|
|||
"""MomematicIP heating thermostat representation."""
|
||||
|
||||
def __init__(self, home, device):
|
||||
""""Initialize heating thermostat."""
|
||||
super().__init__(home, device)
|
||||
_LOGGER.debug('Setting up heating thermostat device: %s', device.label)
|
||||
"""Initialize heating thermostat device."""
|
||||
super().__init__(home, device, 'Heating')
|
||||
|
||||
@property
|
||||
def icon(self):
|
||||
|
@ -173,34 +141,18 @@ class HomematicipHeatingThermostat(HomematicipGenericDevice):
|
|||
"""Return the unit this state is expressed in."""
|
||||
return '%'
|
||||
|
||||
@property
|
||||
def device_state_attributes(self):
|
||||
"""Return the state attributes."""
|
||||
return {
|
||||
ATTR_VALVE_STATE: self._device.valveState.lower(),
|
||||
ATTR_TEMPERATURE_OFFSET: self._device.temperatureOffset,
|
||||
ATTR_LOW_BATTERY: self._device.lowBat,
|
||||
ATTR_RSSI: self._device.rssiDeviceValue
|
||||
}
|
||||
|
||||
|
||||
class HomematicipSensorHumidity(HomematicipGenericDevice):
|
||||
"""MomematicIP thermometer device."""
|
||||
class HomematicipHumiditySensor(HomematicipGenericDevice):
|
||||
"""MomematicIP humidity device."""
|
||||
|
||||
def __init__(self, home, device):
|
||||
""""Initialize the thermometer device."""
|
||||
super().__init__(home, device)
|
||||
_LOGGER.debug('Setting up humidity device: %s', device.label)
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
"""Return the name of the device."""
|
||||
return self._name('Humidity')
|
||||
"""Initialize the thermometer device."""
|
||||
super().__init__(home, device, 'Humidity')
|
||||
|
||||
@property
|
||||
def icon(self):
|
||||
"""Return the icon."""
|
||||
return 'mdi:water'
|
||||
return 'mdi:water-percent'
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
|
@ -212,27 +164,13 @@ class HomematicipSensorHumidity(HomematicipGenericDevice):
|
|||
"""Return the unit this state is expressed in."""
|
||||
return '%'
|
||||
|
||||
@property
|
||||
def device_state_attributes(self):
|
||||
"""Return the state attributes."""
|
||||
return {
|
||||
ATTR_LOW_BATTERY: self._device.lowBat,
|
||||
ATTR_RSSI: self._device.rssiDeviceValue,
|
||||
}
|
||||
|
||||
|
||||
class HomematicipSensorThermometer(HomematicipGenericDevice):
|
||||
"""MomematicIP thermometer device."""
|
||||
class HomematicipTemperatureSensor(HomematicipGenericDevice):
|
||||
"""MomematicIP the thermometer device."""
|
||||
|
||||
def __init__(self, home, device):
|
||||
""""Initialize the thermometer device."""
|
||||
super().__init__(home, device)
|
||||
_LOGGER.debug('Setting up thermometer device: %s', device.label)
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
"""Return the name of the device."""
|
||||
return self._name('Temperature')
|
||||
"""Initialize the thermometer device."""
|
||||
super().__init__(home, device, 'Temperature')
|
||||
|
||||
@property
|
||||
def icon(self):
|
||||
|
@ -248,12 +186,3 @@ class HomematicipSensorThermometer(HomematicipGenericDevice):
|
|||
def unit_of_measurement(self):
|
||||
"""Return the unit this state is expressed in."""
|
||||
return TEMP_CELSIUS
|
||||
|
||||
@property
|
||||
def device_state_attributes(self):
|
||||
"""Return the state attributes."""
|
||||
return {
|
||||
ATTR_TEMPERATURE_OFFSET: self._device.temperatureOffset,
|
||||
ATTR_LOW_BATTERY: self._device.lowBat,
|
||||
ATTR_RSSI: self._device.rssiDeviceValue,
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue