mirror of
https://github.com/home-assistant/core.git
synced 2025-06-04 05:07:08 +00:00

* 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
80 lines
2.2 KiB
Python
80 lines
2.2 KiB
Python
"""
|
|
Support for HomematicIP light.
|
|
|
|
For more details about this component, please refer to the documentation at
|
|
https://home-assistant.io/components/light.homematicip_cloud/
|
|
"""
|
|
|
|
import logging
|
|
|
|
from homeassistant.components.light import Light
|
|
from homeassistant.components.homematicip_cloud import (
|
|
HomematicipGenericDevice, DOMAIN as HMIPC_DOMAIN,
|
|
HMIPC_HAPID)
|
|
|
|
DEPENDENCIES = ['homematicip_cloud']
|
|
|
|
_LOGGER = logging.getLogger(__name__)
|
|
|
|
ATTR_POWER_CONSUMPTION = 'power_consumption'
|
|
ATTR_ENERGIE_COUNTER = 'energie_counter'
|
|
ATTR_PROFILE_MODE = 'profile_mode'
|
|
|
|
|
|
async def async_setup_platform(hass, config, async_add_devices,
|
|
discovery_info=None):
|
|
"""Old way of setting up HomematicIP lights."""
|
|
pass
|
|
|
|
|
|
async def async_setup_entry(hass, config_entry, async_add_devices):
|
|
"""Set up the HomematicIP lights from a config entry."""
|
|
from homematicip.device import (
|
|
BrandSwitchMeasuring)
|
|
|
|
home = hass.data[HMIPC_DOMAIN][config_entry.data[HMIPC_HAPID]].home
|
|
devices = []
|
|
for device in home.devices:
|
|
if isinstance(device, BrandSwitchMeasuring):
|
|
devices.append(HomematicipLightMeasuring(home, device))
|
|
|
|
if devices:
|
|
async_add_devices(devices)
|
|
|
|
|
|
class HomematicipLight(HomematicipGenericDevice, Light):
|
|
"""MomematicIP light device."""
|
|
|
|
def __init__(self, home, device):
|
|
"""Initialize the light device."""
|
|
super().__init__(home, device)
|
|
|
|
@property
|
|
def is_on(self):
|
|
"""Return true if device is on."""
|
|
return self._device.on
|
|
|
|
async def async_turn_on(self, **kwargs):
|
|
"""Turn the device on."""
|
|
await self._device.turn_on()
|
|
|
|
async def async_turn_off(self, **kwargs):
|
|
"""Turn the device off."""
|
|
await self._device.turn_off()
|
|
|
|
|
|
class HomematicipLightMeasuring(HomematicipLight):
|
|
"""MomematicIP measuring light device."""
|
|
|
|
@property
|
|
def current_power_w(self):
|
|
"""Return the current power usage in W."""
|
|
return self._device.currentPowerConsumption
|
|
|
|
@property
|
|
def today_energy_kwh(self):
|
|
"""Return the today total energy usage in kWh."""
|
|
if self._device.energyCounter is None:
|
|
return 0
|
|
return round(self._device.energyCounter)
|