- added initial version of the erd light entity

This commit is contained in:
Jack Simbach 2021-10-08 22:48:17 -04:00
parent 2f5ae91150
commit 0aa02e3f71
6 changed files with 108 additions and 3 deletions

View File

@ -24,6 +24,7 @@ from ..entities import (
GeErdBinarySensor, GeErdBinarySensor,
GeErdSwitch, GeErdSwitch,
GeErdSelect, GeErdSelect,
GeErdLight,
GeFridge, GeFridge,
GeFreezer, GeFreezer,
GeDispenser, GeDispenser,
@ -83,7 +84,7 @@ class FridgeApi(ApplianceApi):
if(ice_bucket_status and ice_bucket_status.is_present_fridge): if(ice_bucket_status and ice_bucket_status.is_present_fridge):
fridge_entities.append(GeErdPropertySensor(self, ErdCode.ICE_MAKER_BUCKET_STATUS, "state_full_fridge")) fridge_entities.append(GeErdPropertySensor(self, ErdCode.ICE_MAKER_BUCKET_STATUS, "state_full_fridge"))
if(interior_light and interior_light != 255): 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): 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")) 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): if(convertable_drawer and convertable_drawer != ErdConvertableDrawerMode.NA):

View File

@ -5,6 +5,7 @@ from .ge_erd_entity import GeErdEntity
from .ge_erd_binary_sensor import GeErdBinarySensor from .ge_erd_binary_sensor import GeErdBinarySensor
from .ge_erd_property_binary_sensor import GeErdPropertyBinarySensor from .ge_erd_property_binary_sensor import GeErdPropertyBinarySensor
from .ge_erd_sensor import GeErdSensor from .ge_erd_sensor import GeErdSensor
from .ge_erd_light import GeErdLight
from .ge_erd_timer_sensor import GeErdTimerSensor from .ge_erd_timer_sensor import GeErdTimerSensor
from .ge_erd_property_sensor import GeErdPropertySensor from .ge_erd_property_sensor import GeErdPropertySensor
from .ge_erd_switch import GeErdSwitch from .ge_erd_switch import GeErdSwitch

View File

@ -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)

View File

@ -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)

View File

@ -3,7 +3,7 @@
"name": "GE Home (SmartHQ)", "name": "GE Home (SmartHQ)",
"config_flow": true, "config_flow": true,
"documentation": "https://github.com/simbaja/ha_gehome", "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"], "codeowners": ["@simbaja"],
"version": "0.5.0" "version": "0.5.0"
} }

View File

@ -34,7 +34,7 @@ from .const import (
) )
from .devices import ApplianceApi, get_appliance_api_type 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__) _LOGGER = logging.getLogger(__name__)