Skip to content

Commit efb0f5b

Browse files
committed
Version 2.2
Add Dimmer Functions for Devices
1 parent 564bf23 commit efb0f5b

3 files changed

Lines changed: 43 additions & 14 deletions

File tree

Release-Notes.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
# phpTradfri - Version History
2-
## Version 2.1.1
2+
## Version 2.2 - 16th Sep 2019
3+
+ getDimmer() and setDimmer() added to devices.php
4+
## Version 2.1.1 - 14th Sep 2019
35
* Fix missing return in Function statusgateway()
4-
## Version 2.1
6+
## Version 2.1 - 14th Sep 2019
57
* Add Subclass for Trådfri Gateway
68
* defines.php
79
+ defines for gateway
@@ -17,9 +19,9 @@
1719
* general.php
1820
* Move from Constants to Parameters for Gateway Config
1921
* to initialize new object parameters User, Secret and Gateway IP must enterd. Example:
20-
```
21-
$groups = new tradfrigroups("<user>", "<secret>", "<ip>");
22-
```
22+
```
23+
$groups = new tradfrigroups("<user>", "<secret>", "<ip>");
24+
```
2325
* cleaning up file
2426
* Update ReadMe File
2527
## Version 1.1 - 09th Sep 2019

devices.php

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@
55
class tradfridevices extends tradfri
66
{
77

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

1018
return explode(",", trim(str_replace(['[',']'], "" ,strstr($this->query("15001"), '[65'))));
@@ -58,7 +66,7 @@ function poweroff($path){
5866
}
5967

6068
else
61-
return "Gerät kann nicht ausgeschalet werden, da es keine Lampe ist";
69+
return $this->getName("15001/$device")." konnte nicht ausgeschaltet werden, da es keine Lampe ist";
6270

6371
}
6472

@@ -75,7 +83,28 @@ function poweron($path){
7583
}
7684

7785
else
78-
return "Gerät konnte nicht eingeschaltet werden, da es keine Lampe ist";
86+
return $this->getName("15001/$device")." konnte nicht eingeschaltet werden, da es keine Lampe ist";
87+
88+
}
89+
90+
function setDimmer($path, $dimmer, $transition = NULL){
91+
92+
if($this->getTypeId($path) == TYPE_LIGHT){
93+
94+
$dim = round(254 * (int)str_replace("%", "", trim($dimmer)) / 100, 0);
95+
96+
$payload = is_null($transition) ? '{ "3311": [{ "5851" : '.$dim.' }] }" : "{ "3311": [{ "5851": '.$dim.', "5712": '.$transition.' }] }';
97+
$this->action("put", $payload, "15001/$path");
98+
99+
if($this->getDimmer($path) == $dim)
100+
return $this->getName("15001/$path")." wurde auf {$dimmer} gedimmt";
101+
else
102+
return $this->getName("15001/$path")." konnte nicht auf {$dimmer} gedimmt werden";
103+
104+
}
105+
106+
else
107+
return $this->getName("15001/$device")." konnte nicht gedimmt werden, da es keine Lampe ist";
79108

80109
}
81110

general.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,15 @@
22

33
require_once('defines.php');
44

5-
class tradfri
6-
{
5+
class tradfri {
76

87
private $gateway;
98

109
function __construct($user, $secret, $gwip){
1110

12-
$this->gateway['user'] = $user;
13-
$this->gateway['secretkey'] = $secret;
14-
$this->gateway['ip'] = $gwip;
11+
$this->gateway['user'] = $user;
12+
$this->gateway['secretkey'] = $secret;
13+
$this->gateway['ip'] = $gwip;
1514

1615
}
1716

@@ -67,7 +66,6 @@ function getName($path){
6766

6867
}
6968

70-
}
71-
//End of Class tradfri
69+
} //End of Class tradfri
7270

7371
?>

0 commit comments

Comments
 (0)