Skip to content

Commit 2ffe1d4

Browse files
authored
Merge pull request #9 from strfl89/testing
Version 2.3
2 parents 61e7df7 + 824105a commit 2ffe1d4

File tree

7 files changed

+100
-9
lines changed

7 files changed

+100
-9
lines changed

.DS_Store

0 Bytes
Binary file not shown.

Release-Notes.md

+13
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,17 @@
11
# phpTradfri - Version History
2+
## Version 2.3 - 22nd Sep 2019
3+
* devices.php
4+
+ add Last Seen Information for Lamps and Remote Controls
5+
+ add statuscontroloutlet()
6+
+ add functions for dimming lamps
7+
+ extend poweron() and poweroff() for control outlets
8+
+ extend getPowerStatus() for control outlets
9+
* gateway.php
10+
* bugfixing ntp in status
11+
* general.php
12+
+ adding return for action()
13+
* groups.php
14+
+ add functions for dimming lamps
215
## Version 2.2 - 16th Sep 2019
316
+ getDimmer() and setDimmer() added to devices.php
417
## Version 2.1.1 - 14th Sep 2019

defines.php

+1
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,6 @@
2727
define('GATEWAY_GOOGLE_STATUS', 9105);
2828
define('GATEWAY_TIME_UNIX', 9059);
2929
define('GATEWAY_SETUP_TIME', 9069);
30+
define('LAST_SEEN', 9020);
3031

3132
?>

devices.php

+62-7
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,38 @@ function getPowerStatus($Id){
4949

5050
$psid = $this->getDetails("15001/$Id");
5151

52-
return $psid['3311']['0'][ONOFF];
52+
switch ($psid[TYPE]) {
53+
case TYPE_LIGHT:
54+
return $psid['3311']['0'][ONOFF];
55+
break;
56+
57+
case TYPE_CONTROL_OUTLET:
58+
return $psid['3312']['0'][ONOFF];
59+
break;
60+
61+
default:
62+
return NULL;
63+
break;
64+
}
5365

5466
}
5567

5668
function poweroff($path){
5769

58-
if($this->getTypeId($path) == TYPE_LIGHT){
59-
$payload = '{ "3311": [{ "5850": 0 }] }';
70+
switch($this->getTypeId($path)){
71+
case TYPE_LIGHT:
72+
$payload = '{ "3311": [{ "5850": 0 }] }';
73+
break;
74+
75+
case TYPE_CONTROL_OUTLET:
76+
$payload = '{ "3312": [{ "5850": 0 }] }';
77+
break;
78+
79+
default:
80+
$payload = NULL;
81+
}
82+
83+
if (!is_null($payload)){
6084
$this->action("put", $payload, "15001/$path");
6185

6286
if($this->getPowerStatus($path) == 0)
@@ -72,8 +96,21 @@ function poweroff($path){
7296

7397
function poweron($path){
7498

75-
if($this->getTypeId($path) == TYPE_LIGHT){
76-
$payload = '{ "3311": [{ "5850": 1 }] }';
99+
switch($this->getTypeId($path)){
100+
case TYPE_LIGHT:
101+
$payload = '{ "3311": [{ "5850": 1 }] }';
102+
break;
103+
104+
case TYPE_CONTROL_OUTLET:
105+
$payload = '{ "3312": [{ "5850": 1 }] }';
106+
break;
107+
108+
default:
109+
$payload = NULL;
110+
}
111+
112+
if (!is_null($payload)){
113+
77114
$this->action("put", $payload, "15001/$path");
78115

79116
if($this->getPowerStatus($path) == 1)
@@ -108,13 +145,31 @@ function setDimmer($path, $dimmer, $transition = NULL){
108145

109146
}
110147

148+
function statuscontroloutlet(){
149+
150+
$Ids = $this->getIds();
151+
sort($Ids, SORT_NUMERIC);
152+
153+
foreach($Ids as $device){
154+
$details = $this->getDetails("15001/$device");
155+
if($details[TYPE] == TYPE_CONTROL_OUTLET){
156+
$output[] = array("id" => $device,"name" => $details[NAME], "type" => $details['3']['1'], "firmware" => $details['3']['3'], "lastseen" => date('H:i:s d.m.Y', $details[LAST_SEEN]), "lastseenunix" => $details[LAST_SEEN], "power" => $details['3312']['0'][ONOFF]);
157+
}
158+
}
159+
160+
return $output;
161+
162+
}
163+
111164
function statusremotecontrol(){
112165

113166
$Ids = $this->getIds();
167+
sort($Ids, SORT_NUMERIC);
168+
114169
foreach($Ids as $device){
115170
$details = $this->getDetails("15001/$device");
116171
if($details[TYPE] == TYPE_REMOTE_CONTROL || $details[TYPE] == TYPE_MOTION_SENSOR){
117-
$output[] = array("id" => $device,"name" => $details[NAME], "type" => $details['3']['1'], "battery" => $details['3']['9'], "firmware" => $details['3']['3']);
172+
$output[] = array("id" => $device,"name" => $details[NAME], "type" => $details['3']['1'], "battery" => $details['3']['9'], "firmware" => $details['3']['3'], "lastseen" => date('H:i:s d.m.Y', $details[LAST_SEEN]), "lastseenunix" => $details[LAST_SEEN]);
118173
}
119174
}
120175

@@ -140,7 +195,7 @@ function statuslamps(){
140195
//Set Dimmer to the INT Value in %
141196
$details[LIGHT]['0'][DIMMER] = round($details[LIGHT]['0'][DIMMER] * 100 / 255);
142197

143-
$output[] = array("id" => $device,"name" => $details[NAME], "type" => $details['3']['1'], "power" => $details[LIGHT]['0'][ONOFF], "dimmer" => $details[LIGHT]['0'][DIMMER], "colorhex" => $colorhex, "colorx" => $colorx, "colory" => $colory, "colortemp" => $colortemp, "transition" => $transition);
198+
$output[] = array("id" => $device,"name" => $details[NAME], "type" => $details['3']['1'], "power" => $details[LIGHT]['0'][ONOFF], "dimmer" => $details[LIGHT]['0'][DIMMER], "colorhex" => $colorhex, "colorx" => $colorx, "colory" => $colory, "colortemp" => $colortemp, "transition" => $transition, "firmware" => $details['3']['3'], "lastseen" => date('H:i:s d.m.Y', $details[LAST_SEEN]), "lastseenunix" => $details[LAST_SEEN]);
144199

145200
//Clean up
146201
unset($colorhex, $colorx, $colory, $colortemp, $transition);

gateway.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ function statusgateway(){
2020

2121
$details = $this->getDetails(GATEWAY."/15012");
2222

23-
$output = array('setup' => $details[GATEWAY_SETUP_TIME], 'ntp' => $details['GATEWAY_NTP'], 'time' => $details[GATEWAY_TIME_UNIX], 'firmware' => $details[GATEWAY_FIRMWARE], 'alexa' => $details[GATEWAY_ALEXA_STATUS], 'google' => $details[GATEWAY_GOOGLE_STATUS]);
23+
$output = array('setup' => $details[GATEWAY_SETUP_TIME], 'ntp' => $details[GATEWAY_NTP], 'time' => $details[GATEWAY_TIME_UNIX], 'firmware' => $details[GATEWAY_FIRMWARE], 'alexa' => $details[GATEWAY_ALEXA_STATUS], 'google' => $details[GATEWAY_GOOGLE_STATUS]);
2424

2525
return $output;
2626
}

general.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ function action($method, $payload, $path){
4848
else
4949
$cmd = "coap-client -m {$method} -u '{$this->gateway['user']}' -k '{$this->gateway['secretkey']}' 'coaps://{$this->gateway['ip']}:5684/{$path}'";
5050

51-
exec($cmd);
51+
return exec($cmd);
5252

5353
}
5454

groups.php

+22
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@
55
class tradfrigroups extends tradfri
66
{
77

8+
function getDimmer($Id){
9+
10+
$dimid = $this->getDetails("15004/$Id");
11+
12+
return $dimid[DIMMER];
13+
14+
}
15+
816
function getIds(){
917

1018
return explode(",", trim(str_replace(['[',']'], "" ,strstr($this->query("15004"), '[13'))));
@@ -63,6 +71,20 @@ function poweron($path){
6371

6472
}
6573

74+
function setDimmer($path, $dimmer){
75+
76+
$dim = round(254 * (int)str_replace("%", "", trim($dimmer)) / 100, 0);
77+
78+
$payload = '{ "'.DIMMER.'": '.$dim.' }';
79+
$this->action("put", $payload, "15004/$path");
80+
81+
if($this->getDimmer($path) == $dim)
82+
return $this->getName("15004/$path")." wurde auf {$dimmer} gedimmt.";
83+
else
84+
return $this->getName("15004/$path")." konnte nicht auf {$dimmer} gedimmt werden.";
85+
86+
}
87+
6688
} // End of class tradfrigroups
6789

6890
?>

0 commit comments

Comments
 (0)