Git Product home page Git Product logo

pytradfri's People

Contributors

42b avatar 4ch1m avatar bachp avatar balloob avatar chrysn avatar cosmix avatar dependabot[bot] avatar ggravlingen avatar github-actions[bot] avatar hate-usernames avatar janiversen avatar jbkkd avatar kjlisby avatar lakitna avatar landrash avatar lwis avatar martijnvwezel avatar martinhjelmare avatar matemaciek avatar michaelnimbs avatar moroen avatar novapax avatar pvizeli avatar rob4t avatar roeladriaans avatar rubenbe avatar salbertson avatar stevenlooman avatar tazle avatar timothebarbe avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pytradfri's Issues

Travis returns error in device.py

The command "py.test" exited with 0.
1.06s$ flake8
./pytradfri/device.py:219:9: E722 do not use bare except'
The command "flake8" exited with 1.
cache.2
store build cache

Support pairing

Where are you using pytradfri (eg stand-alone, Home Assistant etc)

(Used stand-alone, version 4.0.5): I found no way to initiate pairing.

The handbook says that to pair a lamp/switch with the gateway I should run the app, but lacking a device where I can easily run the app, I can't even do that once to listen to how the app puts the device in pairing mode.

Do you have any clues yet as to how pairing is initiated? It should be possible to determine that from sniffing on the network.

Color ranges

Where are you using pytradfri (eg stand-alone, Home Assistant etc)

Stand-alone

Version of pytradfri

5.2.0

I can't find the min and max values of some color properties. I'd like to normalise the values, so I need the absolute minimum and maximum values. Does anyone know them? If they are unkown I'll write a script to find out.

  • Hue (best guess: [0, 64800])
  • Saturation (best guess: [0, 65279])

Might be a good idea to add things like this to the wiki.

Trådfri gateway security improvements using DTLS

Just got this from The Ikea of Sweden Trådfri Team.
I hope you're already aware of this, I don't understand the technical details but I assume that this is a breaking change for pytradfri.

We at IKEA would like to inform you about a change to our TRÅDFRI Gateway. We are very happy to see your interest in our gateway and have seen that you are using the CoAP interface. We consider the CoAP interface as our internal interface not developed for third party usage and therefore we do not offer any technical support for this usage. However that does not mean that we want to hinder your work in any way.

There are some security improvements in a soon coming update that we would like to inform you about since it will break your implementation. Technically the improvement is that the TRÅDFRI Gateway will start using DTLS Identities which you will need to handle in your application.

Please use the Following string to connect to the TRÅDFRI Gateway and create a new DTLS Identity.

coap-client -m post -u "Client_identity" -k "SECURITY_CODE" -e '{"9090":"IDENTITY"}' "coaps://IP_ADDRESS:5684/15011/9063"

SECURITY_CODE is what is labelled on the Gateway label, IDENTITY is any string that is representing the connection.
You will then get back a PRE_SHARED_KEY that can be use in all traffic after that.

coap-client -m get -u "IDENTITY" -k "PRE_SHARED_KEY" "coaps://IP_ADDRESS:5684/15001"

We also would like to request that the SECURITY_CODE that is printed on the gateway is never stored permanently in your application.

Best regards
IKEA of Sweden Trådfri team

Issues with necessary gateway restart

Hello,

As many others are experiencing. When you reach a certain number of bulbs, the gateway needs restarting every 1-2 days. I use IKEA Trådfri with Home Assistant, and feature wise it works great.

Thing is, whenever I reboot the gateway to be able to reach the bulbs, all light groups are switched to off in Home Assistant. Even though they are on. This happens every time.

Home Assistant says it supports local push, which means updates should be pushed automatically. Any way to fix this? Waiting for IKEA to fix their gateway could take some time.. This just started happening when reaching bulb number 20.

not able to activate moods

Where are you using pytradfri (eg stand-alone, Home Assistant etc)

stand alone

Version of pytradfri

4.0.2

Expected behaviour

gather all available moods and activate one of the moods on a specific group

Actual behaviour

I am in trouble to activate the moods.
I wrote this simple code, but it doesn't have any effect.
I couldn't find any working examples so I am not sure it is correct.

groups_command = gateway.get_groups()
groups_commands = api(groups_command)
groups = api(groups_commands)
    
mood_command = gateway.get_moods()
moods = api(mood_command)
#selecting the second group
group = groups[1]
#selecting the third mood 
mood = moods[2]
    
#activate the mood to the selected group
group.activate_mood(mood)

In order to get the mood_id I have also tried with
mood.path
['15005', <pytradfri.command.Command object at 0x76a17590>, 131077]

I suppose the third parameter was the mood_id, but I found it is the parent group_id. Is it right?

Thank you

Usage broken after v2.2

Where are you using pytradfri (eg stand-alone, Home Assistant etc)

stand-alone

Version of pytradfri

>2.2

Expected behaviour

working like <=2.2

Actual behaviour

using >3.0

root@rpi-srv3:~# python3
Python 3.5.2 (default, Sep 14 2017, 22:51:06)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from pytradfri.api.libcoap_api import api_factory
>>> api = api_factory("192.168.21.26", "<key>")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.5/dist-packages/pytradfri/api/libcoap_api.py", line 131, in api_factory
      request(Command('get', ['status']))
  File "/usr/local/lib/python3.5/dist-packages/pytradfri/api/libcoap_api.py", line 78, in request
      return _execute(api_commands[0])
TypeError: 'Command' object does not support indexing

I know some things have changed but examples in code are not working anymore. Please clarify.

pytradfri.error.RequestError

Hi, I still get this error when I call "pytradfri.coap_cli.api_factory(ip,key)". Iam on mac (IP and key are ok)
File "/usr/local/lib/python3.6/site-packages/pytradfri/coap_cli.py", line 81, in api_factory request('get', ['status']) File "/usr/local/lib/python3.6/site-packages/pytradfri/coap_cli.py", line 56, in request 'Error executing request: %s'.format(err)) from None pytradfri.error.RequestError: Error executing request: %s

Group color

Hi
Sorry to open an issue for that but I try to understand the commands sent to Tradfri to control bulbs.
I understood practically everything but I didn't see how to change color of all group's bulbs ?

Is it possible to change the color for the entire group or must we change color of each bulb ?

Thank for your help !

Lamps not identified as lamps with f/w 1.3.14

I am a new user of pytradfri trying to integrate my gateway with homeassistant.
As I know HA only use version 4.1.0 of pytradfri I have also been testing with the standalone version of pytradfri 5.2.0

As my gateway is new and autoupgraded to v 1.3.14 imediately I have'nt tested any earlier firmwares of the gateway. My lamps have fw-version 1.2.217.

When I run pytradfri in Homeassistant my lamps are detected as sensors. I have the same problem with my standalone 5.2.0 test.

output from "python3 -i -m pytradfri 192.168.1.7 key"

DEBUG:pytradfri.api.libcoap_api:Executing 192.168.1.7 get ['15001']
DEBUG:pytradfri.api.libcoap_api:Received: [65536,65537,65539,65538,65540]
DEBUG:pytradfri.api.libcoap_api:Executing 192.168.1.7 get ['15001', 65536]
DEBUG:pytradfri.api.libcoap_api:Received: {"9001":"Fjärrkontroll 1","5750":0,"9002":1515435028,"9020":1515870426,"9003":65536,"9054":0,"9019":1,"3":{"0":"IKEA of Sweden","1":"TRADFRI remote control","2":"","3":"1.2.214","6":3,"9":87},"15009":[{"9003":0}]}
DEBUG:pytradfri.api.libcoap_api:Executing 192.168.1.7 get ['15001', 65537]
DEBUG:pytradfri.api.libcoap_api:Received: {"9001":"Tak vr 1","5750":0,"9002":1515435088,"9020":1516008067,"9003":65537,"9054":0,"9019":1,"3":{"0":"IKEA of Sweden","1":"TRADFRI bulb GU10 WS 400lm","2":"","3":"1.2.217","6":1},"15009":[{"5851":10,"5850":0,"5717":0,"5711":450,"5709":30138,"5710":26909,"5706":"efd275","9003":0}]}
DEBUG:pytradfri.api.libcoap_api:Executing 192.168.1.7 get ['15001', 65539]
DEBUG:pytradfri.api.libcoap_api:Received: {"9001":"Tak vr 3","5750":0,"9002":1515435277,"9020":1516008127,"9003":65539,"9054":0,"9019":1,"3":{"0":"IKEA of Sweden","1":"TRADFRI bulb GU10 WS 400lm","2":"","3":"1.2.217","6":1},"15009":[{"5851":10,"5850":0,"5717":0,"5711":450,"5709":30138,"5710":26909,"5706":"efd275","9003":0}]}
DEBUG:pytradfri.api.libcoap_api:Executing 192.168.1.7 get ['15001', 65538]
DEBUG:pytradfri.api.libcoap_api:Received: {"9001":"Tak vr 2","5750":0,"9002":1515435198,"9020":1516008063,"9003":65538,"9054":0,"9019":1,"3":{"0":"IKEA of Sweden","1":"TRADFRI bulb GU10 WS 400lm","2":"","3":"1.2.217","6":1},"15009":[{"5851":10,"5850":0,"5717":0,"5711":450,"5709":30138,"5710":26909,"5706":"efd275","9003":0}]}
DEBUG:pytradfri.api.libcoap_api:Executing 192.168.1.7 get ['15001', 65540]
DEBUG:pytradfri.api.libcoap_api:Received: {"9001":"Tak vr 4","5750":0,"9002":1515435391,"9020":1516008285,"9003":65540,"9054":0,"9019":1,"3":{"0":"IKEA of Sweden","1":"TRADFRI bulb GU10 WS 400lm","2":"","3":"1.2.217","6":1},"15009":[{"5851":10,"5850":0,"5717":0,"5711":450,"5709":30138,"5710":26909,"5706":"efd275","9003":0}]}
Traceback (most recent call last):
  File "/usr/lib/python3.6/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/usr/lib/python3.6/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/usr/local/lib/python3.6/dist-packages/pytradfri/__main__.py", line 36, in <module>
    light = lights[0]
IndexError: list index out of range
>>> lights
[]
>>>

I would expect my 4 TRADFRI bulb GU10 WS 400lm to be identified as lamps, but the lights array looks empty. I've tried to read the source, but is new to python (c# and perl nerd).

gateway = Gateway()
devices_commands = api(gateway.get_devices())
devices = api(devices_commands)
lights = [dev for dev in devices if dev.has_light_control]
light = lights[0]

It looks to me as pytradfri when calling the coap api does'nt get it right. The lamp devices does not have "has_light_control" set to true...

Inconsistent use of

Readme advocates the use of PSK, but examples fall back to use the Security Key.

"Please always use the PSK when communicating with the gateway."
"KEY is written on the back of your IKEA Tradfri Gateway."

As in home-assistant/core#10252 all of us should use the PSK.

Expected: clarity in the Readme.

Move discovered tradfri-behaviour specific code from home-assistant to pytradfri

Suggested specification:

  • LightControl will receive new methods:
    • can_set_color - returns whether controlled light supports arbitrary color. If so, all of following should change color of light as requested: set_hex_color, set_xy_color, and set_rgb_color. The range of supported colors is not specified, but if some color works in one space and can be specified in other space it should also work there.
    • can_set_kelvin - returns whether controlled light supports color temperature. If so, set_kelvin_color should change color of light as requested. The range of supported tempertures is defined by methods min_kelvin and max_kelvin.
    • min_kelvin - explained above.
    • max_kelvin - explained above.
  • Light will satisfy following speciffication:
    • kelvin_color, xy_color, hex_color and rgb_color will return colors coresponding to actual state of the bulb, regardles of bulb type (white / white spectrum / color & white spectrum). Exception: kelvin_color on colors outside of white spectrum may return None. Boundaries of white spectrum in colored spaces are not strictly defined.

cleanup on asyncio.CancelledError

I'm putting some api calls in a async_timeout, because aiocoap has a 1+ minute timeout by default.

But pytradfri doesn't cleanup on a asyncio.CancelledError.
I think it should.

The place to add such thing would be here right?
https://github.com/ggravlingen/pytradfri/blob/b4a0ee2210d6a5643bffc40829e6f093a1dbc796/pytradfri/api/aiocoap_api.py#L99-L102

        except asyncio.CancelledError as e:
            yield from self._reset_protocol(e)
            raise e

If so I would be glad to make a pull request.

Color temperature in 5.0.0

Where are you using pytradfri (eg stand-alone, Home Assistant etc)

Stand-alone

Version of pytradfri

5.0.0

Expected behaviour

Return color temperature in Kelvin (though Mireds would work too)

Actual behaviour

Return None

My program depends on using color temperatures to define the color of the lamps. I was just trying to port my program to 5.0.0 when I found out that I can't directly get the color temperature anymore as the function returns None.

I traced it to the following code in device.py

@property
def color_temp(self):
    if self.supported_features & SUPPORT_COLOR_TEMP:
        if self.raw.get(ATTR_LIGHT_MIREDS) != 0:
            return self.raw.get(ATTR_LIGHT_MIREDS)

I'm calling the function like this:

light = device.light_control.lights[0]
print(light.dimmer) # returns proper dimmer value
print(light.state) # returns proper state value
print(light.color_temp) # returns None

set_rgb_color not setting correct values

Where are you using pytradfri (eg stand-alone, Home Assistant etc)

Stand-alone in docker dev environment.

Version of pytradfri

4.0.2 or dev?

When setting an RGB value to a color bulb (in my case this is lights[1]) with the command:
api(lights[1].light_control.set_rgb_color(142,116,51))
the resulting RGB value when reading from the light will be:
rgb_color: 153,109,39

PyTradfri 2.0: sans-io

In the Python community there has been a movement to make Sans-IO libraries. For an intro, see this talk by Cory Benfield at PyCon 2016.

The idea is to separate the parser from the actual sending/receiving of messages so that there can be different implementations. With aiocoap being on the horizon (#28), I want to transform the library to be able to both support a sync and async API.

The code is already organized in such a way that the migration will be fairly painless. All writing is already done via a single method: set_values. Instead of having our methods call the API directly, we will have it return a command object. We then have different APIs that we can give the command to.

The sync API would look like this:

command = light.light_control.set_dimmer(100)
api(command)

If the API wants to consume the response from the command, we can have a callback method be added to the command that can automatically be called by an implementing API.

command = light.update()
yield from api(command)
# Under the hood api calls `command.set_result(result)`

Continuous observations

Using the aiocoap-library, are there any possibility of continuous observation, aka unlimited observation duration? I've been unable to find any obvious way, might be overlooking something?

I've been thinking about just rescheduling the observation when it ends, but there might be a better way? Hoping to try utilizing some of the IKEA-tradfri sensors.

Setting color values individually

Where are you using pytradfri (eg stand-alone, Home Assistant etc)

Stand-alone

Version of pytradfri

5.2.1

Expected behaviour

lamp.light_control.set_hsb(1000, 1000, None)

Above code should update hue and saturation, but leave brightness unchanged. This is the behaviour of 5.2.0

Actual behaviour

Program crashes with the following (partial) traceback:

  File "/usr/local/lib/python3.6/site-packages/pytradfri/device.py", line 224, in set_hsb
    self._value_validate(brightness, RANGE_BRIGHTNESS, "Brightness")
  File "/usr/local/lib/python3.6/site-packages/pytradfri/device.py", line 266, in _value_validate
    if value < rnge[0] or value > rnge[1]:
TypeError: '<' not supported between instances of 'NoneType' and 'int'

In other words. The value validation I wrote blocks this type of use.

Solution

The easiest solution is changing the value validation to allow None as a value.

See PR #139

Error when no lights visible with only the remote control

Hello,
i have a little test setup with one light and one remote control.
When the light was not visible for a while by the tradfri gateway, i got the following error when calling has_light_control:

File "/home/pi/PI_Drivers.py", line 272, in
ikea_drv.lights = [dev for dev in ikea_drv.devs if dev.has_light_control]

File "/usr/local/lib/python3.5/dist-packages/pytradfri-2.2.1-py3.5.egg/pytradfri/device.py", line 51, in has_light_control
return (ATTR_LIGHT_CONTROL in self.raw and

TypeError: argument of type 'NoneType' is not iterable

So there is one device, however not a device with light_control.
The script should catch this.

Ofcourse this is a minor bug.
Thanks for this nice module!
Rudy

pytradfri.error.RequestTimeout when using pytradfri inside an infinite loop

I am using the pytradfri lib in a daemon service that run on a pi as an interface to my home automation system JEEDOM.
Using either a pooling method, that check the gateway every 10 sec. or the new observe function (as in example_sync), after some time I get a timeout error:

File "/usr/local/lib/python3.4/dist-packages/pytradfri/api/lib
juin 21 09:00:25 jeedomGaule tradfridaemon.py[23714]: request(Command('get', ['status']))
juin 21 09:00:25 jeedomGaule tradfridaemon.py[23714]: File "/usr/local/lib/python3.4/dist-packages/pytradfri/api/lib
juin 21 09:00:25 jeedomGaule tradfridaemon.py[23714]: return _execute(api_commands[0])
juin 21 09:00:25 jeedomGaule tradfridaemon.py[23714]: File "/usr/local/lib/python3.4/dist-packages/pytradfri/api/lib
juin 21 09:00:25 jeedomGaule tradfridaemon.py[23714]: raise RequestTimeout() from None
juin 21 09:00:25 jeedomGaule tradfridaemon.py[23714]: pytradfri.error.RequestTimeout

and I had to unplug the gateway to be able to access it again.

  • Maybe I am doing something wrong with pytradfri ?
  • Are there a way to do a soft reset of the gateway (without libcoap) ?
  • Another question is the value of the duration parameter in the device.observe ?
  • Can I run it indefinitely ? I try 0 but I received "Observing stopped" after some time. If I restart the thread, I get the RequestTimeout error after some times

Thanks again for the lib
Marc

Connect problem

Hi,
I sill get error when I run pytradfri

python3 -i -m pytradfri 192.168.1.167 <SECRET KEY>

DEBUG:pytradfri.coap_cli:Executing 192.168.1.167 get ['status']
DEBUG:pytradfri.coap_cli:Received: {}
DEBUG:pytradfri.coap_cli:Executing 192.168.1.167 get ['15001']
DEBUG:pytradfri.coap_cli:Received: []
Traceback (most recent call last):
  File "/usr/lib/python3.4/runpy.py", line 170, in _run_module_as_main
    "__main__", mod_spec)
  File "/usr/lib/python3.4/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/usr/local/lib/python3.4/dist-packages/pytradfri/__main__.py", line 22, in <module>
    light = lights[0]
IndexError: list index out of range
>>> lights
[]
>>> 

If i understand correctly I can connect to gateway but there is no chance to get list of lights. (I own 2 lights) I have tried reset of gateway several times. Also on some fresh installation... raspbian, raspbian lite, hassbian, ubuntu. Oryginally i was try to connect tradfri via home assistant which is using this modifided libcoap but also no succes. Home assistant accepted my security key and thats it... no error but also no lights :( I suppose that the isssue is libcoap.

coap-client token argument

Hi,
I found where is the problem. Iam using coap-client (v4.1.1) and there is argument for token string "-T" but in pytradfri is used "-k", so it crash on illegal option.

Light ID

Where are you using pytradfri (eg stand-alone, Home Assistant etc)

Standalone

Version of pytradfri

Latest

Expected behaviour

More of a request for assistance than issue - is it possible to send a device ID to the program instead of an array [0]/[1]/[2]?
On restart of the gateway the order tends to change, resulting in lights being assigned a different number.
My planned usage is 'python3 pytradfri-program.py 65545 on' where 1 represents the change_state.
I understand usage of sys.argv.

Thank you

pytradfri.error.RequestTimeout

I get an RequestTimeout when I run python3 -i -m pytradfri IP KEY

DEBUG:pytradfri.coap_cli:Executing 10.6.2.153 get ['status']
Traceback (most recent call last):
  File "/usr/lib/python3.4/runpy.py", line 170, in _run_module_as_main
    "__main__", mod_spec)
  File "/usr/lib/python3.4/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/usr/src/app/pytradfri/__main__.py", line 18, in <module>
    api = api_factory(sys.argv[1], sys.argv[2])
  File "/usr/src/app/pytradfri/coap_cli.py", line 104, in api_factory
    request('get', ['status'])
  File "/usr/src/app/pytradfri/coap_cli.py", line 58, in request
    raise RequestTimeout() from None
pytradfri.error.RequestTimeout

Multiple gateways

Where are you using pytradfri (eg stand-alone, Home Assistant etc)

Home assistant

Version of pytradfri

4.0.1

Expected behaviour

Works with multiple gateways

Actual behaviour

undefined behaviour - lights are detected only on one gateway

I have 2 Tradfri gateways in different locations that are too far away to be controlled by a single gateway. Both are in the same network. With this configuration, HomeAssistant stops working properly, often one gateway is detected (most likely the one that response faster.

I see error messages like this:

2017-11-07 12:47:49 ERROR (MainThread) [coap] Fatal DTLS error: code 20
2017-11-07 12:47:49 ERROR (MainThread) [coap] Exception CancelledError() can not be represented as errno, setting -1.
2017-11-07 12:47:49 ERROR (MainThread) [homeassistant.core] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
File "/usr/lib/python3.6/asyncio/tasks.py", line 181, in _step
result = coro.throw(exc)
File "/usr/lib/python3.6/site-packages/homeassistant/components/tradfri.py", line 66, in configuration_callback
psk = yield from api_factory.generate_psk(callback_data.get('key'))
File "/usr/lib/python3.6/site-packages/pytradfri/api/aiocoap_api.py", line 193, in generate_psk
self._psk = yield from self.request(command)
File "/usr/lib/python3.6/site-packages/pytradfri/api/aiocoap_api.py", line 149, in request
result = yield from self._execute(api_commands)
File "/usr/lib/python3.6/site-packages/pytradfri/api/aiocoap_api.py", line 139, in _execute
_, res = yield from self._get_response(msg)
File "/usr/lib/python3.6/site-packages/pytradfri/api/aiocoap_api.py", line 92, in _get_response
r = yield from pr.response
File "/usr/lib/python3.6/asyncio/futures.py", line 331, in iter
yield self # This tells Task to wait for completion.
File "/usr/lib/python3.6/asyncio/tasks.py", line 244, in _wakeup
future.result()
File "/usr/lib/python3.6/asyncio/futures.py", line 244, in result
raise self._exception
File "/usr/lib/python3.6/site-packages/aiocoap/protocol.py", line 814, in _run_outer
yield from cls._run(app_request, response, weak_observation, protocol, log, exchange_monitor_factory)
File "/usr/lib/python3.6/site-packages/aiocoap/protocol.py", line 863, in _run
blockresponse = yield from blockrequest.response
File "/usr/lib/python3.6/asyncio/futures.py", line 331, in iter
yield self # This tells Task to wait for completion.
File "/usr/lib/python3.6/asyncio/tasks.py", line 244, in _wakeup
future.result()
File "/usr/lib/python3.6/asyncio/futures.py", line 244, in result
raise self._exception
OSError: [Errno -1] No error information
2017-11-07 12:47:50 ERROR (MainThread) [coap] Fatal DTLS error: code 20
2017-11-07 12:47:50 ERROR (MainThread) [coap] Exception CancelledError() can not be represented as errno, setting -1.
2017-11-07 12:47:50 ERROR (MainThread) [coap] Fatal DTLS error: code 20
2017-11-07 12:47:50 ERROR (MainThread) [coap] Exception CancelledError() can not be represented as errno, setting -1.
2017-11-07 12:47:50 ERROR (MainThread) [coap] Fatal DTLS error: code 20

I'm not sure, if this is a problem of PyTradfri or HomeAssistant.

Groups

Is it possible to set color temp for group?

Has anyone tried observing the tradfri motion montior with pytradfri

not a real Issue, more a question:
I was asking myself if i could use the IKEA tradri series (gateway & motion dector) with pytradfri to detect motion and run linux commands if motion is detected.
I'm not sure if this is possible but i thought maybe somebody has or can try it.

Address lights through name instead of index

I lost contact with my gatateway and rebooted. All devices were present but the index numbers had changed, the last bulb added was now at index 0 and my scripts stopped working. I'm now looping through the lights to check for name but it woud be better to be able to address through name and not only by index number. Alternatively adding a utility function that translates from name to index (-1 or similar if not found), to be used instead of using index number. Simplifies the code in the user script.

`NoneType` dereference in `generate_psk`

Where are you using pytradfri (eg stand-alone, Home Assistant etc)

Latest Home Assistant, fresh install

Version of pytradfri

4.1.0

Expected behaviour

pytradfri creates a PSK for the hub

Actual behaviour

We get a value of None for security_key:

2017-12-18 12:54:31 ERROR (MainThread) [homeassistant.core] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/home/vemek/.pyenv/versions/3.5.3/lib/python3.5/asyncio/tasks.py", line 241, in _step
    result = coro.throw(exc)
  File "/home/vemek/.pyenv/versions/3.5.3/envs/hass/lib/python3.5/site-packages/homeassistant/core.py", line 1031, in _event_to_service_call
    yield from service_handler.func(service_call)
  File "/home/vemek/.pyenv/versions/3.5.3/envs/hass/lib/python3.5/site-packages/homeassistant/components/configurator.py", line 224, in async_handle_service_call
    call.data.get(ATTR_FIELDS, {}))
  File "/home/vemek/.pyenv/versions/3.5.3/lib/python3.5/asyncio/futures.py", line 380, in __iter__
    yield self  # This tells Task to wait for completion.
  File "/home/vemek/.pyenv/versions/3.5.3/lib/python3.5/asyncio/tasks.py", line 304, in _wakeup
    future.result()
  File "/home/vemek/.pyenv/versions/3.5.3/lib/python3.5/asyncio/futures.py", line 293, in result
    raise self._exception
  File "/home/vemek/.pyenv/versions/3.5.3/lib/python3.5/asyncio/tasks.py", line 239, in _step
    result = coro.send(None)
  File "/home/vemek/.pyenv/versions/3.5.3/envs/hass/lib/python3.5/site-packages/homeassistant/components/tradfri.py", line 70, in configuration_callback
    key = yield from api_factory.generate_psk(security_code)
  File "/home/vemek/.pyenv/versions/3.5.3/envs/hass/lib/python3.5/site-packages/pytradfri/api/aiocoap_api.py", line 193, in generate_psk
    PatchedDTLSSecurityStore.KEY = security_key.encode('utf-8')
AttributeError: 'NoneType' object has no attribute 'encode'

It's worth noting that example_async works as expected and detects the hub and can read the state of the lights. I'm not sure why this is not working under Home Assistant, but I'm more than happy to help debug if you could kindly point me in the right direction? I'm going to take a look at the Home Assistant component source and see if I can create minimal reproduction steps using just pytradfri. Thanks for all your work on this!

Forgot to change 255 to 254 in color.py?

Where are you using pytradfri (eg stand-alone, Home Assistant etc)

Home Assistant, 0.57.2

Version of pytradfri

The one included in the latest Home Assistant

Expected behaviour

No errors in log

Actual behaviour

2017-11-07 19:58:53 ERROR (MainThread) [homeassistant.core] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/asyncio/tasks.py", line 179, in _step
    result = coro.send(None)
  File "/srv/homeassistant/homeassistant_venv/lib/python3.6/site-packages/pytradfri/api/aiocoap_api.py", line 149, in request
    result = yield from self._execute(api_commands)
  File "/srv/homeassistant/homeassistant_venv/lib/python3.6/site-packages/pytradfri/api/aiocoap_api.py", line 107, in _execute
    yield from self._observe(api_command)
  File "/srv/homeassistant/homeassistant_venv/lib/python3.6/site-packages/pytradfri/api/aiocoap_api.py", line 169, in _observe
    api_command.result = _process_output(r)
  File "/srv/homeassistant/homeassistant_venv/lib/python3.6/site-packages/pytradfri/command.py", line 71, in result
    self._result = self._process_result(value)
  File "/srv/homeassistant/homeassistant_venv/lib/python3.6/site-packages/pytradfri/resource.py", line 46, in observe_callback
    callback(self)
  File "/srv/homeassistant/homeassistant_venv/lib/python3.6/site-packages/homeassistant/components/light/tradfri.py", line 324, in _observe_update
    self._light_data.hex_color_inferred
  File "/srv/homeassistant/homeassistant_venv/lib/python3.6/site-packages/pytradfri/device.py", line 281, in hex_color_inferred
    *xy_brightness_to_rgb(scale(x), scale(y), self.dimmer)
  File "/srv/homeassistant/homeassistant_venv/lib/python3.6/site-packages/pytradfri/color.py", line 142, in xy_brightness_to_rgb
    brightness = ibrightness / 255.
TypeError: unsupported operand type(s) for /: 'NoneType' and 'float'
2017-11-07 19:58:53 WARNING (MainThread) [root] Observation deleted without explicit cancellation
2017-11-07 19:59:00 WARNING (MainThread) [root] Observation deleted without explicit cancellation

I assume that you forgot to change the 255 to 254 (the new max brightness value in Ikea things if I understand it right) in the color.py.

DockerfileRPI does not work on Stretch / Raspberry PI Zero W

It seems that the base image of DockerfileRPI does not work on Raspbian Stretch:

pi@raspberrypi:~/pytradfri $ docker run armhf/debian:latest /bin/sh
i@raspberrypi:~/pytradfri $ docker ps -a | head -n2
CONTAINER ID        IMAGE                 COMMAND                  CREATED             STATUS                          PORTS               NAMES
bca5eafb5e7e        armhf/debian:latest   "/bin/sh"                44 seconds ago      Exited (139) 38 seconds ago                         pensive_brown
pi@raspberrypi:~/pytradfri $ cat /etc/debian_version 
9.1

unable to get a put request through coap-client DTLS (get works fine)

i installed libcoap as instructed (as of pytradfri 1.0) and my tradfri bulbs are displayed ok (in the HA dev version) and even status changes are displayed (with a short delay). switching in HA however fails. in the HA logs a client error (4.00) appeared in pytradfri version < 1.0. now there are no more errors in the log, but switching still doesn’t work.

looking into the matter through coap-client shows this:

echo '{ "3311" : [{ "5851" : 20 }] }' | coap-client -u "Client_identity" -k "xxx" -v 10 -m put "coaps://192.168.1.68:5684/15001/65539" -f -

Apr 18 20:12:48 DEBG created DTLS endpoint 0.0.0.0:57153
v:1 t:CON c:PUT i:07c5 {} [ ]
Apr 18 20:12:48 DEBG sending CoAP request:
v:1 t:CON c:PUT i:07c5 {} [ Uri-Path:15001, Uri-Path:65539 ]
Apr 18 20:12:48 DEBG *** new session 0x7fb09ae00610
Apr 18 20:12:48 DEBG call dtls_write
Apr 18 20:12:48 DEBG *** add 0x7fb09af00130 to sendqueue of session 0x7fb09ae00610
Apr 18 20:12:48 DEBG timeout is set to 90 seconds
Apr 18 20:12:48 DEBG received 60 bytes on fd 3
Apr 18 20:12:48 DEBG received 63 bytes on fd 3
Apr 18 20:12:48 DEBG received 25 bytes on fd 3
Apr 18 20:12:48 DEBG received 14 bytes on fd 3
Apr 18 20:12:48 DEBG received 53 bytes on fd 3
Apr 18 20:12:48 DEBG *** EVENT: 0x01de
Apr 18 20:12:48 DEBG received 33 bytes on fd 3
Apr 18 20:12:48 INFO ** application data:
v:1 t:ACK c:4.00 i:07c5 {} [ ]
Apr 18 20:12:48 DEBG *** removed transaction 291
Apr 18 20:12:48 DEBG ** process incoming 4.00 response:
v:1 t:ACK c:4.00 i:07c5 {} [ ]
4.00
Apr 18 20:12:48 DEBG *** removed session 0x7fb09ae00610

i tested this on mac os 10.12 (sierra) and 10.11 (el capitan). seems to be an SSL problem (again) occurring only on mac os. however, @balloob, you also use a mac — and your coap-client seems to work fine. any additional SSL stuff or libs you installed?

Is running on Windows possible?

I tried to have a go by installing Python 3.6.3, running 'pip install pytradfri' and then following 'install-aiocoap.sh', and trying to run pytradfri I'm met with:

C:\Users\JohnEdwa>python -i -m pytradfri 192.168.10.55 INHqt7BjpXGsku4d
Traceback (most recent call last):
  File "C:\Users\JohnEdwa\AppData\Local\Programs\Python\Python36\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "C:\Users\JohnEdwa\AppData\Local\Programs\Python\Python36\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\Users\JohnEdwa\AppData\Local\Programs\Python\Python36\lib\site-packages\pytradfri\__main__.py", line 7, in <module>
    from .api.libcoap_api import api_factory
ImportError: cannot import name 'api_factory'

If I've understood correctly, I'd still need either libcoap or tinydtls, so the answer to my question would be no?

pytradfri 4.0.0 not working

Where are you using pytradfri (eg stand-alone, Home Assistant etc)

standalone

Version of pytradfri

4.0.0

Expected behaviour

working again with gateway firmware 1.2.42

Actual behaviour

running this:

#!/usr/bin/env python3

import sys
from pytradfri import Gateway
from pytradfri.api.libcoap_api import APIFactory

api_factory = APIFactory(sys.argv[1])
with open('/mnt/rw/ikea/gateway_psk.txt', 'a+') as file:
    file.seek(0)
    psk = file.read()
    if psk:
        api_factory.psk = psk.strip()
    else:
        psk = api_factory.generate_psk(sys.argv[2])
        print('Generated PSK: ', psk)
        file.write(psk)
api = api_factory.request

root@raspberrypi:~# /opt/testing 192.168.21.26 <devicekey>

gives:

Traceback (most recent call last):
  File "/opt/testing", line 13, in <module>
    psk = api_factory.generate_psk(sys.argv[2])
  File "/usr/local/lib/python3.5/dist-packages/pytradfri/api/libcoap_api.py", line 156, in generate_psk
    self._psk = self.request(command)
  File "/usr/local/lib/python3.5/dist-packages/pytradfri/api/libcoap_api.py", line 93, in request
    return self._execute(api_commands)
  File "/usr/local/lib/python3.5/dist-packages/pytradfri/api/libcoap_api.py", line 87, in _execute
    api_command.result = _process_output(return_value, parse_json)
  File "/usr/local/lib/python3.5/dist-packages/pytradfri/command.py", line 71, in result
    self._result = self._process_result(value)
  File "/usr/local/lib/python3.5/dist-packages/pytradfri/gateway.py", line 28, in process_result
    return result[ATTR_PSK]
TypeError: 'NoneType' object is not subscriptable

???

tinydtls won't install on macOS without modifications

When trying to install tinydtls from git clone --depth 1 https://git.fslab.de/jkonra2m/tinydtls.git on macOS 10.12 it will fail with:

../mc-helper.c:82:35: error: use of undeclared identifier 'IPV6_ADD_MEMBERSHIP' if(setsockopt(fd, IPPROTO_IPV6, IPV6_ADD_MEMBERSHIP, &mreq, sizeof(mreq))){

It seems IPV6_ADD_MEMBERSHIP is deprecated and IPV6_JOIN_GROUP should be used instead (I am way out of my depth here and might be very wrong).

Replacing the three mentions of IPV6_ADD_MEMBERSHIP with IPV6_JOIN_GROUP in mc-helper.c makes it possible to install tinydtls on macOS and tradfri seems to work fine in Home Assistant 0.55.0.

(I also did mv configure.in configure.ac to get rid of a warning from autoconf.)

'module' object has no attribute 'DEVNULL'

Hi,

I'm trying to run pytradfri on my raspberry pi.

I've installed everything and try to start it with:
python3 -i -m pytradfri 192.168.192.107 n65inIz...

But then, I got the following error message:
Traceback (most recent call last): File "/usr/lib/python3.2/runpy.py", line 161, in _run_module_as_main "__main__", fname, loader, pkg_name) File "/usr/lib/python3.2/runpy.py", line 74, in _run_code exec(code, run_globals) File "/home/pi/tradfri/pytradfri/pytradfri/__main__.py", line 19, in <module> api = api_factory(sys.argv[1], sys.argv[2]) File "pytradfri/api/libcoap_api.py", line 131, in api_factory request(Command('get', ['status'])) File "pytradfri/api/libcoap_api.py", line 78, in request return _execute(api_commands[0]) File "pytradfri/api/libcoap_api.py", line 49, in _execute 'stderr': subprocess.DEVNULL, AttributeError: 'module' object has no attribute 'DEVNULL'

What's the error and how can I fix it?

Best wishes

Tobi

FileNotFoundError: [Errno 2] No such file or directory: 'coap-client'

Description: Using pytradfri from my homeassistant instance running in a python virtual environment on Ubuntu OS

base OS: Ubuntu 17.04 zesty
Hass version: 0.48.0
Python version: Python 3.5.3

I've followed the guide https://home-assistant.io/components/tradfri/ several times. Each time I've retried it ive uninstalled libtool, autconf and coap-client, with --purge, then executed a apt-get update and dist-upgrade command followed by a reboot.

I can execute the command "coap-client" from both my regular user outside the virtal environment, and also when inside the virtual environment as my user "homeassistant" which runs hass.

This is the error i receive as soon as i use the "configurator" in hass (entering my security code) or adding a tradfri.conf in my configuration folder for hass.


2017-07-03 12:25:31 ERROR (MainThread) [homeassistant.core] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/lib/python3.5/asyncio/tasks.py", line 239, in _step
    result = coro.send(None)
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/tradfri.py", line 57, in configuration_callback
    DEFAULT_ALLOW_TRADFRI_GROUPS)
  File "/usr/lib/python3.5/asyncio/coroutines.py", line 210, in coro
    res = func(*args, **kw)
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/tradfri.py", line 116, in _setup_gateway
    api = retry_timeout(cli_api_factory(host, key))
  File "/home/homeassistant/.homeassistant/deps/pytradfri/coap_cli.py", line 104, in api_factory
    request('get', ['status'])
  File "/home/homeassistant/.homeassistant/deps/pytradfri/coap_cli.py", line 56, in request
    return_value = subprocess.check_output(command, **kwargs)
  File "/usr/lib/python3.5/subprocess.py", line 316, in check_output
    **kwargs).stdout
  File "/usr/lib/python3.5/subprocess.py", line 383, in run
    with Popen(*popenargs, **kwargs) as process:
  File "/usr/lib/python3.5/subprocess.py", line 676, in __init__
    restore_signals, start_new_session)
  File "/usr/lib/python3.5/subprocess.py", line 1282, in _execute_child
    raise child_exception_type(errno_num, err_msg)
FileNotFoundError: [Errno 2] No such file or directory: 'coap-client'
(homeassistant) homeassistant@HomeAssistant:/usr/local/bin$ which coap-client
/usr/local/bin/coap-client

Running coap-client insite virtual environment

(homeassistant) homeassistant@HomeAssistant:/usr/local/bin$ coap-client
coap-client v4.1.2 -- a small CoAP implementation
(c) 2010-2015 Olaf Bergmann <[email protected]>

usage: coap-client [-A type...] [-t type] [-b [num,]size] [-B seconds] [-e text]
                [-m method] [-N] [-o file] [-P addr[:port]] [-p port]
                [-s duration] [-O num,text] [-T string] [-v num] [-a addr]

tried giving coap-client full access

(homeassistant) homeassistant@HomeAssistant:/usr/local/bin$ ls -color
total 640
-rwxr-xr-x 1 root    212 Jun 28 21:04 virtualenv
-rwxr-xr-x 1 root 208280 Jul  3 11:28 coap-server
-rwxr-xr-x 1 root 215936 Jul  3 11:28 coap-rd
-rwxrwxrwx 1 root 222464 Jul  3 12:23 coap-client

For troubleshooting I've also installed a completely fresh install of homeassistant on ubuntu 16.04, same errors.
I also have a docker version of hass running, inside that one everything works, but I did not configure the special coaplib for that one, it was already done in the image I guess.

Let me know if you need more information!

About Gateway 1.3.14

So Ikea recently updated their Gateway software with the following changelog:

New features and changes in Gateway: 1.3.14:
Stability improvements in application connectivity to gateway.
Resolution of DHCP and COAP issues.
Connectivity improvements in iOS app.

I don't think it will change anything for Pytradfri, but it's a good idea to think about it a bit. Anyone any thoughts or issues?

Add RGB support

(same text as in general Tradfri discussion)

Apparently E27 RGB bulbs are now available, today I bought one in an IKEA in Germany.
I didn't find anything online, so these gotta be released brand-new.
Here are some photos and screenshots: http://imgur.com/a/yC5VW
The Android App is able to display the colors that the bulb shows, but it's not able to set them. Setting RGB color only works at the moment by repeatedly pressing the < and > buttons on the physical Tradfri remote.
Will try to do further investigation soon.

EDIT:

  • Cycleable colors are: The three normal whites (cold, normal, warm), candlelight, warm amber, dark peach, saturated pink, light purple, light blue. (These color names are shown when you click on New Mood for a category which the RGB bulb is in.)

Script for tinyDTLS missing

I'm trying to replace libcoap's coap-client in my python code due to libcoap's strange behaviour/implementation regarding resource observation, and I found your code which pretty much looks like a good replacement for the base of my whole Tradfri monitoring/control system.
But, since we need DTLS to communicate with the Tradfri gateway, we need to also build aiocoap with tinyDTLS, and your instructions for that point to a script that is non-existant...https://github.com/ggravlingen/pytradfri/blob/master/script/install-aiocoap.sh

Can you recreate it or, if it is not needed anymore, update the installation/compilation docs and README.md to give the valid and current instructions for preparing aiocoap for the usage with your code?

Thanks.

Check for gateway version

Where are you using pytradfri (eg stand-alone, Home Assistant etc)

Stand-alone in a network that won't let the gateway access the Internet

Version of pytradfri

4.0.5

Expected behaviour

python3 example_async.py GW-A0CC2BF5AC6D.amsuess.com DevicePrintedKey should show something meaningful

Actual behaviour

Traceback (most recent call last):
  File "example_async.py", line 115, in <module>
    asyncio.get_event_loop().run_until_complete(run())
  File "/usr/lib/python3.6/asyncio/base_events.py", line 467, in run_until_complete
    return future.result()
  File "example_async.py", line 45, in run
    psk = yield from api_factory.generate_psk(sys.argv[2])
  File "/tmp/pytradfri/pytradfri/api/aiocoap_api.py", line 198, in generate_psk
    self._psk = yield from self.request(command)
  File "/tmp/pytradfri/pytradfri/api/aiocoap_api.py", line 154, in request
    result = yield from self._execute(api_commands)
  File "/tmp/pytradfri/pytradfri/api/aiocoap_api.py", line 146, in _execute
    api_command.result = _process_output(res, parse_json)
  File "/tmp/pytradfri/pytradfri/command.py", line 71, in result
    self._result = self._process_result(value)
  File "/tmp/pytradfri/pytradfri/gateway.py", line 28, in process_result
    return result[ATTR_PSK]
TypeError: 'NoneType' object is not subscriptable

I suppose this is because I haven't let the gateway update itself since I bought it. The code it fails in indicates that the issue is with creating a per-client key and that's not supported.

To help adding a gate before trying to add an own key (and if it's only "Sorry, too old, please upgrade your GW" instead of an exception), here's my gateway's key data:

.well-known/core:

<//15001>;ct=0;obs,<//15001/reset>;ct=0,<//status>;ct=0;obs,<//15005>;ct=0;obs,<//15004>;ct=0;obs,<//15004/add>;ct=0,<//15004/remove>;ct=0,<//15006>;ct=0;obs,<//15011/15012>;ct=0;obs,<//15011/9034>;ct=0,<//15011/9030>;ct=0,<//15011/9031>;ct=0,<//15011/9063>;ct=0,<//15011/9033>;ct=0,<//15010>;ct=0;obs

`/15011/15012':

{"9029":"1.0.0008","9061":0,"9060":"1970-01-01T01:27:03.017176Z","9023":"0.debian.pool.ntp.org","9059":5223,"9062":0,"9054":0,"9055":0,"9066":0,"9069":0,"9071":0}

After letting the device upgrade, things ran through as expected (to the point where lights[0] fails because I haven't assigned any lights yet).

How to get a serial number/unique identifier of a bulb?

Where are you using pytradfri (eg stand-alone, Home Assistant etc)

standalone

Version of pytradfri

Tried 5.0.0 and 5.2.0

Expected behaviour

Finding a serial number or another unique identifier at device.device_info.serial.

Actual behaviour

The serial field is empty. The raw field contains: {'0': 'IKEA of Sweden', '1': 'TRADFRI bulb E27 CWS opal 600lm', '2': '', '3': '1.3.002', '6': 1} and according to the definition of DeviceInfo: ATTR_SERIAL = '2', which is indeed empty.

The gateway changes the order of bulbs on every reboot, so I can't rely on the order in which pytradfri reports them. I found issue #99, but that was closed by the OP without any resolution, and it seems that he was asking for a different API, but knew how to get an ID.

Is the serial number located somewhere else, or is it an issue with either pytradfri or the gateway itself?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.