Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Xiaomi Philips Lights: Platform not ready behavior fixed #9325

Merged
merged 1 commit into from
Sep 7, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 17 additions & 2 deletions homeassistant/components/light/xiaomi_philipslight.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
CCT_MAX = 100

SUCCESS = ['ok']
ATTR_MODEL = 'model'


# pylint: disable=unused-argument
Expand All @@ -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
Expand All @@ -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):
Expand All @@ -90,6 +100,11 @@ def available(self):
"""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."""
Expand Down