From 31bf358b1ee31467e793e00bdbd7dd0e6f8e2a8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=98=D1=81=D1=83=D0=BF=D0=BE=D0=B2=20=D0=90=D0=BD=D0=B4?= =?UTF-8?q?=D1=80=D0=B5=D0=B9=20=D0=9D=D0=B8=D0=BA=D0=BE=D0=BB=D0=B0=D0=B5?= =?UTF-8?q?=D0=B2=D0=B8=D1=87?= Date: Thu, 29 Feb 2024 07:57:24 +0300 Subject: [PATCH] fix update linked property brightness linked setting debug --- modules/openhasp/openhasp.class.php | 33 +++++++++++++++++++++++----- templates/openhasp/action_admin.html | 10 +++++++-- 2 files changed, 36 insertions(+), 7 deletions(-) diff --git a/modules/openhasp/openhasp.class.php b/modules/openhasp/openhasp.class.php index 469a4ef..60c9959 100644 --- a/modules/openhasp/openhasp.class.php +++ b/modules/openhasp/openhasp.class.php @@ -127,7 +127,8 @@ function admin(&$out) { $out['MQTT_PASSWORD'] = $this->config['MQTT_PASSWORD']; $out['MQTT_AUTH'] = $this->config['MQTT_AUTH']; $out['DEBUG_MODE'] = $this->config['DEBUG_MODE']; - + $out['DEBUG'] = $this->config['DEBUG']; + if ($this->view_mode == 'update_settings') { $this->config['MQTT_HOST'] = gr('mqtt_host', 'trim'); $this->config['MQTT_USERNAME'] = gr('mqtt_username', 'trim'); @@ -135,6 +136,7 @@ function admin(&$out) { $this->config['MQTT_AUTH'] = gr('mqtt_auth', 'int'); $this->config['MQTT_PORT'] = gr('mqtt_port', 'int'); $this->config['MQTT_QUERY'] = gr('mqtt_query', 'trim'); + $this->config['DEBUG'] = gr('debug', 'int'); $this->saveConfig(); setGlobal('cycle_openhaspControl', 'restart'); $this->redirect("?"); @@ -219,8 +221,8 @@ function setLinked($config){ function sendMQTTCommand($topic, $command) { - DebMes("Sending custom command to $topic: " . $command, 'openhasp'); $this->getConfig(); + $this->log("Sending command to $topic: " . $command); include_once(ROOT . "3rdparty/phpmqtt/phpMQTT.php"); $client_name = "NSPanel module"; if ($this->config['MQTT_AUTH']) { @@ -274,7 +276,7 @@ function api($params) if ($rec){ if ($_SERVER['REQUEST_METHOD']=='POST'){ - $old_config = $this->getPanelConfig($rec['PANEL_CONFIG']); + $old_config = $rec['PANEL_CONFIG']; $config = file_get_contents('php://input'); $rec['PANEL_CONFIG'] = $config; SQLUpdate($table_name, $rec); @@ -286,6 +288,8 @@ function api($params) return $rec['PANEL_CONFIG']; } } + else + return "Not found"; } if ($params['request'][0]=='reload') { $id = $params['request'][1]; @@ -330,7 +334,7 @@ function processPanelMessage($panel, $topic, $msg) { $key = basename($topic); - DebMes("Processing (" . $panel['TITLE'] . ") $topic $key:\n$msg", 'openhasp'); + $this->log("Processing (" . $panel['TITLE'] . ") $topic $key: $msg"); if ($key == "page"){ @@ -363,6 +367,10 @@ function processPanelMessage($panel, $topic, $msg) $this->sendValue($panel['MQTT_PATH'], "backlight" , 255); } } + else if ($key == "backlight"){ + $backlight = json_decode($msg,true); + $this->setLinkedProperty($panel,"brightness", $backlight['brightness']); + } else if (preg_match('/^p(\d+)b(\d+)$/', $key, $matches)) { $page_index = $matches[1]; $object_id = $matches[2]; @@ -410,6 +418,7 @@ function setLinkedProperty($panel,$name,$value){ function processMessage($topic, $msg) { + $this->getConfig(); if (preg_match('/command/', $topic)) return; $panels = SQLSelect("SELECT * FROM hasp_panels"); $total = count($panels); @@ -446,7 +455,10 @@ function propertySetHandle($object, $property, $value) if (preg_match($pattern, $key, $matches)) { $name = $matches[1]; - $this->sendValue($panels[$i]['MQTT_PATH'], $name , $value); + if ($name == 'brightness') + $this->sendValue($panels[$i]['MQTT_PATH'], "backlight" , $value); + else + $this->sendValue($panels[$i]['MQTT_PATH'], $name , $value); } } } @@ -462,6 +474,8 @@ function propertySetHandle($object, $property, $value) if (is_string($val) && str_contains($val, $op)){ $name = "p".$pi."b".$object["id"].".".$key; $data = str_replace($op, $value, $val); + if (str_contains($data, '%')) + $data = processTitle($data); $this->sendValue($panels[$i]['MQTT_PATH'], $name , $data); $found = 1; } @@ -478,6 +492,15 @@ function processCycle() { $this->getConfig(); //to-do } + + + function log($message) { + //echo $message . "\n"; + // DEBUG MESSAGE LOG + if($this->config['DEBUG'] == 1) + DebMes($message, $this->name); + } + /** * Install * diff --git a/templates/openhasp/action_admin.html b/templates/openhasp/action_admin.html index 99f2d61..c61c42e 100644 --- a/templates/openhasp/action_admin.html +++ b/templates/openhasp/action_admin.html @@ -4,7 +4,7 @@
<#LANG_ADD#> <#LANG_SETUP#> - +
  @@ -59,7 +59,13 @@
- +
+ + <#LANG_YES#> + <#LANG_NO#> +