Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions homeassistant/components/light/tplink.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
from pyHS100 import SmartBulb
host = config.get(CONF_HOST)
name = config.get(CONF_NAME)
add_devices([TPLinkSmartBulb(SmartBulb(host), name)], True)
bulb = TPLinkSmartBulb(SmartBulb(host), name)
bulb.get_features()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not keep this call inside the TPLinkSmartBulb class?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because I/O is not allowed inside constructor, and if those features are not set min_mireds may be called before there an initial update has happened. Or that's my understanding at least.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In async_update_ha_state the call to update will be done before any entity properties are accessed. I propose to revert all changes except on line 45, which will make sure that update is called before the first state update, and that supported features should be up to date.

Copy link
Copy Markdown
Member Author

@rytilahti rytilahti Jul 19, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, if that's the case, there's then no need for this PR at all actually and the problem itself should have been fixed by #15484, as the second parameter was True already.

add_devices([bulb], True)


def brightness_to_percentage(byt):
Expand Down Expand Up @@ -140,9 +142,6 @@ def update(self):
try:
self._available = True

if self._supported_features == 0:
self.get_features()

self._state = (
self.smartbulb.state == self.smartbulb.BULB_STATE_ON)

Expand Down