Skip to content

Commit

Permalink
fix update linked property
Browse files Browse the repository at this point in the history
brightness linked
setting debug
  • Loading branch information
Исупов Андрей Николаевич committed Feb 29, 2024
1 parent d50ce15 commit 31bf358
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 7 deletions.
33 changes: 28 additions & 5 deletions modules/openhasp/openhasp.class.php
Expand Up @@ -127,14 +127,16 @@ 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');
$this->config['MQTT_PASSWORD'] = gr('mqtt_password', 'trim');
$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("?");
Expand Down Expand Up @@ -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']) {
Expand Down Expand Up @@ -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);
Expand All @@ -286,6 +288,8 @@ function api($params)
return $rec['PANEL_CONFIG'];
}
}
else
return "Not found";
}
if ($params['request'][0]=='reload') {
$id = $params['request'][1];
Expand Down Expand Up @@ -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"){
Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
}
}
Expand All @@ -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;
}
Expand All @@ -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
*
Expand Down
10 changes: 8 additions & 2 deletions templates/openhasp/action_admin.html
Expand Up @@ -4,7 +4,7 @@
<div class="col-md-3">
<a href="?view_mode=edit_hasp_panels" class="btn btn-default"><i class="glyphicon glyphicon-plus"></i> <#LANG_ADD#></a>
<a href="#" onClick="$('#api_settings').toggle();return false;" class="btn btn-default"><i class="glyphicon glyphicon-wrench"></i> <#LANG_SETUP#></a>
<a href="https://github.com/anisan/majordomo-openhasp" target="_blank" class="btn btn-default"><i class="glyphicon glyphicon-info-sign"></i></a>
<a href="https://connect.smartliving.ru/tasks/894.html" target="_blank" class="btn btn-default"><i class="glyphicon glyphicon-info-sign"></i></a>
</div>
<div class="col-md-3">
&nbsp;
Expand Down Expand Up @@ -59,7 +59,13 @@
</label>
<input type="password" name="mqtt_password" value="[#MQTT_PASSWORD#]" class="form-control">
</div>

<div class="form-group">
<label class="control-label">
Debug to DebMes:
</label>
<input type="radio" value="1" name="debug" [#if DEBUG="1"#] checked[#endif#]> <#LANG_YES#>
<input type="radio" value="0" name="debug" [#if DEBUG!="1"#] checked[#endif#]> <#LANG_NO#>
</div>
<div class="form-group">
<button type="submit" name="subm" value="Submit" class="btn btn-primary"><#LANG_UPDATE#></button>
<input type="hidden" name="view_mode" value="update_settings">
Expand Down

0 comments on commit 31bf358

Please sign in to comment.