Skip to content

Commit

Permalink
no message
Browse files Browse the repository at this point in the history
  • Loading branch information
Nall-chan committed Jan 21, 2024
1 parent 3ca8659 commit 68c128d
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 18 deletions.
2 changes: 1 addition & 1 deletion Tapo Discovery/module.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ private function GetDevices(): array
$Values = [];
foreach ($Devices as $Device) {
$Guid = \TpLink\DeviceModel::GetGuidByDeviceModel($Device[\TpLink\Api\Result::DeviceModel]);
if (!$Guid) {
if ($Guid == '') {
continue;
}
$InstanceID = array_search(strtoupper($Device[\TpLink\Api\Result::Mac]), $IPSDevices);
Expand Down
9 changes: 7 additions & 2 deletions Tapo Hub Configurator/module.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,13 @@ private function GetDevicesFromHub()
return [];
}
$List = $Result[\TpLink\Api\Result::ChildList];
foreach ($List as &$ChildDevice) {
$ChildDevice['moduleID'] = \TpLink\HubChildDevicesModel::GetGuidByDeviceModel($ChildDevice[\TpLink\Api\Result::Model]);
foreach ($List as $Index => $ChildDevice) {
$Guid = \TpLink\HubChildDevicesModel::GetGuidByDeviceModel($ChildDevice[\TpLink\Api\Result::Model]);
if ($Guid) {
$List[$Index]['moduleID'] = $Guid;
} else {
unset($List[$Index]);
}
}
return $List;
}
Expand Down
15 changes: 15 additions & 0 deletions Tapo Hub Device/module.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

declare(strict_types=1);
eval('declare(strict_types=1);namespace TapoHubDevice {?>' . file_get_contents(dirname(__DIR__) . '/libs/helper/DebugHelper.php') . '}');
eval('declare(strict_types=1);namespace TapoHubDevice {?>' . file_get_contents(dirname(__DIR__) . '/libs/helper/VariableProfileHelper.php') . '}');
require_once dirname(__DIR__) . '/libs/TapoLib.php';

/**
Expand All @@ -15,16 +16,19 @@
* @version 1.60
*
* @method bool SendDebug(string $Message, mixed $Data, int $Format)
* @method void RegisterProfileFloat(string $Name, string $Icon, string $Prefix, string $Suffix, float $MinValue, float $MaxValue, float $StepSize, int $Digits)
*/
class TapoHubDevice extends IPSModule
{
use \TapoHubDevice\DebugHelper;
use \TapoHubDevice\VariableProfileHelper;

public function Create()
{
$this->RegisterPropertyString(\TpLink\Property::DeviceId, '');
$this->RegisterPropertyBoolean(\TpLink\Property::AutoRename, false);
$this->RegisterAttributeString(\TpLink\Attribute::Category, '');
//Tapo.Temperature.Room
}

public function Destroy()
Expand All @@ -38,6 +42,8 @@ public function ApplyChanges()
//Never delete this line!
parent::ApplyChanges();

$this->RegisterProfileFloat(\TpLink\VariableProfile::TargetTemperature, 'Temperature', '', ' °C', 5, 30, 0.5, 1);

$DeviceId = $this->ReadPropertyString(\TpLink\Property::DeviceId);
if ($DeviceId) {
$this->SetReceiveDataFilter('.*"' . \TpLink\Property::DeviceId . '":"' . $DeviceId . '".*');
Expand Down Expand Up @@ -187,4 +193,13 @@ private function GetModuleIdents(): array
}
return \TpLink\HubChildDevicesCategory::GetVariableIdentsByCategory($Category);
}

private function TrvStateToString(array $Values)
{
$State = array_shift($Values[\TpLink\VariableIdentTrv::trv_states]);
if (!$State) {
$State = '';
}
return $State;
}
}
6 changes: 3 additions & 3 deletions library.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"compatibility": {
"version": "6.0"
},
"version": "1.64",
"build": 164,
"date": 1705855551
"version": "1.65",
"build": 165,
"date": 1705843766
}
2 changes: 1 addition & 1 deletion libs/TapoCrypt.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,6 @@ private function EncryptedRequest(string $Payload): string
if ($Result === false) {
return '';
}
$this->SendDebug('EncryptedResponse', $Result, 0);
$json = json_decode($Result, true);
if ($json[\TpLink\Api\ErrorCode] == 9999) {
// Session Timeout, try to reconnect
Expand All @@ -189,6 +188,7 @@ private function EncryptedRequest(string $Payload): string
return '';
}
if ($json[\TpLink\Api\ErrorCode] != 0) {
$this->SendDebug('Response ' . \TpLink\Api\ErrorCode, $json[\TpLink\Api\ErrorCode], 0);
if (array_key_exists($json[\TpLink\Api\ErrorCode], \TpLink\Api\Protocol::$ErrorCodes)) {
$msg = \TpLink\Api\Protocol::$ErrorCodes[$json[\TpLink\Api\ErrorCode]];
} else {
Expand Down
3 changes: 3 additions & 0 deletions libs/TapoDevice.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ public function Destroy()

public function ApplyChanges()
{
//Never delete this line!
parent::ApplyChanges();

$this->RegisterProfileInteger(\TpLink\VariableProfile::RuntimeSeconds, '', '', ' seconds', 0, 0, 0);
$this->SetTimerInterval(\TpLink\Timer::RequestState, 0);
$this->SetSummary($this->ReadPropertyString(\TpLink\Property::Host));
Expand Down
33 changes: 22 additions & 11 deletions libs/TapoLib.php
Original file line number Diff line number Diff line change
Expand Up @@ -200,12 +200,13 @@ class DeviceModel

public static function GetGuidByDeviceModel(string $Model): string
{
$Model = explode(' ', $Model)[0];
$Model = explode('(', $Model)[0];
if (!array_key_exists($Model, self::$DeviceModels)) {
return false;
$Match = [];
if (preg_match('/^[a-zA-Z]{2}\d{3}/', $Model, $Match)) {
if (array_key_exists($Match[0], self::$DeviceModels)) {
return self::$DeviceModels[$Match[0]];
}
}
return self::$DeviceModels[$Model];
return '';
}
}

Expand Down Expand Up @@ -235,12 +236,13 @@ class HubChildDevicesModel

public static function GetGuidByDeviceModel(string $Model): string
{
$Model = explode(' ', $Model)[0];
$Model = explode('(', $Model)[0];
if (!array_key_exists($Model, self::$DeviceModels)) {
return false;
$Match = [];
if (preg_match('/^[a-zA-Z]{2}\d{3}/', $Model, $Match)) {
if (array_key_exists($Match[0], self::$DeviceModels)) {
return self::$DeviceModels[$Match[0]];
}
}
return self::$DeviceModels[$Model];
return '';
}
}

Expand Down Expand Up @@ -515,6 +517,7 @@ class VariableIdentTrv
public const target_temp = 'target_temp';
public const frost_protection_on = 'frost_protection_on';
public const child_protection = 'child_protection';
public const trv_states = 'trv_states';

public static $Variables = [
self::target_temp=> [
Expand All @@ -535,6 +538,14 @@ class VariableIdentTrv
IPSVarProfile => VariableProfile::Switch,
HasAction => true
],
self::trv_states=> [
IPSVarName => 'State',
IPSVarType => VARIABLETYPE_STRING,
IPSVarProfile => '',
HasAction => false,
ReceiveFunction=> 'TrvStateToString',
],

];
}
/*
Expand Down Expand Up @@ -563,7 +574,7 @@ class VariableProfile
public const Switch = '~Switch';
public const HexColor = '~HexColor';
public const UnixTimestampTime = '~UnixTimestampTime';
public const TargetTemperature = '~Temperature.HM';
public const TargetTemperature = 'Tapo.Temperature.Room';
public const Temperature = '~Temperature';
public const Humidity = '~Humidity';
public const Battery = '~Battery.100';
Expand Down

0 comments on commit 68c128d

Please sign in to comment.