]> _ Git - tortuga-home.git/commitdiff
.
authorVincent <vincent@enhydra.fr>
Wed, 10 Feb 2021 19:40:05 +0000 (20:40 +0100)
committerVincent <vincent@enhydra.fr>
Wed, 10 Feb 2021 19:40:05 +0000 (20:40 +0100)
.idea/workspace.xml
config/rooms.php
scripts/denon.php
scripts/lib/denon.php
scripts/lib/scenes.php

index 3664d148aa1806329d6dc6128f4bac9edbedafad..b9865f05a9c9c6db88ba176d361921f17d78234d 100644 (file)
@@ -2,15 +2,11 @@
 <project version="4">
   <component name="ChangeListManager">
     <list default="true" id="352ce63a-b52a-41a2-979b-becda7920939" name="Default" comment=".">
-      <change beforePath="$PROJECT_DIR$/.idea/home.iml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/home.iml" afterDir="false" />
-      <change beforePath="$PROJECT_DIR$/.idea/php.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/php.xml" afterDir="false" />
       <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
-      <change beforePath="$PROJECT_DIR$/composer.json" beforeDir="false" afterPath="$PROJECT_DIR$/composer.json" afterDir="false" />
-      <change beforePath="$PROJECT_DIR$/composer.lock" beforeDir="false" afterPath="$PROJECT_DIR$/composer.lock" afterDir="false" />
-      <change beforePath="$PROJECT_DIR$/config/global.php" beforeDir="false" afterPath="$PROJECT_DIR$/config/global.php" afterDir="false" />
+      <change beforePath="$PROJECT_DIR$/config/rooms.php" beforeDir="false" afterPath="$PROJECT_DIR$/config/rooms.php" afterDir="false" />
+      <change beforePath="$PROJECT_DIR$/scripts/denon.php" beforeDir="false" afterPath="$PROJECT_DIR$/scripts/denon.php" afterDir="false" />
       <change beforePath="$PROJECT_DIR$/scripts/lib/denon.php" beforeDir="false" afterPath="$PROJECT_DIR$/scripts/lib/denon.php" afterDir="false" />
-      <change beforePath="$PROJECT_DIR$/scripts/lib/squeezebox.php" beforeDir="false" afterPath="$PROJECT_DIR$/scripts/lib/squeezebox.php" afterDir="false" />
-      <change beforePath="$PROJECT_DIR$/scripts/squeeze.php" beforeDir="false" afterPath="$PROJECT_DIR$/scripts/squeeze.php" afterDir="false" />
+      <change beforePath="$PROJECT_DIR$/scripts/lib/scenes.php" beforeDir="false" afterPath="$PROJECT_DIR$/scripts/lib/scenes.php" afterDir="false" />
     </list>
     <option name="SHOW_DIALOG" value="false" />
     <option name="HIGHLIGHT_CONFLICTS" value="true" />
       <workItem from="1612347206766" duration="685000" />
       <workItem from="1612620373278" duration="26000" />
       <workItem from="1612620424202" duration="11603000" />
-      <workItem from="1612640974349" duration="5158000" />
-    </task>
-    <task id="LOCAL-00400" summary=".">
-      <created>1605437456015</created>
-      <option name="number" value="00400" />
-      <option name="presentableId" value="LOCAL-00400" />
-      <option name="project" value="LOCAL" />
-      <updated>1605437456015</updated>
+      <workItem from="1612640974349" duration="5182000" />
+      <workItem from="1612793924157" duration="7405000" />
+      <workItem from="1612981789538" duration="2041000" />
     </task>
     <task id="LOCAL-00401" summary=".">
       <created>1605517718088</created>
       <option name="project" value="LOCAL" />
       <updated>1612696367187</updated>
     </task>
-    <option name="localTasksCounter" value="449" />
+    <task id="LOCAL-00449" summary=".">
+      <created>1612793716184</created>
+      <option name="number" value="00449" />
+      <option name="presentableId" value="LOCAL-00449" />
+      <option name="project" value="LOCAL" />
+      <updated>1612793716185</updated>
+    </task>
+    <option name="localTasksCounter" value="450" />
     <servers />
   </component>
   <component name="TypeScriptGeneratedFilesManager">
index c7829d049162aa5134a4c3ba6c1e3c77f36fa68a..37415e4085889b013b59bd2e849c34de19f4e864 100644 (file)
@@ -66,9 +66,9 @@ function salon()
         ['type' => 'light', 'scene' => 'salon/lecturenocture', 'label' => 'Lecture nocturne'],
         ['type' => 'light', 'scene' => 'salon/cheminee', 'label' => 'Cheminée'],
     ];
-    $all = array_merge($favorites, [
-
-    ]);
+    $all = array_merge($favorites, [['type' => 'separator', 'label' => 'Projecteur'],
+        ['type' => 'light', 'scene' => 'salon/projector/on', 'label' => 'Allumer'],
+        ['type' => 'light', 'scene' => 'salon/projector/off', 'label' => 'éteindre']]);
     return array('all' => $all, 'favorites' => $favorites);
 }
 
index 4cc566766d78fc20823f81d17bc3da7b28d6dff6..bd19c737f1a525079aefecfe97913c38385abf96 100644 (file)
@@ -1,9 +1,17 @@
 <?php
 require_once "import.php";
-if(isset($_GET['avroff'])){
+if(isset($_GET['avrcmd'])){
+    echo _denonTelnet($_GET['avrcmd']);
+}elseif (isset($_GET['avrvolume'])) {
+    echo denonAVRGetVolume();
+} else if (isset($_GET['avrinput'])) {
+    echo denonAVRGetInput();
+} else if (isset($_GET['avroff'])) {
     denonAVROff();
-}else if(isset($_GET['avron'])){
+} else if (isset($_GET['avron'])) {
     denonAVROn();
-}else {
+} else if (isset($_GET['avrpower'])) {
+    echo denonAVRGetPowerState();
+} else {
     setState('denon', '0');
 }
\ No newline at end of file
index 7395fb8073bcddf20a3faf1aaae04019397c3f2e..b1fd2eb7cdc249c9ea0ee0cf214afe24d2ff0c37 100644 (file)
@@ -1,4 +1,6 @@
 <?php
+
+
 function denon($on = false)
 {
     $state = getState('denon', '0') == '1';
@@ -9,17 +11,9 @@ function denon($on = false)
     setState('denon', $on ? '1' : '0');
 }
 
-function _denonAVR($command)
-{
-    $context = ['http' => ['method' => 'GET'], 'ssl' => ['verify_peer' => false, 'verify_peer_name' => false, 'allow_self_signed' => true]];
-    $context = stream_context_create($context);
-    return file_get_contents('https://192.168.13.42:10443/ajax/globals/' . $command . '&_' . time(), false, $context);
-}
-
 function denonAVRVolume($volume, $increase = '')
 {
-    $device = 2894;
-    $current = domoticzGetLevel($device);
+    $current = denonAVRGetVolume();
     if ($increase === '+' || $increase === '-') {
         if ($increase === '+') {
             $volume += $current;
@@ -27,39 +21,142 @@ function denonAVRVolume($volume, $increase = '')
             $volume = $current - $volume;
         }
     }
-    $volume = min(80, $volume);
-    domoticzSetLevel($device, $volume, true);
+    $volume = min(80, max(0, round($volume)));
+    if ($volume !== $current) {
+        echo _denonTelnet('MV' . $volume);
+    }
     return $current . '->' . $volume;
 }
 
 function denonAVROn($input = 'Media Player')
 {
-    _denonAVR('set_config?type=4&data=' . rawurlencode('<MainZone><Power>1</Power></MainZone>'));
+    if (!denonAVRGetPowerState()) {
+        _denonTelnet('ZMON');
+    }
     denonAVRInput($input);
 }
 
 function denonAVRInput($input)
 {
-    $map = ['Media Player' => 5, 'CD' => 9, 'HEOS Music' => 13, 'AUX' => 7];
-    $volumes = ['Media Player' => 59, 'HEOS Music' => 50, 'CD' => 30, 'AUX' => 40];
+    $map = ['Media Player' => 'MPLAY', 'CBL/SAT' => 'SAT/CBL', 'Blu-Ray' => 'BD', 'AUX' => 'AUX1', 'HEOS Music' => 'NET', 'TV Audio' => 'TV'];
     if (isset($map[$input])) {
-        _denonAVR('set_config?type=7&data=' . rawurlencode('<Source zone="1" index="' . $map[$input] . '"></Source>'));
+        $cmd = $map[$input];
+    } else {
+        $cmd = $input;
+    }
+    $cmd = 'SI' . strtoupper($cmd);
+    if (denonAVRGetInput() !== $cmd) {
+        _denonTelnet($cmd);
         sleep(1);
     }
+
+    $audioMode = ['Media Player' => 'MOVIE', 'AUX' => 'MUSIC', 'CD' => 'MUSIC'];
+    if (isset($audioMode[$input])) {
+        denonAVRSetAudioMode($audioMode[$input]);
+        usleep(1000000 * 0.5);
+    }
+
+    $volumes = ['Media Player' => 60, 'HEOS Music' => 50, 'CD' => 30, 'AUX' => 26];
     if (isset($volumes[$input])) {
-        denonAVRVolume($volumes[$input]);
-        sleep(1);
-        denonAVRVolume(1, '+');
+        denonAVRVolume($volumes[$input], '');
+        usleep(1000000 * 0.5);
+    }
+
+    denonAVRSetSpeakerPreset(1);
+}
+
+function denonAVRGetVolume()
+{
+    $res = _denonTelnet('MV?');
+    $res = substr($res, 2);
+    if ($res > 100) {
+        $res /= 10;
+    }
+    return round($res);
+}
+
+function denonAVRSetAudioMode($mode)
+{
+    $cmd = 'MS' . strtoupper($mode);
+    if ($cmd === denonAVRGetAudioMode()) {
+        return;
+    }
+    $res = _denonTelnet($cmd);
+    sleep(1);
+    return $res;
+}
+
+function denonAVRSetSpeakerPreset($preset)
+{
+    $current = denonAVRGetSpeakerPreset();
+    if ($preset == $current) {
+        return;
     }
+    _denonTelnet('SPPR ' . $preset);
+}
+
+function denonAVRGetSpeakerPreset()
+{
+    $res = _denonTelnet('SPPR ?');
+    $e = explode(' ', $res);
+    return $e[1];
+}
+
+function denonAVRGetAudioMode()
+{
+    return _denonTelnet('MS?');
+}
+
+function denonAVRGetInput()
+{
+    return _denonTelnet('SI?');
+}
+
+function denonAVRGetPowerState()
+{
+    return _denonTelnet('ZM?') === 'ZMON';
+}
+
+function _denonTelnet($cmd)
+{
+    $client = getDenonTelnetClient();
+    $res = $client->execute($cmd);
+    if ($res->isError()) {
+        return false;
+    }
+    return trim($res->getResponseText());
 }
 
 function denonAVROff()
 {
-    _denonAVR('set_config?type=4&data=' . rawurlencode('<MainZone><Power>3</Power></MainZone>'));
+    _denonTelnet('ZMOFF');
+    _denonTelnet('Z2OFF');
+    _denonTelnet('PWSTANDBY');
 }
 
-function epson($on = true)
+function epson($on = true, $force = false)
 {
+    $currentState = getState('EpsonPowerState', '0') === '1';
+    if (!$force && $currentState === $on) {
+        return;
+    }
     $cmd = $on ? 'PowerOn' : 'PowerOff';
     sshCommand('/usr/local/bin/ir Epson ' . $cmd, 'salon');
+    setState('EpsonPowerState', $on ? '1' : '0');
+    if ($currentState !== $on && $on) {
+        sleep(15);
+    }
+}
+
+/**
+ * @return \Graze\TelnetClient\TelnetClient
+ */
+function getDenonTelnetClient()
+{
+    global $denonTelnetClient;
+    if (!isset($denonTelnetClient)) {
+        $denonTelnetClient = Graze\TelnetClient\TelnetClient::factory();
+        $denonTelnetClient->connect('192.168.13.42:23', '', '', "\r", 2);
+    }
+    return $denonTelnetClient;
 }
\ No newline at end of file
index 6f0e96f6d8d68075eae2b4d7618d1164926a97fc..e6eb859406aea0c5c5f343a43a15ced763e4c22e 100644 (file)
@@ -334,6 +334,12 @@ $scenes = [
     'home/music/synchro/soiree' => [
         ['type' => 'function', 'function' => 'synchroSoiree'],
     ],
+    'salon/projector/on' => [
+        ['type' => 'function', 'function' => 'epson', 'args' => [true, true]],
+    ],
+    'salon/projector/off' => [
+        ['type' => 'function', 'function' => 'epson', 'args' => [false, true]],
+    ],
     'salon/on' => [
         ['type' => 'hue', 'group' => $salon, 'scene' => 'Gte8sl76rzAD1wO', 'repeat' => 2],
         //['type' => 'insteon', 'command' => '0?113=I=0=0'],
@@ -545,7 +551,7 @@ $scenes = [
         ['type' => 'scene', 'scene' => 'bureau/screen/up'],
         ['type' => 'scene', 'scene' => 'bureau/rideaux/open'],
         ['type' => 'scene', 'scene' => 'bureau/auto'],
-        ['type' => 'ir', 'room' => 'bureausun', 'device' => 'Projector', 'command' => 'PowerOff'],
+//        ['type' => 'ir', 'room' => 'bureausun', 'device' => 'Projector', 'command' => 'PowerOff'],
         ['type' => 'scene', 'scene' => 'bureau/sound/off'],
     ],
     'bureau/screen/down' => [