Skip to content
Permalink
Browse files

Update zigbee2mqtt.class.php

  • Loading branch information...
directman66 committed Apr 16, 2019
1 parent 6ab1127 commit 47d69284d2fdfc53fd52d00719e30c662a73534f
Showing with 64 additions and 22 deletions.
  1. +64 −22 modules/zigbee2mqtt/zigbee2mqtt.class.php
@@ -309,17 +309,31 @@ function setProperty($id, $value, $set_linked=0) {
function setPropertyDevice($id, $value, $set_linked=0) {
debmes('Нужно изменить значение id='.$id.' на '.$value, 'zigbee2mqtt');
debmes("SELECT * FROM zigbee2mqtt WHERE DEV_ID='".$id."'", 'zigbee2mqtt');
$rec=SQLSelectOne("SELECT * FROM zigbee2mqtt WHERE DEV_ID='".$id."'");
$sql="SELECT * FROM zigbee2mqtt WHERE DEV_ID='".$id."' and length(PATH_WRITE)>2";
if (!$rec['ID'] || !$rec['PATH']) {
debmes('Не хватает данных', 'zigbee2mqtt');
return 0;
}
debmes($sql, 'zigbee2mqtt');
// $rec=SQLSelectOne("SELECT * FROM zigbee2mqtt WHERE DEV_ID='".$id."' and PATH_WRITE is not null");
$rec=SQLSelect($sql);
$cnt=count($rec);
debmes("Найдено $cnt свойств, которые можно изменить", 'zigbee2mqtt');
if ($rec['REPLACE_LIST']!='') {
$list=explode(',',$rec['REPLACE_LIST']);
for($i=0;$i<$cnt;$i++) {
if ($rec[$i]['ID'] || $rec[$i]['PATH_WRITE']) {
//debmes('Не хватает данных, устройство '.$rec['ID'].' или путь управления '.$rec['PATH'].' не найдены', 'zigbee2mqtt');
// return 0;
debmes('Данных хватает, параметр '.$rec[$i]['ID'].' путь управления '.$rec[$i]['PATH'], 'zigbee2mqtt');
debmes($rec,'zigbee2mqtt');
debmes('Поехали дальше', 'zigbee2mqtt');
if ($rec[$i]['REPLACE_LIST']!='') {
$list=explode(',',$rec[$i]['REPLACE_LIST']);
foreach($list as $pair) {
$pair=trim($pair);
list($new,$old)=explode('=',$pair);
@@ -372,30 +386,39 @@ function setPropertyDevice($id, $value, $set_linked=0) {
**/
if (($rec['PAYLOAD_ON'])||$rec['PAYLOAD_OFF']) {
debmes('Подменяем '.$value. " на ". $rec['PAYLOAD_ON']."/".$rec['PAYLOAD_OFF'], 'zigbee2mqtt');
if (($rec[$i]['PAYLOAD_ON'])||$rec[$i]['PAYLOAD_OFF']) {
debmes('Подменяем '.$value. " на ". $rec[$i]['PAYLOAD_ON']."/".$rec[$i]['PAYLOAD_OFF'], 'zigbee2mqtt');
//if (($rec['PAYLOAD_ON'])&& ($value=="1")) $json=array( $rec['METRIKA']=> $rec['PAYLOAD_ON']);
//if (($rec['PAYLOAD_OFF'])&& ($value=="0")) $json=array( $rec['METRIKA']=> $rec['PAYLOAD_OFF']);
if ($value=="1") $json=array( $rec['COMMAND_VALUE']=> $rec['PAYLOAD_ON']);
if ($value=="0") $json=array( $rec['COMMAND_VALUE']=> $rec['PAYLOAD_OFF']);
if ($value=="1") $json=array( $rec[$i]['COMMAND_VALUE']=> $rec[$i]['PAYLOAD_ON']);
if ($value=="0") $json=array( $rec[$i]['COMMAND_VALUE']=> $rec[$i]['PAYLOAD_OFF']);
if (($value=="device_on_left")&&($rec[$i]['METRIKA']=="state")) $json=array( $rec[$i]['COMMAND_VALUE']=> $rec[$i]['PAYLOAD_ON']);
if (($value=="device_off_left")&&($rec[$i]['METRIKA']=="state")) $json=array( $rec[$i]['COMMAND_VALUE']=> $rec[$i]['PAYLOAD_OFF']);
if (($value=="device_on_right")&&($rec[$i]['METRIKA']=="state")) $json=array( $rec[$i]['COMMAND_VALUE']=> $rec[$i]['PAYLOAD_ON']);
if (($value=="device_off_right")&&($rec[$i]['METRIKA']=="state")) $json=array( $rec[$i]['COMMAND_VALUE']=> $rec[$i]['PAYLOAD_OFF']);
$jsonvalue=json_encode($json) ;
debmes('Заменили '.$value. " на ". $jsonvalue, 'zigbee2mqtt');
} else
{
$json=array( $rec['COMMAND_VALUE']=> $value);
$json=array( $rec[$i]['COMMAND_VALUE']=> $value);
$jsonvalue=json_encode($json) ;
}
debmes('Публикую zigbee2mqqtt '.$rec['PATH_WRITE'].":".$jsonvalue, 'zigbee2mqtt');
debmes('Публикую zigbee2mqqtt '.$rec[$i]['PATH_WRITE'].":".$jsonvalue, 'zigbee2mqtt');
if ($rec['PATH_WRITE']) {
if ($rec[$i]['PATH_WRITE']) {
$mqtt_client->publish($rec['PATH_WRITE'],$jsonvalue, (int)$rec['QOS'], (int)$rec['RETAIN']);
$mqtt_client->publish($rec[$i]['PATH_WRITE'],$jsonvalue, (int)$rec[$i]['QOS'], (int)$rec[$i]['RETAIN']);
}
@@ -414,16 +437,18 @@ function setPropertyDevice($id, $value, $set_linked=0) {
}
*/
$rec['VALUE']=$value.'';
$rec['UPDATED']=date('Y-m-d H:i:s');
SQLUpdate('zigbee2mqtt', $rec);
$rec[$i]['VALUE']=$value.'';
$rec[$i]['UPDATED']=date('Y-m-d H:i:s');
SQLUpdate('zigbee2mqtt', $rec[$i]);
// if ($set_linked && $rec['LINKED_OBJECT'] && $rec['LINKED_PROPERTY']) {
// setGlobal($rec['LINKED_OBJECT'].'.'.$rec['LINKED_PROPERTY'], $value, array($this->name=>'0'));
// }
}
}
//else debmes('Не хватает данных, устройство '.$rec['ID'].' или путь управления '.$rec['PATH'].' не найдены', 'zigbee2mqtt');
}
@@ -963,19 +988,36 @@ function admin(&$out) {
$id=$this->id;
// $this->setProperty($mqtt_properties[$i]['ID'], $value);
debmes('!!!!!!!device_on','zigbee2mqtt');
$this->setPropertyDevice($id, 1);
$this->setPropertyDevice($id, 'device_on_left');
$this->redirect("?");
}
if ($this->view_mode=='device_off') {
$id=$this->id;
debmes('!!!!!!!device_off','zigbee2mqtt');
// $this->setProperty($mqtt_properties[$i]['ID'], $value);
$this->setPropertyDevice($id, 0);
$this->setPropertyDevice($id, 'device_off_left');
$this->redirect("?");
}
if ($this->view_mode=='device_on_right') {
$id=$this->id;
// $this->setProperty($mqtt_properties[$i]['ID'], $value);
debmes('!!!!!!!device_on','zigbee2mqtt');
$this->setPropertyDevice($id, 'device_on_right');
$this->redirect("?");
}
if ($this->view_mode=='device_off_right') {
$id=$this->id;
debmes('!!!!!!!device_off','zigbee2mqtt');
// $this->setProperty($mqtt_properties[$i]['ID'], $value);
$this->setPropertyDevice($id, 'device_off_right');
$this->redirect("?");
}
if ($this->view_mode=='startpairing') {
$this->sendcommand('zigbee2mqtt/bridge/config/permit_join', 'true');
$this->redirect("?tab=service");

0 comments on commit 47d6928

Please sign in to comment.
You can’t perform that action at this time.