From 9a7089bad30f3fe0b8a05569f723e9ce77d40a60 Mon Sep 17 00:00:00 2001 From: Sebastian Muszynski Date: Thu, 7 Sep 2017 09:01:59 +0200 Subject: [PATCH] Platform not ready behavior fixed. (#9325) Expose the device model as sensor attribute. Device initialized log message added. Provides device model, firmware and hardware version. --- .../components/light/xiaomi_philipslight.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/light/xiaomi_philipslight.py b/homeassistant/components/light/xiaomi_philipslight.py index 96d2d7ff9d2..8df25153a73 100644 --- a/homeassistant/components/light/xiaomi_philipslight.py +++ b/homeassistant/components/light/xiaomi_philipslight.py @@ -35,6 +35,7 @@ CCT_MIN = 1 CCT_MAX = 100 SUCCESS = ['ok'] +ATTR_MODEL = 'model' # pylint: disable=unused-argument @@ -53,8 +54,13 @@ def async_setup_platform(hass, config, async_add_devices, discovery_info=None): try: light = Ceil(host, token) + device_info = light.info() + _LOGGER.info("%s %s %s initialized", + device_info.raw['model'], + device_info.raw['fw_ver'], + device_info.raw['hw_ver']) - philips_light = XiaomiPhilipsLight(name, light) + philips_light = XiaomiPhilipsLight(name, light, device_info) hass.data[PLATFORM][host] = philips_light except DeviceException: raise PlatformNotReady @@ -65,15 +71,19 @@ def async_setup_platform(hass, config, async_add_devices, discovery_info=None): class XiaomiPhilipsLight(Light): """Representation of a Xiaomi Philips Light.""" - def __init__(self, name, light): + def __init__(self, name, light, device_info): """Initialize the light device.""" self._name = name + self._device_info = device_info self._brightness = None self._color_temp = None self._light = light self._state = None + self._state_attrs = { + ATTR_MODEL: self._device_info.raw['model'], + } @property def should_poll(self): @@ -90,6 +100,11 @@ class XiaomiPhilipsLight(Light): """Return true when state is known.""" return self._state is not None + @property + def device_state_attributes(self): + """Return the state attributes of the device.""" + return self._state_attrs + @property def is_on(self): """Return true if light is on."""