def update(self) -> None: """Update properties from the bulb.""" import yeelight try: self._bulb.get_properties() if self._bulb_device.bulb_type == yeelight.BulbType.Color: self._supported_features = SUPPORT_YEELIGHT_RGB elif self._bulb_device.bulb_type == yeelight.BulbType.WhiteTemp: self._supported_features = SUPPORT_YEELIGHT_WHITE_TEMP if self._min_mireds is None: model_specs = self._bulb.get_model_specs() self._min_mireds = \ kelvin_to_mired(model_specs['color_temp']['max']) self._max_mireds = \ kelvin_to_mired(model_specs['color_temp']['min']) self._is_on = self._properties.get('power') == 'on' bright = self._properties.get('bright', None) if bright: self._brightness = round(255 * (int(bright) / 100)) temp_in_k = self._properties.get('ct', None) if temp_in_k: self._color_temp = kelvin_to_mired(int(temp_in_k)) self._hs = self._get_hs_from_properties() self._available = True except yeelight.BulbException as ex: if self._available: # just inform once _LOGGER.error("Unable to update bulb status: %s", ex) self._available = False
def get_features(self): """Determine all supported features in one go.""" if self.smartbulb.is_dimmable: self._supported_features += SUPPORT_BRIGHTNESS if self.smartbulb.is_variable_color_temp: self._supported_features += SUPPORT_COLOR_TEMP self._min_mireds = kelvin_to_mired( self.smartbulb.valid_temperature_range[1]) self._max_mireds = kelvin_to_mired( self.smartbulb.valid_temperature_range[0]) if self.smartbulb.is_color: self._supported_features += SUPPORT_COLOR
def get_features(self): """Determine all supported features in one go.""" self._sysinfo = self.smartbulb.sys_info self._supported_features = 0 if self.smartbulb.is_dimmable: self._supported_features += SUPPORT_BRIGHTNESS if getattr(self.smartbulb, 'is_variable_color_temp', False): self._supported_features += SUPPORT_COLOR_TEMP self._min_mireds = kelvin_to_mired( self.smartbulb.valid_temperature_range[1]) self._max_mireds = kelvin_to_mired( self.smartbulb.valid_temperature_range[0]) if getattr(self.smartbulb, 'is_color', False): self._supported_features += SUPPORT_COLOR
def update(self) -> None: """Update properties from the bulb.""" import yeelight try: self._bulb.get_properties() if self._bulb_device.bulb_type == yeelight.BulbType.Color: self._supported_features = SUPPORT_YEELIGHT_RGB self._is_on = self._properties.get('power') == 'on' bright = self._properties.get('bright', None) if bright: self._brightness = 255 * (int(bright) / 100) temp_in_k = self._properties.get('ct', None) if temp_in_k: self._color_temp = kelvin_to_mired(int(temp_in_k)) self._rgb = self._get_rgb_from_properties() if self._rgb: xyb = color_RGB_to_xy(*self._rgb) self._xy = (xyb[0], xyb[1]) else: self._xy = None self._available = True except yeelight.BulbException as ex: if self._available: # just inform once _LOGGER.error("Unable to update bulb status: %s", ex) self._available = False
def update(self) -> None: """Update properties from the bulb.""" import yeelight bulb_type = self._bulb.bulb_type if bulb_type == yeelight.BulbType.Color: self._supported_features = SUPPORT_YEELIGHT_RGB elif self.light_type == yeelight.enums.LightType.Ambient: self._supported_features = SUPPORT_YEELIGHT_RGB elif bulb_type in (yeelight.BulbType.WhiteTemp, yeelight.BulbType.WhiteTempMood): if self._is_nightlight_enabled: self._supported_features = SUPPORT_YEELIGHT else: self._supported_features = SUPPORT_YEELIGHT_WHITE_TEMP if self.min_mireds is None: model_specs = self._bulb.get_model_specs() self._min_mireds = \ kelvin_to_mired(model_specs['color_temp']['max']) self._max_mireds = \ kelvin_to_mired(model_specs['color_temp']['min']) if bulb_type == yeelight.BulbType.WhiteTempMood: self._is_on = self._get_property('main_power') == 'on' else: self._is_on = self._get_property('power') == 'on' if self._is_nightlight_enabled: bright = self._get_property('nl_br') else: bright = self._get_property('bright') if bright: self._brightness = round(255 * (int(bright) / 100)) temp_in_k = self._get_property('ct') if temp_in_k: self._color_temp = kelvin_to_mired(int(temp_in_k)) self._hs = self._get_hs_from_properties()
def update(self): """Update the TP-Link Bulb's state.""" from pyHS100 import SmartDeviceException try: if self._supported_features == 0: self.get_features() self._state = ( self.smartbulb.state == self.smartbulb.BULB_STATE_ON) # Pull the name from the device if a name was not specified if self._name == DEFAULT_NAME: self._name = self.smartbulb.alias if self._supported_features & SUPPORT_BRIGHTNESS: self._brightness = brightness_from_percentage( self.smartbulb.brightness) if self._supported_features & SUPPORT_COLOR_TEMP: if (self.smartbulb.color_temp is not None and self.smartbulb.color_temp != 0): self._color_temp = kelvin_to_mired( self.smartbulb.color_temp) if self._supported_features & SUPPORT_COLOR: hue, sat, _ = self.smartbulb.hsv self._hs = (hue, sat) if self.smartbulb.has_emeter: self._emeter_params[ATTR_CURRENT_POWER_W] = '{:.1f}'.format( self.smartbulb.current_consumption()) daily_statistics = self.smartbulb.get_emeter_daily() monthly_statistics = self.smartbulb.get_emeter_monthly() try: self._emeter_params[ATTR_DAILY_ENERGY_KWH] \ = "{:.3f}".format( daily_statistics[int(time.strftime("%d"))]) self._emeter_params[ATTR_MONTHLY_ENERGY_KWH] \ = "{:.3f}".format( monthly_statistics[int(time.strftime("%m"))]) except KeyError: # device returned no daily/monthly history pass self._available = True except (SmartDeviceException, OSError) as ex: if self._available: _LOGGER.warning( "Could not read state for %s: %s", self._name, ex) self._available = False
def update(self): """Update the TP-Link Bulb's state.""" from pyHS100 import SmartPlugException try: self._state = ( self.smartbulb.state == self.smartbulb.BULB_STATE_ON) self._brightness = brightness_from_percentage( self.smartbulb.brightness) if self.smartbulb.is_color: if (self.smartbulb.color_temp is not None and self.smartbulb.color_temp != 0): self._color_temp = kelvin_to_mired( self.smartbulb.color_temp) self._rgb = hsv_to_rgb(self.smartbulb.hsv) except (SmartPlugException, OSError) as ex: _LOGGER.warning('Could not read state for %s: %s', self.name, ex)
def update(self): """Update the TP-Link Bulb's state.""" from pyHS100 import SmartDeviceException try: self._available = True if self._supported_features == 0: self.get_features() self._state = ( self.smartbulb.state == self.smartbulb.BULB_STATE_ON) if self._name is None: self._name = self.smartbulb.alias if self._supported_features & SUPPORT_BRIGHTNESS: self._brightness = brightness_from_percentage( self.smartbulb.brightness) if self._supported_features & SUPPORT_COLOR_TEMP: if (self.smartbulb.color_temp is not None and self.smartbulb.color_temp != 0): self._color_temp = kelvin_to_mired( self.smartbulb.color_temp) if self._supported_features & SUPPORT_RGB_COLOR: self._rgb = hsv_to_rgb(self.smartbulb.hsv) if self.smartbulb.has_emeter: self._emeter_params[ATTR_CURRENT_CONSUMPTION] \ = "%.1f W" % self.smartbulb.current_consumption() daily_statistics = self.smartbulb.get_emeter_daily() monthly_statistics = self.smartbulb.get_emeter_monthly() try: self._emeter_params[ATTR_DAILY_CONSUMPTION] \ = "%.2f kW" % daily_statistics[int( time.strftime("%d"))] self._emeter_params[ATTR_MONTHLY_CONSUMPTION] \ = "%.2f kW" % monthly_statistics[int( time.strftime("%m"))] except KeyError: # device returned no daily/monthly history pass except (SmartDeviceException, OSError) as ex: _LOGGER.warning("Could not read state for %s: %s", self._name, ex) self._available = False
def update(self) -> None: """Update properties from the bulb.""" import yeelight try: self._bulb.get_properties() self._is_on = self._properties.get("power") == "on" bright = self._properties.get("bright", None) if bright: self._brightness = 255 * (int(bright) / 100) temp_in_k = self._properties.get("ct", None) if temp_in_k: self._color_temp = kelvin_to_mired(int(temp_in_k)) self._rgb = self._get_rgb_from_properties() self._available = True except yeelight.BulbException as ex: if self._available: # just inform once _LOGGER.error("Unable to update bulb status: %s", ex) self._available = False
def max_mireds(self): """Return maximu supported color temperature.""" return kelvin_to_mired(EUFY_MIN_KELVIN)
def __init__(self, *args, **kwargs): """Initialize the Yeelight Ambient light.""" super().__init__(*args, **kwargs) self._min_mireds = kelvin_to_mired(6500) self._max_mireds = kelvin_to_mired(1700)
def color_temp(self): """Return the color temperature of this light.""" return kelvin_to_mired(self._color_temp)
def max_mireds(self) -> int: """Return maximum supported color temperature.""" return kelvin_to_mired(self.device.valid_temperature_range.min)
def color_temp(self): """Return the color temperature of this light.""" temp_in_k = int(EUFY_MIN_KELVIN + (self._temp * (EUFY_MAX_KELVIN - EUFY_MIN_KELVIN) / 100)) return kelvin_to_mired(temp_in_k)
def min_mireds(self): """Return minimum supported color temperature.""" return kelvin_to_mired(EUFY_MAX_KELVIN)
def max_mireds(self): """Return maximum supported color temperature.""" if self.supported_features & SUPPORT_COLOR_TEMP: return kelvin_to_mired(YEELIGHT_RGB_MIN_KELVIN) return kelvin_to_mired(YEELIGHT_MIN_KELVIN)
def max_mireds(self): """Return the warmest color_temp that this light supports.""" return kelvin_to_mired(3000)
def min_mireds(self): """Return the coldest color_temp that this light supports.""" return kelvin_to_mired(6500)
def color_temp(self): """Return the CT color value in mireds.""" if not self._color_temp: return None return int(kelvin_to_mired(self._color_temp))
def max_mireds(self): """Return the warmest color_temp that this light supports.""" if not self._color_temp_min: return None return kelvin_to_mired(self._color_temp_min)
def color_temp(self) -> int | None: """Return the color temperature of this light in mireds for HA.""" return kelvin_to_mired(self.device.color_temp)
def min_mireds(self): """Return minimum supported color temperature.""" return kelvin_to_mired(EUFY_MAX_KELVIN)
def color_temp(self): """Return the color temperature of this light.""" temp_in_k = int(EUFY_MIN_KELVIN + (self._temp * (EUFY_MAX_KELVIN - EUFY_MIN_KELVIN) / 100)) return kelvin_to_mired(temp_in_k)
def max_mireds(self): """Return maximum supported color temperature.""" if self.supported_features & SUPPORT_COLOR_TEMP: return kelvin_to_mired(YEELIGHT_RGB_MIN_KELVIN) return kelvin_to_mired(YEELIGHT_MIN_KELVIN)
def max_mireds(self): """Return maximu supported color temperature.""" return kelvin_to_mired(EUFY_MIN_KELVIN)
def max_mireds(self): """Return maximum supported color temperature.""" return kelvin_to_mired(self.smartbulb.valid_temperature_range[0])
def color_temp(self) -> int: """Return the color temperature.""" temp_in_k = self._get_property("ct") if temp_in_k: self._color_temp = kelvin_to_mired(int(temp_in_k)) return self._color_temp
def color_temp(self) -> int: """Return the color temperature.""" temp = self._get_property('ct') if temp: self._color_temp = temp return kelvin_to_mired(int(self._color_temp))
def color_temp(self): """Return the color temperature of this light.""" return kelvin_to_mired(self._color_temp)
def color_temp(self) -> int: """Return the current color temperature.""" return kelvin_to_mired(self._nanoleaf.color_temperature)