Skip to content
Permalink
Browse files

Update zigbee2mqtt.class.php

  • Loading branch information...
directman66 committed Jun 25, 2019
1 parent acff38e commit e5be27662c14e5e6fd9576b72b0c6fd7d71e1abc
Showing with 85 additions and 53 deletions.
  1. +85 −53 modules/zigbee2mqtt/zigbee2mqtt.class.php
@@ -361,7 +361,9 @@ function setProperty($id, $value, $set_linked=0) {
if ($set_linked && $rec['LINKED_OBJECT'] && $rec['LINKED_PROPERTY']) {
setGlobal($rec['LINKED_OBJECT'].'.'.$rec['LINKED_PROPERTY'], $value, array($this->name=>'0'));
$oldvalue=getGlobal($rec['LINKED_OBJECT'].'.'.$rec['LINKED_PROPERTY']);
if ($value<>$oldvalue) setGlobal($rec['LINKED_OBJECT'].'.'.$rec['LINKED_PROPERTY'], $value, array($this->name=>'0'));
}
}
@@ -659,16 +661,11 @@ function processMessage2($path, $value) {
if (ZMQTT_DEBUG=="1" ) debmes('Поместили '.$ok , 'zigbee2mqtt');
//раскодируем
//parse_deviceinfo($ar)
if (ZMQTT_DEBUG=="1" ) debmes($json,'zigbee2mqtt');
if (ZMQTT_DEBUG=="1" ) debmes($json->{'type'},'zigbee2mqtt');
if ($json->{'type'}=='devices') {
if (ZMQTT_DEBUG=="1" ) debmes('справочник устройств:','zigbee2mqtt');
@@ -677,55 +674,13 @@ function processMessage2($path, $value) {
$this->parse_deviceinfo($json);
}
if ($json->{'type'}=='groups') {
if (ZMQTT_DEBUG=="1" ) debmes('обновим справочник групп','zigbee2mqtt');
if (ZMQTT_DEBUG=="1" ) debmes($json->{'message'}, 'zigbee2mqtt');
foreach ($json->{'message'} as $key=> $value)
{
//if (ZMQTT_DEBUG=="1" ) debmes($key.":". $value, 'zigbee2mqtt');
//echo $key.":". $value->{'friendly_name'};
$sql="select * from zigbee2mqtt_grouplist where Z2M_ID='$key'";
if (ZMQTT_DEBUG=="1" ) debmes($sql, 'zigbee2mqtt');
$grs=SQLSElectOne($sql);
$this->update_groups($json);
if (ZMQTT_DEBUG=="1" ) debmes($grs, 'zigbee2mqtt');
if (!$grs['ID'])
{
$grs['Z2M_ID']=$key;
$grs['TITLE']=$value->{'friendly_name'};
$grs['ADDED']= date('Y-m-d H:i:s');
if (ZMQTT_DEBUG=="1" ) debmes('SQLInsert zigbee2mqtt_grouplist' , 'zigbee2mqtt');
SQLInsert( 'zigbee2mqtt_grouplist', $grs);
} else
{
$grs['Z2M_ID']=$key;
$grs['TITLE']=$value->{'friendly_name'};
$grs['ADDED']= date('Y-m-d H:i:s');
if (ZMQTT_DEBUG=="1" ) debmes('SQLUpdate zigbee2mqtt_grouplist' , 'zigbee2mqtt');
SQLUpdate( 'zigbee2mqtt_grouplist', $grs);
}
}
}
}
//добавляем в справочник устройств zigbee2mqtt_devices
/* Search 'PATH' in database (db) */
@@ -925,7 +880,10 @@ function processMessage2($path, $value) {
// setGlobal($rec['LINKED_OBJECT'].'.'.$rec['LINKED_PROPERTY'], $newvalue, array($this->name=>'0'));
if (ZMQTT_DEBUG=="1" ) debmes('Вызываю setglobal: value:'.$rec['LINKED_OBJECT'].'.'.$rec['LINKED_PROPERTY'].' value:'. $newvalue,'zigbee2mqtt');
setGlobal($rec['LINKED_OBJECT'].'.'.$rec['LINKED_PROPERTY'], $newvalue, array('zigbee2mqtt'=>'0'));
$oldvalue=getGlobal($rec['LINKED_OBJECT'].'.'.$rec['LINKED_PROPERTY']);
if ($newvalue<>$oldvalue) setGlobal($rec['LINKED_OBJECT'].'.'.$rec['LINKED_PROPERTY'], $newvalue, array('zigbee2mqtt'=>'0'));
}
if ($rec['LINKED_OBJECT'] && $rec['LINKED_METHOD']) {
callMethod($rec['LINKED_OBJECT'] . '.' . $rec['LINKED_METHOD'], $rec['VALUE']);
@@ -993,7 +951,10 @@ function processMessage2($path, $value) {
if($rec1['LINKED_OBJECT'] && $rec1['LINKED_PROPERTY']) {
debmes('Вызываю setglobal: value:'.$rec1['LINKED_OBJECT'].'.'.$rec1['LINKED_PROPERTY'].' value:'. $newvalue,'zigbee2mqtt');
setGlobal($rec1['LINKED_OBJECT'].'.'.$rec1['LINKED_PROPERTY'], $newvalue, array('zigbee2mqtt'=>'0'));
$oldvalue=getGlobal($rec['LINKED_OBJECT'].'.'.$rec['LINKED_PROPERTY']);
if ($newvalue<>$oldvalue) setGlobal($rec1['LINKED_OBJECT'].'.'.$rec1['LINKED_PROPERTY'], $newvalue, array('zigbee2mqtt'=>'0'));
}
debmes('Проверяем, нужно ли вызвать метод : '.$rec1['LINKED_OBJECT'].'.'.$rec1['LINKED_METHOD'].' value:'. $newvalue,'zigbee2mqtt');
@@ -1086,7 +1047,10 @@ function processMessage2($path, $value) {
if($rec1['LINKED_OBJECT'] && $rec1['LINKED_PROPERTY']) {
debmes('Вызываю setglobal: value:'.$rec1['LINKED_OBJECT'].'.'.$rec1['LINKED_PROPERTY'].' value:'. $newvalue,'zigbee2mqtt');
setGlobal($rec1['LINKED_OBJECT'].'.'.$rec1['LINKED_PROPERTY'], $newvalue, array('zigbee2mqtt'=>'0'));
$oldvalue=getGlobal($rec['LINKED_OBJECT'].'.'.$rec['LINKED_PROPERTY']);
if ($newvalue<>$oldvalue) setGlobal($rec1['LINKED_OBJECT'].'.'.$rec1['LINKED_PROPERTY'], $newvalue, array('zigbee2mqtt'=>'0'));
}
@@ -1116,6 +1080,51 @@ function processMessage2($path, $value) {
}
function update_groups($json){
if (ZMQTT_DEBUG=="1" ) debmes('обновим справочник групп','zigbee2mqtt');
if (ZMQTT_DEBUG=="1" ) debmes($json->{'message'}, 'zigbee2mqtt');
foreach ($json->{'message'} as $key=> $value)
{
//if (ZMQTT_DEBUG=="1" ) debmes($key.":". $value, 'zigbee2mqtt');
//echo $key.":". $value->{'friendly_name'};
$sql="select * from zigbee2mqtt_grouplist where Z2M_ID='$key'";
if (ZMQTT_DEBUG=="1" ) debmes($sql, 'zigbee2mqtt');
$grs=SQLSElectOne($sql);
if (ZMQTT_DEBUG=="1" ) debmes($grs, 'zigbee2mqtt');
if (!$grs['ID'])
{
$grs['Z2M_ID']=$key;
$grs['TITLE']=$value->{'friendly_name'};
$grs['ADDED']= date('Y-m-d H:i:s');
if (ZMQTT_DEBUG=="1" ) debmes('SQLInsert zigbee2mqtt_grouplist' , 'zigbee2mqtt');
SQLInsert( 'zigbee2mqtt_grouplist', $grs);
} else
{
$grs['Z2M_ID']=$key;
$grs['TITLE']=$value->{'friendly_name'};
$grs['ADDED']= date('Y-m-d H:i:s');
if (ZMQTT_DEBUG=="1" ) debmes('SQLUpdate zigbee2mqtt_grouplist' , 'zigbee2mqtt');
SQLUpdate( 'zigbee2mqtt_grouplist', $grs);
}
}
}
// }
@@ -2073,7 +2082,8 @@ function admin(&$out) {
$type_id=$_GET['type_id'];
$vid_id=$_GET['vid_id'];
$this->redirect("?&location=$location&type_id=$type_id&vendor_id=$vendor_id&vid_id=$vid_id");
//$this->redirect("?&location=$location&type_id=$type_id&vendor_id=$vendor_id&vid_id=$vid_id");
$this->redirect("?");
}
@@ -2117,6 +2127,7 @@ function admin(&$out) {
$vid_id=$_GET['vid_id'];
$this->redirect("?&location=$location&type_id=$type_id&vendor_id=$vendor_id&vid_id=$vid_id");
//$this->redirect("?");
}
/////////////////////
@@ -2320,10 +2331,31 @@ function admin(&$out) {
$this->redirect("?tab=bind");
}
if ($this->view_mode=='cleardevicelog') {
$id=$this->id;
$rec=SQLSelectOne('select * from zigbee2mqtt_devices where ID="'.$id.'"' );
$ieee=$rec['IEEEADDR'];
sqlexec('delete from zigbee2mqtt_log where TITLE like "%'.$ieee.'%"');
debmes('delete from zigbee2mqtt_log where TITLE like "%'.$ieee.'%"', 'z2m');
$this->redirect("?view_mode=view_mqtt&id=".$id."&tab=device_log");
}
if ($this->view_mode=='unbind') {
$id=$this->id;
$target=$_POST['target'];
$source=$_POST['source'];

0 comments on commit e5be276

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