* Add HomematicIP Cloud to config flow * Inititial trial for config_flow * Integrations text files * Load and write config_flow and init homematicip_cloud * Split into dedicated files * Ceanup of text messages * Working config_flow * Move imports inside a function * Enable laoding even no accesspoints are defined * Revert unnecassary changes in CONFIG_SCHEMA * Better error handling * fix flask8 * Migration to async for token generation * A few fixes * Simplify config_flow * Bump version to 9.6 with renamed package * Requirements file * First fixes after review * Implement async_step_import * Cleanup for Config Flow * First tests for homematicip_cloud setup * Remove config_flow tests * Really remove all things * Fix comment * Update picture * Add support for async_setup_entry to switch and climate platform * Update path of the config_flow picture * Refactoring for better tesability * Further tests implemented * Move 3th party lib inside function * Fix lint * Update requirments_test_all.txt file * UPdate of requirments_test_all.txt did not work * Furder cleanup in websocket connection * Remove a test for the hap * Revert "Remove a test for the hap" This reverts commit 968d58cba108e0f371022c7ab540374aa2ab13f4. * First tests implemented for config_flow * Fix lint * Rework of client registration process * Implemented tests for config_flow 100% coverage * Cleanup * Cleanup comments and code * Try to fix import problem * Add homematicip to the test env requirements
72 lines
2.1 KiB
Python
72 lines
2.1 KiB
Python
"""GenericDevice for the HomematicIP Cloud component."""
|
|
import logging
|
|
|
|
from homeassistant.helpers.entity import Entity
|
|
|
|
_LOGGER = logging.getLogger(__name__)
|
|
|
|
ATTR_HOME_ID = 'home_id'
|
|
ATTR_HOME_NAME = 'home_name'
|
|
ATTR_DEVICE_ID = 'device_id'
|
|
ATTR_DEVICE_LABEL = 'device_label'
|
|
ATTR_STATUS_UPDATE = 'status_update'
|
|
ATTR_FIRMWARE_STATE = 'firmware_state'
|
|
ATTR_UNREACHABLE = 'unreachable'
|
|
ATTR_LOW_BATTERY = 'low_battery'
|
|
ATTR_MODEL_TYPE = 'model_type'
|
|
ATTR_GROUP_TYPE = 'group_type'
|
|
ATTR_DEVICE_RSSI = 'device_rssi'
|
|
ATTR_DUTY_CYCLE = 'duty_cycle'
|
|
ATTR_CONNECTED = 'connected'
|
|
ATTR_SABOTAGE = 'sabotage'
|
|
ATTR_OPERATION_LOCK = 'operation_lock'
|
|
|
|
|
|
class HomematicipGenericDevice(Entity):
|
|
"""Representation of an HomematicIP generic device."""
|
|
|
|
def __init__(self, home, device, post=None):
|
|
"""Initialize the generic device."""
|
|
self._home = home
|
|
self._device = device
|
|
self.post = post
|
|
_LOGGER.info('Setting up %s (%s)', self.name,
|
|
self._device.modelType)
|
|
|
|
async def async_added_to_hass(self):
|
|
"""Register callbacks."""
|
|
self._device.on_update(self._device_changed)
|
|
|
|
def _device_changed(self, json, **kwargs):
|
|
"""Handle device state changes."""
|
|
_LOGGER.debug('Event %s (%s)', self.name, self._device.modelType)
|
|
self.async_schedule_update_ha_state()
|
|
|
|
@property
|
|
def name(self):
|
|
"""Return the name of the generic device."""
|
|
name = self._device.label
|
|
if (self._home.name is not None and self._home.name != ''):
|
|
name = "{} {}".format(self._home.name, name)
|
|
if (self.post is not None and self.post != ''):
|
|
name = "{} {}".format(name, self.post)
|
|
return name
|
|
|
|
@property
|
|
def should_poll(self):
|
|
"""No polling needed."""
|
|
return False
|
|
|
|
@property
|
|
def available(self):
|
|
"""Device available."""
|
|
return not self._device.unreach
|
|
|
|
@property
|
|
def device_state_attributes(self):
|
|
"""Return the state attributes of the generic device."""
|
|
return {
|
|
ATTR_LOW_BATTERY: self._device.lowBat,
|
|
ATTR_MODEL_TYPE: self._device.modelType
|
|
}
|