@@ -52,11 +52,13 @@ def set_light(light, data):
52
52
53
53
if "5712" not in payload :
54
54
payload ["5712" ] = 4 #If no transition add one, might also add check to prevent large transitiontimes
55
- check_output ("./coap-client-linux -B 2 -m put -u \" " + light .protocol_cfg ["identity" ] + "\" -k \" " + light .protocol_cfg ["psk" ] + "\" -e '{ \" 3311\" : [" + json .dumps (payload ) + "] }' \" " + url + "\" " , shell = True )
55
+ cmd = ["./coap-client-linux" , "-B" , "2" , "-m" , "put" , "-u" , light .protocol_cfg ["identity" ], "-k" , light .protocol_cfg ["psk" ], "-e" , "{ \" 3311\" : [" + json .dumps (payload ) + "] }" , url ]
56
+ check_output (cmd )
56
57
57
58
def get_light_state (light ):
58
59
state = {}
59
- light_data = json .loads (check_output ("./coap-client-linux -B 5 -m get -u \" " + light .protocol_cfg ["identity" ] + "\" -k \" " + light .protocol_cfg ["psk" ] + "\" \" coaps://" + light .protocol_cfg ["ip" ] + ":5684/15001/" + str (light .protocol_cfg ["id" ]) + "\" " , shell = True ).decode ('utf-8' ).rstrip ('\n ' ).split ("\n " )[- 1 ])
60
+ cmd = ["./coap-client-linux" , "-B" , "5" , "-m" , "get" , "-u" , light .protocol_cfg ["identity" ], "-k" , light .protocol_cfg ["psk" ], "coaps://" + light .protocol_cfg ["ip" ] + ":5684/15001/" + str (light .protocol_cfg ["id" ])]
61
+ light_data = json .loads (check_output (cmd ).decode ('utf-8' ).rstrip ('\n ' ).split ("\n " )[- 1 ])
60
62
state ["on" ] = bool (light_data ["3311" ][0 ]["5850" ])
61
63
state ["bri" ] = light_data ["3311" ][0 ]["5851" ]
62
64
if "5706" in light_data ["3311" ][0 ]:
@@ -75,10 +77,12 @@ def discover(detectedLights, tradfriConfig):
75
77
if "psk" in tradfriConfig :
76
78
logging .debug ("tradfri: <discover> invoked!" )
77
79
try :
78
- tradriDevices = json .loads (check_output ("./coap-client-linux -B 5 -m get -u \" " + tradfriConfig ["identity" ] + "\" -k \" " + tradfriConfig ["psk" ] + "\" \" coaps://" + tradfriConfig ["tradfriGwIp" ] + ":5684/15001\" " , shell = True ).decode ('utf-8' ).rstrip ('\n ' ).split ("\n " )[- 1 ])
80
+ cmd = ["./coap-client-linux" , "-B" , "5" , "-m" , "get" , "-u" , tradfriConfig ["identity" ], "-k" , tradfriConfig ["psk" ], "coaps://" + tradfriConfig ["tradfriGwIp" ] + ":5684/15001" ]
81
+ tradriDevices = json .loads (check_output (cmd ).decode ('utf-8' ).rstrip ('\n ' ).split ("\n " )[- 1 ])
79
82
logging .debug (tradriDevices )
80
83
for device in tradriDevices :
81
- deviceParameters = json .loads (check_output ("./coap-client-linux -B 5 -m get -u \" " + tradfriConfig ["identity" ] + "\" -k \" " + tradfriConfig ["psk" ] + "\" \" coaps://" + tradfriConfig ["tradfriGwIp" ] + ":5684/15001/" + str (device ) + "\" " , shell = True ).decode ('utf-8' ).rstrip ('\n ' ).split ("\n " )[- 1 ])
84
+ cmd = ["./coap-client-linux" , "-B" , "5" , "-m" , "get" , "-u" , tradfriConfig ["identity" ], "-k" , tradfriConfig ["psk" ], "coaps://" + tradfriConfig ["tradfriGwIp" ] + ":5684/15001/" + str (device )]
85
+ deviceParameters = json .loads (check_output (cmd ).decode ('utf-8' ).rstrip ('\n ' ).split ("\n " )[- 1 ])
82
86
if "3311" in deviceParameters :
83
87
logging .debug ("found tradfi light " + deviceParameters ["9001" ])
84
88
detectedLights .append ({"protocol" : "tradfri" , "name" : deviceParameters ["9001" ], "modelid" : "LCT015" , "protocol_cfg" : {"ip" : tradfriConfig ["tradfriGwIp" ], "id" : device , "identity" : tradfriConfig ["identity" ], "psk" : tradfriConfig ["psk" ]}})
0 commit comments