From efb0f5ba5355254e33d0ce735f5118128babd1a3 Mon Sep 17 00:00:00 2001 From: Florian Strunk Date: Mon, 16 Sep 2019 07:51:22 +0200 Subject: [PATCH] Version 2.2 Add Dimmer Functions for Devices --- Release-Notes.md | 12 +++++++----- devices.php | 33 +++++++++++++++++++++++++++++++-- general.php | 12 +++++------- 3 files changed, 43 insertions(+), 14 deletions(-) diff --git a/Release-Notes.md b/Release-Notes.md index 7713ff5..fdc7819 100644 --- a/Release-Notes.md +++ b/Release-Notes.md @@ -1,7 +1,9 @@ # phpTradfri - Version History -## Version 2.1.1 +## Version 2.2 - 16th Sep 2019 ++ getDimmer() and setDimmer() added to devices.php +## Version 2.1.1 - 14th Sep 2019 * Fix missing return in Function statusgateway() -## Version 2.1 +## Version 2.1 - 14th Sep 2019 * Add Subclass for Trådfri Gateway * defines.php + defines for gateway @@ -17,9 +19,9 @@ * general.php * Move from Constants to Parameters for Gateway Config * to initialize new object parameters User, Secret and Gateway IP must enterd. Example: -``` -$groups = new tradfrigroups("", "", ""); -``` + ``` + $groups = new tradfrigroups("", "", ""); + ``` * cleaning up file * Update ReadMe File ## Version 1.1 - 09th Sep 2019 diff --git a/devices.php b/devices.php index 87f88ac..c8d7db0 100644 --- a/devices.php +++ b/devices.php @@ -5,6 +5,14 @@ class tradfridevices extends tradfri { + function getDimmer($Id){ + + $dimid = $this->getDetails("15001/$Id"); + + return $dimid['3311']['0'][DIMMER]; + + } + function getIds(){ return explode(",", trim(str_replace(['[',']'], "" ,strstr($this->query("15001"), '[65')))); @@ -58,7 +66,7 @@ function poweroff($path){ } else - return "Gerät kann nicht ausgeschalet werden, da es keine Lampe ist"; + return $this->getName("15001/$device")." konnte nicht ausgeschaltet werden, da es keine Lampe ist"; } @@ -75,7 +83,28 @@ function poweron($path){ } else - return "Gerät konnte nicht eingeschaltet werden, da es keine Lampe ist"; + return $this->getName("15001/$device")." konnte nicht eingeschaltet werden, da es keine Lampe ist"; + + } + + function setDimmer($path, $dimmer, $transition = NULL){ + + if($this->getTypeId($path) == TYPE_LIGHT){ + + $dim = round(254 * (int)str_replace("%", "", trim($dimmer)) / 100, 0); + + $payload = is_null($transition) ? '{ "3311": [{ "5851" : '.$dim.' }] }" : "{ "3311": [{ "5851": '.$dim.', "5712": '.$transition.' }] }'; + $this->action("put", $payload, "15001/$path"); + + if($this->getDimmer($path) == $dim) + return $this->getName("15001/$path")." wurde auf {$dimmer} gedimmt"; + else + return $this->getName("15001/$path")." konnte nicht auf {$dimmer} gedimmt werden"; + + } + + else + return $this->getName("15001/$device")." konnte nicht gedimmt werden, da es keine Lampe ist"; } diff --git a/general.php b/general.php index 323a843..d16a692 100644 --- a/general.php +++ b/general.php @@ -2,16 +2,15 @@ require_once('defines.php'); -class tradfri - { +class tradfri { private $gateway; function __construct($user, $secret, $gwip){ - $this->gateway['user'] = $user; - $this->gateway['secretkey'] = $secret; - $this->gateway['ip'] = $gwip; + $this->gateway['user'] = $user; + $this->gateway['secretkey'] = $secret; + $this->gateway['ip'] = $gwip; } @@ -67,7 +66,6 @@ function getName($path){ } - } -//End of Class tradfri + } //End of Class tradfri ?>