mirror of https://github.com/simbaja/ha_gehome.git
- added initial version of the erd light entity
This commit is contained in:
parent
2f5ae91150
commit
0aa02e3f71
|
@ -24,6 +24,7 @@ from ..entities import (
|
|||
GeErdBinarySensor,
|
||||
GeErdSwitch,
|
||||
GeErdSelect,
|
||||
GeErdLight,
|
||||
GeFridge,
|
||||
GeFreezer,
|
||||
GeDispenser,
|
||||
|
@ -83,7 +84,7 @@ class FridgeApi(ApplianceApi):
|
|||
if(ice_bucket_status and ice_bucket_status.is_present_fridge):
|
||||
fridge_entities.append(GeErdPropertySensor(self, ErdCode.ICE_MAKER_BUCKET_STATUS, "state_full_fridge"))
|
||||
if(interior_light and interior_light != 255):
|
||||
fridge_entities.append(GeErdSensor(self, ErdCode.INTERIOR_LIGHT))
|
||||
fridge_entities.append(GeErdLight(self, ErdCode.INTERIOR_LIGHT))
|
||||
if(proximity_light and proximity_light != ErdOnOff.NA):
|
||||
fridge_entities.append(GeErdSwitch(self, ErdCode.PROXIMITY_LIGHT, ErdOnOffBoolConverter(), icon_on_override="mdi:lightbulb-on", icon_off_override="mdi:lightbulb"))
|
||||
if(convertable_drawer and convertable_drawer != ErdConvertableDrawerMode.NA):
|
||||
|
|
|
@ -5,6 +5,7 @@ from .ge_erd_entity import GeErdEntity
|
|||
from .ge_erd_binary_sensor import GeErdBinarySensor
|
||||
from .ge_erd_property_binary_sensor import GeErdPropertyBinarySensor
|
||||
from .ge_erd_sensor import GeErdSensor
|
||||
from .ge_erd_light import GeErdLight
|
||||
from .ge_erd_timer_sensor import GeErdTimerSensor
|
||||
from .ge_erd_property_sensor import GeErdPropertySensor
|
||||
from .ge_erd_switch import GeErdSwitch
|
||||
|
|
|
@ -0,0 +1,65 @@
|
|||
import logging
|
||||
|
||||
from gehomesdk import ErdCodeType
|
||||
from homeassistant.components.light import (
|
||||
ATTR_BRIGHTNESS,
|
||||
COLOR_MODE_BRIGHTNESS,
|
||||
SUPPORT_BRIGHTNESS,
|
||||
LightEntity
|
||||
)
|
||||
|
||||
from ...devices import ApplianceApi
|
||||
from .ge_erd_entity import GeErdEntity
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def to_ge_level(level):
|
||||
"""Convert the given Home Assistant light level (0-255) to GE (0-100)."""
|
||||
return int(round((level * 100) / 255))
|
||||
|
||||
def to_hass_level(level):
|
||||
"""Convert the given GE (0-100) light level to Home Assistant (0-255)."""
|
||||
return int((level * 255) // 100)
|
||||
|
||||
class GeErdLight(GeErdEntity, LightEntity):
|
||||
"""Lights for ERD codes."""
|
||||
|
||||
def __init__(self, api: ApplianceApi, erd_code: ErdCodeType, erd_override: str = None, color_mode = COLOR_MODE_BRIGHTNESS):
|
||||
super().__init__(api, erd_code, erd_override)
|
||||
self._attr_color_mode = color_mode
|
||||
|
||||
@property
|
||||
def supported_features(self):
|
||||
"""Flag supported features."""
|
||||
return SUPPORT_BRIGHTNESS
|
||||
|
||||
@property
|
||||
def supported_color_modes(self):
|
||||
"""Flag supported color modes."""
|
||||
return COLOR_MODE_BRIGHTNESS
|
||||
|
||||
@property
|
||||
def brightness(self):
|
||||
"""Return the brightness of the light."""
|
||||
return to_hass_level(self.appliance.get_erd_value(self.erd_code))
|
||||
|
||||
async def _set_brightness(self, brightness, **kwargs):
|
||||
await self.appliance.async_set_erd_value(self.erd_code, to_ge_level(brightness))
|
||||
|
||||
@property
|
||||
def is_on(self) -> bool:
|
||||
"""Return True if light is on."""
|
||||
return self.appliance.get_erd_value(self.erd_code) > 0
|
||||
|
||||
async def async_turn_on(self, **kwargs):
|
||||
"""Turn the light on."""
|
||||
brightness = kwargs.pop(ATTR_BRIGHTNESS, 255)
|
||||
|
||||
_LOGGER.debug(f"Turning on {self.unique_id}")
|
||||
await self._set_brightness(brightness, kwargs)
|
||||
|
||||
async def async_turn_off(self, **kwargs):
|
||||
"""Turn the light off."""
|
||||
_LOGGER.debug(f"Turning off {self.unique_id}")
|
||||
await self._set_brightness(0, kwargs)
|
|
@ -0,0 +1,38 @@
|
|||
"""GE Home Select Entities"""
|
||||
import async_timeout
|
||||
import logging
|
||||
from typing import Callable
|
||||
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from .const import DOMAIN
|
||||
from .entities import GeErdLight
|
||||
from .update_coordinator import GeHomeUpdateCoordinator
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant, config_entry: ConfigEntry, async_add_entities: Callable
|
||||
):
|
||||
"""GE Home lights."""
|
||||
_LOGGER.debug("Adding GE Home lights")
|
||||
coordinator: GeHomeUpdateCoordinator = hass.data[DOMAIN][config_entry.entry_id]
|
||||
|
||||
# This should be a NOP, but let's be safe
|
||||
with async_timeout.timeout(20):
|
||||
await coordinator.initialization_future
|
||||
_LOGGER.debug("Coordinator init future finished")
|
||||
|
||||
apis = list(coordinator.appliance_apis.values())
|
||||
_LOGGER.debug(f"Found {len(apis):d} appliance APIs")
|
||||
entities = [
|
||||
entity
|
||||
for api in apis
|
||||
for entity in api.entities
|
||||
if isinstance(entity, GeErdLight)
|
||||
and entity.erd_code in api.appliance._property_cache
|
||||
]
|
||||
_LOGGER.debug(f"Found {len(entities):d} lights")
|
||||
async_add_entities(entities)
|
|
@ -3,7 +3,7 @@
|
|||
"name": "GE Home (SmartHQ)",
|
||||
"config_flow": true,
|
||||
"documentation": "https://github.com/simbaja/ha_gehome",
|
||||
"requirements": ["gehomesdk==0.4.9","magicattr==0.1.5"],
|
||||
"requirements": ["gehomesdk==0.4.11","magicattr==0.1.5"],
|
||||
"codeowners": ["@simbaja"],
|
||||
"version": "0.5.0"
|
||||
}
|
||||
|
|
|
@ -34,7 +34,7 @@ from .const import (
|
|||
)
|
||||
from .devices import ApplianceApi, get_appliance_api_type
|
||||
|
||||
PLATFORMS = ["binary_sensor", "sensor", "switch", "water_heater", "select", "climate"]
|
||||
PLATFORMS = ["binary_sensor", "sensor", "switch", "water_heater", "select", "climate", "light"]
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue