forked from MiniMeOSc/phpTradfri
-
Notifications
You must be signed in to change notification settings - Fork 1
/
groups.php
98 lines (59 loc) · 1.92 KB
/
groups.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
<?php
require_once('general.php');
class tradfrigroups extends tradfri
{
function getDimmer($Id){
$dimid = $this->getDetails("15004/$Id");
return $dimid[DIMMER];
}
function getIds(){
return explode(",", trim(str_replace(['[',']'], "" ,strstr($this->query("15004"), '[13'))));
}
function getIdbyName($name){
$Ids = $this->getIds() ?? [];
foreach($Ids as $Id){
$Idname = strtolower(trim($this->getName("15004/$Id")));
$Idname = str_replace(['ä','ö','ü','ß'], ['ae','oe','ue','ss'], $Idname);
if(strcasecmp(trim($name), $Idname) == 0)
$output = $Id;
}
if(isset($output))
return $output;
else
return NULL;
}
function getMembers($Id){
$members = $this->getDetails("15004/$Id");
return $members['9018']['15002']['9003'];
}
function getPowerStatus($Id){
$psid = $this->getDetails("15004/$Id");
return $psid[ONOFF];
}
function poweroff($path){
$payload = '{ "5850": 0 }';
$this->action("put", $payload, "15004/$path");
if($this->getPowerStatus($path) == 0)
return $this->getName("15004/$path")." wurde ausgeschaltet";
else
return $this->getName("15004/$path")." konnte nicht ausgeschaltet werden";
}
function poweron($path){
$payload = '{ "5850": 1 }';
$this->action("put", $payload, "15004/$path");
if($this->getPowerStatus($path) == 1)
return $this->getName("15004/$path")." wurde eingeschaltet";
else
return $this->getName("15004/$path")." konnte nicht eingeschaltet werden";
}
function setDimmer($path, $dimmer){
$dim = round(254 * (int)str_replace("%", "", trim($dimmer)) / 100, 0);
$payload = '{ "'.DIMMER.'": '.$dim.' }';
$this->action("put", $payload, "15004/$path");
//if($this->getDimmer($path) == $dim)
return $this->getName("15004/$path")." wurde auf {$dimmer} gedimmt.";
/*else
return $this->getName("15004/$path")." konnte nicht auf {$dimmer} gedimmt werden.";*/
}
} // End of class tradfrigroups
?>