Skip to content

Commit

Permalink
power meter fix
Browse files Browse the repository at this point in the history
  • Loading branch information
fandaymon committed Oct 8, 2023
1 parent 6764bec commit 1592b39
Showing 1 changed file with 20 additions and 35 deletions.
55 changes: 20 additions & 35 deletions modules/tuya/tuya.class.php
Expand Up @@ -634,7 +634,7 @@ function RefreshToken(){
return $this->config['TUYA_ACCESS_TOKEN'];
}

function TuyaLocalEncrypt($command, $json, $local_key,$tuya_ver='3.3') {
function TuyaLocalEncrypt($command, $json, $local_key, $tuya_ver='3.3') {
$prefix="000055aa00000000000000";
$suffix="000000000000aa55";
if ($tuya_ver == '3.1') {
Expand Down Expand Up @@ -1499,42 +1499,27 @@ function Tuya_Web_Discovery_Devices() {
$cmd_rec = SQLSelectOne("SELECT * FROM tucommands WHERE DEVICE_ID=".(int)$rec['ID']." AND TITLE LIKE '".DBSafe($key)."'");

if (!$cmd_rec['ID']) {
$cmd_rec = array();
$cmd_rec['TITLE'] = $key;
$cmd_rec['VALUE_MIN'] = $sc[$device['productId']][$key]['min'];
$cmd_rec['MODE'] = $sc[$device['productId']][$key]['mode'];
$cmd_rec['ALIAS'] = $sc[$device['productId']][$key]['code'];
$cmd_rec['VALUE_UNIT'] = $sc[$device['productId']][$key]['unit'];
$cmd_rec['VALUE_TYPE'] = $sc[$device['productId']][$key]['type'];

$cmd_rec['VALUE_MAX'] = $sc[$device['productId']][$key]['max'];
$cmd_rec['VALUE_SCALE'] = $sc[$device['productId']][$key]['scale'];
if ($cmd_rec['VALUE_SCALE'] == '') $cmd_rec['VALUE_SCALE']=0;
$cmd_rec['DIVIDEDBY2'] = 0;
$cmd_rec['DIVIDEDBY10'] = 0;
$cmd_rec['DIVIDEDBY100'] = 0;

$cmd_rec['DEVICE_ID'] = $rec['ID'];
$cmd_rec['ID'] = SQLInsert('tucommands', $cmd_rec);
} else {
$cmd_rec['VALUE_MIN'] = $sc[$device['productId']][$key]['min'];
$cmd_rec['MODE'] = $sc[$device['productId']][$key]['mode'];
$cmd_rec['ALIAS'] = $sc[$device['productId']][$key]['code'];
$cmd_rec['VALUE_UNIT'] = $sc[$device['productId']][$key]['unit'];
$cmd_rec['VALUE_MAX'] = $sc[$device['productId']][$key]['max'];
if ($cmd_rec['DIVIDEDBY2'] == 0) {
$cmd_rec = array();
$cmd_rec['TITLE'] = $key;
$cmd_rec['VALUE_MIN'] = $sc[$device['productId']][$key]['min'];
$cmd_rec['MODE'] = $sc[$device['productId']][$key]['mode'];
$cmd_rec['ALIAS'] = $sc[$device['productId']][$key]['code'];
$cmd_rec['VALUE_UNIT'] = $sc[$device['productId']][$key]['unit'];
$cmd_rec['VALUE_TYPE'] = $sc[$device['productId']][$key]['type'];

$cmd_rec['VALUE_MAX'] = $sc[$device['productId']][$key]['max'];
$cmd_rec['VALUE_SCALE'] = $sc[$device['productId']][$key]['scale'];
if ($cmd_rec['VALUE_SCALE'] == '') $cmd_rec['VALUE_SCALE']=0;
$cmd_rec['DIVIDEDBY2'] = 0;
$cmd_rec['DIVIDEDBY10'] = 0;
$cmd_rec['DIVIDEDBY100'] = 0;
$cmd_rec['POWER_METER'] = 0;
$cmd_rec['DECODE'] = 0;
$cmd_rec['SPLIT'] = 0;

$cmd_rec['DEVICE_ID'] = $rec['ID'];
$cmd_rec['ID'] = SQLInsert('tucommands', $cmd_rec);
}
if ($cmd_rec['VALUE_SCALE'] == '') $cmd_rec['VALUE_SCALE']=0;

$cmd_rec['VALUE_TYPE'] = $sc[$device['productId']][$key]['type'];

$cmd_rec['POWER_METER'] = 0;
$cmd_rec['DECODE'] = 0;
$cmd_rec['SPLIT'] = 0;

$cmd_rec['ID'] = SQLUpdate('tucommands', $cmd_rec);
}

if (isset($sc[$device['productId']][$key]['range']) and $sc[$device['productId']][$key]['range']) {
foreach ($sc[$device['productId']][$key]['range'] as $range_key => $range_value) {
Expand Down

0 comments on commit 1592b39

Please sign in to comment.