Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
54bef8c
Import
lwis Dec 13, 2017
c42e6bd
Fix bugs
lwis Dec 17, 2017
c386f8f
Change colour logic
lwis Dec 17, 2017
77d2f5d
Denormalise colour
lwis Dec 17, 2017
3ad01ac
Lint
lwis Dec 17, 2017
9aab001
Fix bug
lwis Dec 17, 2017
e183ef8
Fix bugs, expose rgb conversion
lwis Dec 18, 2017
dd5190c
Fix bug
lwis Dec 18, 2017
08432b5
Fix bug
lwis Dec 18, 2017
8010c2a
Fix bug
lwis Dec 18, 2017
34323f1
Improve XY
lwis Dec 21, 2017
19ea536
Improve XY
lwis Dec 21, 2017
5c46fc4
async/wait for tradfri.
lwis Mar 4, 2018
3b3a329
Remove comma
lwis Mar 4, 2018
28bdfbf
Switch to new HS colour system, using native data from tradfri gateway.
lwis Mar 21, 2018
f08833e
Lint.
lwis Mar 21, 2018
9f1bd74
Brightness bug.
lwis Mar 21, 2018
9d9509b
Remove guard.
lwis Mar 21, 2018
e8beb9d
Temp workaround for bug.
lwis Mar 22, 2018
4938a18
Temp workaround for bug.
lwis Mar 22, 2018
762009d
Temp workaround for bug.
lwis Mar 22, 2018
adc382e
Safety.
lwis Mar 22, 2018
759ef6d
Switch logic.
lwis Mar 22, 2018
62dad67
Integrate latest
lwis Mar 22, 2018
53341fe
Fixes.
lwis Mar 23, 2018
ffdca3f
Fixes.
lwis Mar 23, 2018
5d7fc89
Mired validation.
lwis Mar 23, 2018
3635cfa
Set bounds.
lwis Mar 23, 2018
a6ea8b3
Transition time.
lwis Mar 23, 2018
dbb9b9a
Transition time.
lwis Mar 23, 2018
cc3990f
Transition time.
lwis Mar 23, 2018
93017f5
Fix brightness values.
lwis Mar 23, 2018
eb457d9
unique_ids for tradfri lights and groups
NovapaX Mar 24, 2018
61c295b
set color temperature on CWS bulb
NovapaX Mar 24, 2018
c5748dc
make travis happy
NovapaX Mar 24, 2018
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
48 changes: 38 additions & 10 deletions homeassistant/components/light/tradfri.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
PLATFORM_SCHEMA as LIGHT_PLATFORM_SCHEMA
from homeassistant.components.tradfri import KEY_GATEWAY, KEY_TRADFRI_GROUPS, \
KEY_API
import homeassistant.util.color as color_util

_LOGGER = logging.getLogger(__name__)

Expand All @@ -41,32 +42,40 @@ async def async_setup_platform(hass, config,
devices = await api(devices_commands)
lights = [dev for dev in devices if dev.has_light_control]
if lights:
async_add_devices(TradfriLight(light, api) for light in lights)
async_add_devices(
TradfriLight(light, api, gateway_id) for light in lights)

allow_tradfri_groups = hass.data[KEY_TRADFRI_GROUPS][gateway_id]
if allow_tradfri_groups:
groups_command = gateway.get_groups()
groups_commands = await api(groups_command)
groups = await api(groups_commands)
if groups:
async_add_devices(TradfriGroup(group, api) for group in groups)
async_add_devices(
TradfriGroup(group, api, gateway_id) for group in groups)


class TradfriGroup(Light):
"""The platform class required by hass."""

def __init__(self, light, api):
def __init__(self, group, api, gateway_id):
"""Initialize a Group."""
self._api = api
self._group = light
self._name = light.name
self._unique_id = "group-{}-{}".format(gateway_id, group.id)
self._group = group
self._name = group.name

self._refresh(light)
self._refresh(group)

async def async_added_to_hass(self):
"""Start thread when added to hass."""
self._async_start_observe()

@property
def unique_id(self):
"""Return unique ID for this group."""
return self._unique_id

@property
def should_poll(self):
"""No polling needed for tradfri group."""
Expand Down Expand Up @@ -144,9 +153,10 @@ def _observe_update(self, tradfri_device):
class TradfriLight(Light):
"""The platform class required by Home Assistant."""

def __init__(self, light, api):
def __init__(self, light, api, gateway_id):
"""Initialize a Light."""
self._api = api
self._unique_id = "light-{}-{}".format(gateway_id, light.id)
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.

Use the device info serial instead of crafting your own: https://github.com/ggravlingen/pytradfri/blob/master/pytradfri/device.py#L111

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Of course I would’ve used that if it actually returned anything other than a blank string. ☺️

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.

Sounds like a bug upstream 😉

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes. You’d say. Bit it looks like the gateway doesn’t return it, so it’s not a bug in pytradri.
I’ll do some packet sniffing to make sure.

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.

IIRC the raw data contains a blank string.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Wasn’t there someone in the community who had contact with a tradfri dev at IKEA?
Maybe we can ask if they can modify the gateway firmware to include it in thier response, and if so at what timeframe.
Else this current unique-is is the best we can get I guess.

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.

They don't seem to be very receptive to queries as it's not a public API. So we either forego unique I'd until IKEA provide a better solution, or we use this.

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.

I'm fine with the current implementation. Or do we know if Tradfri is reusing IDs if we unpair/pair a bulb?

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.

Sorry, just saw the other comments. Disregard

self._light = None
self._light_control = None
self._light_data = None
Expand All @@ -157,6 +167,11 @@ def __init__(self, light, api):

self._refresh(light)

@property
def unique_id(self):
"""Return unique ID for light."""
return self._unique_id

@property
def min_mireds(self):
"""Return the coldest color_temp that this light supports."""
Expand Down Expand Up @@ -252,9 +267,22 @@ async def async_turn_on(self, **kwargs):

if brightness is None:
params[ATTR_TRANSITION_TIME] = transition_time
await self._api(
self._light_control.set_color_temp(temp,
**params))
# White Spectrum bulb (can set temp, but cannot set color)
if (self._light_control.can_set_temp and
not self._light_control.can_set_color):
await self._api(
self._light_control.set_color_temp(temp, **params))
# Color White Spsctrum (CWS) bulb
# (It can set temp, but we need to set with hsb)
if self._light_control.can_set_color:
params[ATTR_BRIGHTNESS] = brightness
temp_k = color_util.color_temperature_mired_to_kelvin(temp)
hs_color = color_util.color_temperature_to_hs(temp_k)
hue = int(hs_color[0] * (65535 / 360))
sat = int(hs_color[1] * (65279 / 100))
await self._api(
self._light_control.set_hsb(hue, sat,
**params))

if brightness is not None:
params[ATTR_TRANSITION_TIME] = transition_time
Expand Down
37 changes: 19 additions & 18 deletions requirements_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ pip>=8.0.3
jinja2>=2.10
voluptuous==0.11.1
typing>=3,<4
aiohttp==3.1.1
aiohttp==3.0.9
async_timeout==2.0.1
astral==1.6
certifi>=2017.4.17
Expand Down Expand Up @@ -74,7 +74,7 @@ aiodns==1.1.1
aiohttp_cors==0.7.0

# homeassistant.components.hue
aiohue==1.3.0
aiohue==1.2.0

# homeassistant.components.sensor.imap
aioimaplib==0.7.13
Expand Down Expand Up @@ -137,7 +137,7 @@ beautifulsoup4==4.6.0
bellows==0.5.1

# homeassistant.components.bmw_connected_drive
bimmer_connected==0.5.0
bimmer_connected==0.4.1

# homeassistant.components.blink
blinkpy==0.6.0
Expand Down Expand Up @@ -356,7 +356,7 @@ hipnotify==1.0.8
holidays==0.9.4

# homeassistant.components.frontend
home-assistant-frontend==20180326.0
home-assistant-frontend==20180316.0

# homeassistant.components.homematicip_cloud
homematicip==0.8
Expand Down Expand Up @@ -430,10 +430,10 @@ jsonrpc-async==0.6
jsonrpc-websocket==0.6

# homeassistant.scripts.keyring
keyring==12.0.0
keyring==11.0.0

# homeassistant.scripts.keyring
keyrings.alt==3.0
keyrings.alt==2.3

# homeassistant.components.device_tracker.owntracks
# homeassistant.components.device_tracker.owntracks_http
Expand Down Expand Up @@ -685,7 +685,7 @@ pybbox==0.0.5-alpha
pychannels==1.0.0

# homeassistant.components.media_player.cast
pychromecast==2.1.0
pychromecast==2.0.0

# homeassistant.components.media_player.cmus
pycmus==0.1.0
Expand Down Expand Up @@ -804,7 +804,7 @@ pylutron==0.1.0
pymailgunner==1.4

# homeassistant.components.media_player.mediaroom
pymediaroom==0.6
pymediaroom==0.5

# homeassistant.components.media_player.xiaomi_tv
pymitv==1.0.0
Expand Down Expand Up @@ -860,7 +860,7 @@ pyowm==2.8.0
pypollencom==1.1.1

# homeassistant.components.qwikswitch
pyqwikswitch==0.5
pyqwikswitch==0.4

# homeassistant.components.rainbird
pyrainbird==0.1.3
Expand Down Expand Up @@ -948,14 +948,14 @@ python-juicenet==0.0.5
# homeassistant.components.sensor.xiaomi_miio
# homeassistant.components.switch.xiaomi_miio
# homeassistant.components.vacuum.xiaomi_miio
python-miio==0.3.9
python-miio==0.3.8

# homeassistant.components.media_player.mpd
python-mpd2==0.5.5

# homeassistant.components.light.mystrom
# homeassistant.components.switch.mystrom
python-mystrom==0.4.2
python-mystrom==0.3.8

# homeassistant.components.nest
python-nest==3.7.0
Expand All @@ -976,7 +976,7 @@ python-roku==3.1.5
python-sochain-api==0.0.2

# homeassistant.components.media_player.songpal
python-songpal==0.0.7
python-songpal==0.0.6

# homeassistant.components.sensor.synologydsm
python-synology==0.1.0
Expand Down Expand Up @@ -1006,7 +1006,8 @@ python_opendata_transport==0.0.3
python_openzwave==0.4.3

# homeassistant.components.egardia
pythonegardia==1.0.39
# homeassistant.components.alarm_control_panel.egardia
pythonegardia==1.0.38

# homeassistant.components.sensor.whois
pythonwhois==2.4.3
Expand Down Expand Up @@ -1048,13 +1049,13 @@ pywebpush==1.6.0
pywemo==0.4.25

# homeassistant.components.camera.xeoma
pyxeoma==1.4.0
pyxeoma==1.3

# homeassistant.components.zabbix
pyzabbix==0.7.4

# homeassistant.components.sensor.qnap
qnapstats==0.2.5
qnapstats==0.2.4

# homeassistant.components.switch.rachio
rachiopy==0.1.2
Expand Down Expand Up @@ -1136,7 +1137,7 @@ simplisafe-python==1.0.5
skybellpy==0.1.1

# homeassistant.components.notify.slack
slacker==0.9.65
slacker==0.9.60

# homeassistant.components.notify.xmpp
sleekxmpp==1.3.2
Expand Down Expand Up @@ -1218,7 +1219,7 @@ todoist-python==7.0.17
toonlib==1.0.2

# homeassistant.components.alarm_control_panel.totalconnect
total_connect_client==0.17
total_connect_client==0.16

# homeassistant.components.sensor.transmission
# homeassistant.components.switch.transmission
Expand Down Expand Up @@ -1307,7 +1308,7 @@ yahooweather==0.10
yeelight==0.4.0

# homeassistant.components.light.yeelightsunflower
yeelightsunflower==0.0.10
yeelightsunflower==0.0.8

# homeassistant.components.media_extractor
youtube_dl==2018.03.10
Expand Down