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.
This commit is contained in:
Sebastian Muszynski 2017-09-07 09:01:59 +02:00 committed by Paulus Schoutsen
parent 894200d87d
commit 9a7089bad3

View File

@ -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."""