]> _ Git - tortuga-home.git/commitdiff
.
authorVincent <vincent@enhydra.fr>
Sat, 14 Nov 2020 14:15:31 +0000 (15:15 +0100)
committerVincent <vincent@enhydra.fr>
Sat, 14 Nov 2020 14:15:31 +0000 (15:15 +0100)
.idea/workspace.xml
scripts/lib/lib.php
scripts/lib/off.php
scripts/lib/proc.php [new file with mode: 0644]
scripts/lib/scenes.php
scripts/lib/shield.php
servers/logcat.php [new file with mode: 0644]
servers/logcatb.php [new file with mode: 0644]
servers/logcats.php [new file with mode: 0644]

index 6d39c3c80d34472946a50d517d3c7fd187a14524..99ed3d4fc79072ca998e556704c1cb3b9458f69a 100644 (file)
@@ -2,8 +2,15 @@
 <project version="4">
   <component name="ChangeListManager">
     <list default="true" id="352ce63a-b52a-41a2-979b-becda7920939" name="Default" comment=".">
+      <change afterPath="$PROJECT_DIR$/scripts/lib/proc.php" afterDir="false" />
+      <change afterPath="$PROJECT_DIR$/servers/logcat.php" afterDir="false" />
+      <change afterPath="$PROJECT_DIR$/servers/logcatb.php" afterDir="false" />
+      <change afterPath="$PROJECT_DIR$/servers/logcats.php" afterDir="false" />
       <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
+      <change beforePath="$PROJECT_DIR$/scripts/lib/lib.php" beforeDir="false" afterPath="$PROJECT_DIR$/scripts/lib/lib.php" afterDir="false" />
+      <change beforePath="$PROJECT_DIR$/scripts/lib/off.php" beforeDir="false" afterPath="$PROJECT_DIR$/scripts/lib/off.php" afterDir="false" />
       <change beforePath="$PROJECT_DIR$/scripts/lib/scenes.php" beforeDir="false" afterPath="$PROJECT_DIR$/scripts/lib/scenes.php" afterDir="false" />
+      <change beforePath="$PROJECT_DIR$/scripts/lib/shield.php" beforeDir="false" afterPath="$PROJECT_DIR$/scripts/lib/shield.php" afterDir="false" />
     </list>
     <option name="SHOW_DIALOG" value="false" />
     <option name="HIGHLIGHT_CONFLICTS" value="true" />
       <workItem from="1605001866699" duration="7793000" />
       <workItem from="1605087671373" duration="102000" />
       <workItem from="1605087787424" duration="33487000" />
-      <workItem from="1605261347643" duration="600000" />
-    </task>
-    <task id="LOCAL-00340" summary=".">
-      <created>1598265728108</created>
-      <option name="number" value="00340" />
-      <option name="presentableId" value="LOCAL-00340" />
-      <option name="project" value="LOCAL" />
-      <updated>1598265728109</updated>
+      <workItem from="1605261347643" duration="1199000" />
+      <workItem from="1605342171398" duration="4613000" />
+      <workItem from="1605355486465" duration="7740000" />
     </task>
     <task id="LOCAL-00341" summary=".">
       <created>1599316711212</created>
       <option name="project" value="LOCAL" />
       <updated>1605188139134</updated>
     </task>
-    <option name="localTasksCounter" value="389" />
+    <task id="LOCAL-00389" summary=".">
+      <created>1605261980841</created>
+      <option name="number" value="00389" />
+      <option name="presentableId" value="LOCAL-00389" />
+      <option name="project" value="LOCAL" />
+      <updated>1605261980842</updated>
+    </task>
+    <option name="localTasksCounter" value="390" />
     <servers />
   </component>
   <component name="TypeScriptGeneratedFilesManager">
       <screen x="0" y="0" width="1707" height="920" />
     </state>
     <state x="740" y="229" key="#com.jetbrains.php.refactoring.extractMethod.PhpExtractMethodDialog#function0/0.0.1707.920@0.0.1707.920" timestamp="1604146905948" />
-    <state x="701" y="75" width="737" height="502" key="CommitChangelistDialog2" timestamp="1605188136787">
-      <screen x="0" y="0" width="1920" height="1160" />
+    <state x="198" y="0" width="737" height="502" key="CommitChangelistDialog2" timestamp="1605261958132">
+      <screen x="0" y="0" width="2560" height="1040" />
     </state>
     <state x="132" y="0" width="737" height="502" key="CommitChangelistDialog2/0.0.1707.920@0.0.1707.920" timestamp="1605086955514" />
     <state x="701" y="75" key="CommitChangelistDialog2/0.0.1920.1160@0.0.1920.1160" timestamp="1605188136787" />
-    <state x="198" y="0" width="745" height="567" key="CommitChangelistDialog2/0.0.2560.1040@0.0.2560.1040" timestamp="1605171492435" />
+    <state x="198" y="0" width="745" height="567" key="CommitChangelistDialog2/0.0.2560.1040@0.0.2560.1040" timestamp="1605261958132" />
     <state x="952" y="244" key="FileChooserDialogImpl" timestamp="1605104496549">
       <screen x="0" y="0" width="2560" height="1040" />
     </state>
     <state x="635" y="216" key="FileChooserDialogImpl/0.0.1707.920@0.0.1707.920" timestamp="1604227698339" />
     <state x="952" y="244" key="FileChooserDialogImpl/0.0.2560.1040@0.0.2560.1040" timestamp="1605104496549" />
-    <state x="1114" y="443" key="NewPhpFileDialog" timestamp="1605089580764">
+    <state x="1114" y="443" key="NewPhpFileDialog" timestamp="1605344146097">
       <screen x="0" y="0" width="2560" height="1040" />
     </state>
     <state x="743" y="392" key="NewPhpFileDialog/0.0.1707.920@0.0.1707.920" timestamp="1604238041494" />
-    <state x="1114" y="443" key="NewPhpFileDialog/0.0.2560.1040@0.0.2560.1040" timestamp="1605089580764" />
+    <state x="1114" y="443" key="NewPhpFileDialog/0.0.2560.1040@0.0.2560.1040" timestamp="1605344146097" />
     <state x="546" y="120" key="SettingsEditor" timestamp="1605087773918">
       <screen x="0" y="0" width="2560" height="1040" />
     </state>
index dcf3b148717b41346b0d036285b44e15d5640019..1232d51fdb7b9601304ca3f88dca149708ae7089 100644 (file)
@@ -43,6 +43,7 @@ require_once ROOT . '/scripts/lib/ifttt.php';
 require_once ROOT . '/scripts/lib/router.php';
 require_once ROOT . '/scripts/lib/flowerpower.php';
 require_once ROOT . '/scripts/lib/denon.php';
+require_once ROOT . '/scripts/lib/proc.php';
 require_once ROOT . '/scripts/lib/shield.php';
 
 
index fa905ba13fb1b5598d1605e6c683c60e5f830905..dbae0fc69ca6be8ea7e48f3e9e52218bd7648d4f 100644 (file)
@@ -33,8 +33,7 @@ function offSalon()
 
 function offBureau()
 {
-    domoticzSwitch(1, false);
-    irsend('bureau', 'Projector', 'PowerOff');
+    execScene('bureau/media/stop');
 }
 
 function offSdb()
diff --git a/scripts/lib/proc.php b/scripts/lib/proc.php
new file mode 100644 (file)
index 0000000..733eacd
--- /dev/null
@@ -0,0 +1,131 @@
+<?php
+
+/**
+ * this is a pure php implementation of something like 'expect'. this is for
+ * automating cli applications where the apps block while waiting for user
+ * input. In the end, the goal is to automate these input blocking cli apps for
+ * example, subversion asking for svn username and password.
+ * @since april 23rd, 2012
+ * @author shean massey
+ */
+class proc
+{
+    private $_proc_resource = null;
+    private $_cases = array();
+    private $_output_text = '';
+    private $_pipes = null;
+
+    public function __construct($process = '')
+    {
+        if ($process) {
+            $this->open($process);
+        }
+    }
+
+    /**
+     * create the internal pipes for reading and writing to the opened process
+     */
+    public function open($process)
+    {
+        $descriptors = array(
+            0 => array('pipe', 'r'),
+            1 => array('pipe', 'w'),
+            2 => array('pipe', 'w'),
+        );
+        $this->_proc_resource = proc_open($process, $descriptors, $pipes);
+        if (!is_resource($this->_proc_resource)) {
+            throw new \exception('proc_open() failed to create a resource');
+        }
+        $this->_pipes = $pipes;
+        return $this;
+    }
+
+    /**
+     * close the opened pipes+process and return the return code of that process
+     */
+    public function close()
+    {
+        fclose($this->_pipes[0]);
+        fclose($this->_pipes[1]);
+        $return_code = proc_close($this->_proc_resource);
+        return $return_code;
+    }
+
+    /**
+     * set the rules, and assoc array where the keys are strings
+     * of 'expected text' and the values are closures to be executed
+     * once the expected string has been matched
+     */
+    public function on(array $cases)
+    {
+        $this->_cases = $cases;
+        return $this;
+    }
+
+    /**
+     * write to the opened processes input stream
+     */
+    public function write($text)
+    {
+        fwrite($this->_pipes[0], $text);
+        return $this;
+    }
+
+    /**
+     * write() + newline
+     */
+    public function writeln($text)
+    {
+        return $this->write($text . PHP_EOL);
+    }
+
+    /**
+     * run the script that was previously open()d and apply the expectation rules
+     */
+    public function run()
+    {
+        $buffer = '';
+        while ($block = stream_get_contents($this->_pipes[1], 20)) {
+            $e = explode("\n", $block);
+            $buffer .= $e[0];
+            $linesToParse = [];
+            if (count($e) > 1) {
+                for ($i = 1; $i < count($e); $i++) {
+                    $linesToParse[] = $buffer;
+                    $buffer = $e[$i];
+                }
+            }
+            foreach ($linesToParse as $line) {
+                $this->_parseLine($line);
+            }
+        }
+    }
+
+    protected function _parseLine($line)
+    {
+        if ($this->tooLate($line)) {
+            return;
+        }
+
+        foreach ($this->_cases as $expected_text => $closure) {
+            if (strpos($line, $expected_text)) {
+                $closure();
+            }
+        }
+    }
+
+    protected function tooLate($line)
+    {
+        // Time 11-14 14:31:35.586
+        $month = (int)substr($line, 0, 2);
+        $day = (int)substr($line, 3, 2);
+        $hour = (int)substr($line, 6, 2);
+        $min = (int)substr($line, 9, 2);
+        $sec = (int)substr($line, 12, 2);
+
+        $t = mktime($hour, $min, $sec, $month, $day, date('Y'));
+        $c = time();
+
+        return $t < $c - 5 || $t > $c;
+    }
+}
\ No newline at end of file
index 0d33d3d1068a1a0fd16b28308a3853c2d2f7bd92..2c5060c4af5e08b4db038b93f9fd44bd260d6564 100644 (file)
@@ -497,6 +497,14 @@ $scenes = [
         ['type' => 'function', 'function' => 'bureauAuto', 'args' => [false]],
         ['type' => 'ir', 'room' => 'bureausun', 'device' => 'Projector', 'command' => 'PowerOn'],
     ],
+    'bureau/media/stop' => [
+        /*    domoticzSwitch(1, false);
+      irsend('bureau', 'Projector', 'PowerOff');*/
+        ['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'],
+    ],
     'bureau/screen/down' => [
         ['type' => 'domoticz', 'device' => '1', 'command' => true, 'priority' => true],
     ],
index 495e4d09a26cab40c2f1a1800e49ddd85e40934f..a9c355407a58bfb400095bada585374f1ad960f8 100644 (file)
@@ -261,13 +261,30 @@ function shieldShareIntent($content, $device = null)
     shieldCommand('shell am start', '-a android.intent.action.VIEW  -d \'"' . $content . '"\'', $device);
 }
 
+function shieldLogcat($cases = [], $device = null)
+{
+    shieldConnect(false, $device);
+    $proc = new proc();
+    $cmd=_adbcmd('logcat', '', $device);
+    echo $cmd."\n";
+    $proc->open($cmd);
+    $proc->on($cases);
+    $proc->run();
+}
+
 
 function _adb($command, $params = '', $device = null)
+{
+    $c = _adbcmd($command, $params, $device);
+    echo $c . ' :: ' . `$c` . "\n";
+}
+
+function _adbcmd($command, $params, $device = null)
 {
     $device = getDevice($device);
     $c = 'adb -s ' . $device['shield'] . ':5555 ' . $command;
     if ($params) {
         $c .= ' ' . $params;
     }
-    echo $c . ' :: ' . `$c` . "\n";
+    return $c;
 }
\ No newline at end of file
diff --git a/servers/logcat.php b/servers/logcat.php
new file mode 100644 (file)
index 0000000..61ab15d
--- /dev/null
@@ -0,0 +1,28 @@
+<?php
+require_once __DIR__ . "/../scripts/import.php";
+
+if (!isset($device)) {
+    $device = 'salon';
+}
+
+// Set time limit to indefinite execution
+set_time_limit(0);
+ignore_user_abort(true);
+
+$cases = [
+    'Going to sleep due to power button' => function () use ($device) {
+        echo 'sleep' . "\n";
+        off($device);
+    },
+    'Waking up from sleep' => function () use ($device) {
+        echo 'wakeup' . "\n";
+        shieldRunActivity($device);
+    },
+];
+
+echo 'Run home server logcat ' . $device . "\n";
+
+while (true) {
+    shieldLogcat($cases, $device);
+    echo 'Logcat ended' . "\n----\n";
+}
diff --git a/servers/logcatb.php b/servers/logcatb.php
new file mode 100644 (file)
index 0000000..aed22b0
--- /dev/null
@@ -0,0 +1,4 @@
+#!/usr/bin/php
+<?php
+$device = 'bureau';
+include_once "logcat.php";
\ No newline at end of file
diff --git a/servers/logcats.php b/servers/logcats.php
new file mode 100644 (file)
index 0000000..de44220
--- /dev/null
@@ -0,0 +1,4 @@
+#!/usr/bin/php
+<?php
+$device = 'salon';
+include_once "logcat.php";
\ No newline at end of file