Skip to content

Commit

Permalink
Version 1.50
Browse files Browse the repository at this point in the history
  • Loading branch information
Nall-chan committed Dec 7, 2023
1 parent 91228df commit b26a133
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
6 changes: 4 additions & 2 deletions Tapo P100/module.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ public function RequestAction($Ident, $Value)
{
switch ($Ident) {
case \TpLink\VariableIdent::State:
return $this->SwitchMode((bool) $Value);
$this->SwitchMode((bool) $Value);
return;
}
//todo errormsg
}

public function RequestState()
Expand All @@ -45,6 +45,7 @@ public function RequestState()
}
return false;
}

public function SwitchMode(bool $State): bool
{
$Request = \TpLink\Api\Protocol::BuildRequest(\TpLink\Api\Method::SetDeviceInfo, $this->terminalUUID, [\TpLink\Api\Param::DeviceOn => $State]);
Expand Down Expand Up @@ -96,5 +97,6 @@ protected function SetStatus($Status)
$this->RequestState();
}
}
return true;
}
}
18 changes: 17 additions & 1 deletion libs/TapoLib.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class Url
public const HandshakeKlap = self::App . '/handshake2';
public const KlapRequest = self::App . '/request?';
}

class Method
{
public const GetDeviceInfo = 'get_device_info';
Expand All @@ -57,12 +58,14 @@ class Method
public const Login = 'login_device';
public const SecurePassthrough = 'securePassthrough';
}

class Param
{
public const DeviceOn = 'device_on';
public const Username = 'username';
public const Password = 'password';
}

class Result
{
public const Result = 'result';
Expand All @@ -71,6 +74,7 @@ class Result
public const Response = 'response';
public const EncryptedKey = 'key';
}

class Protocol
{
public const Method = 'method';
Expand All @@ -87,6 +91,7 @@ class Protocol
-1003=> 'JSON formatting error ',
9999 => 'Session Timeout'
];

public static function BuildHandshakeRequest(string $publicKey): string
{
return json_encode([
Expand All @@ -98,6 +103,7 @@ public static function BuildHandshakeRequest(string $publicKey): string

]);
}

public static function BuildRequest(string $Method, string $TerminalUUID = '', array $Params = []): string
{
$Request = [
Expand All @@ -114,6 +120,7 @@ public static function BuildRequest(string $Method, string $TerminalUUID = '', a
return json_encode($Request);
}
}

class TpProtocol
{
private const Token = 'token';
Expand Down Expand Up @@ -163,10 +170,12 @@ class VariableIdent
public const month_energy = 'month_energy';
public const current_power = 'current_power';
}

class VariableProfile
{
public const Runtime = 'Tapo.Runtime';
}

class TpLinkCipher
{
private $key;
Expand Down Expand Up @@ -290,6 +299,7 @@ public function Destroy()
//Never delete this line!
parent::Destroy();
}

public function ApplyChanges()
{
$this->SetTimerInterval(\TpLink\Timer::RequestState, 0);
Expand All @@ -307,6 +317,7 @@ public function ApplyChanges()
$this->SetStatus(IS_INACTIVE);
}
}

public function GetDeviceInfo()
{
$Request = \TpLink\Api\Protocol::BuildRequest(\TpLink\Api\Method::GetDeviceInfo);
Expand Down Expand Up @@ -335,6 +346,7 @@ protected function SetStatus($Status)
if ($this->GetStatus() != $Status) {
parent::SetStatus($Status);
}
return true;
}

protected function SendRequest(string $Request): string
Expand All @@ -358,7 +370,8 @@ protected function SendRequest(string $Request): string
return $this->EncryptedRequest($Request);
}
}
protected function CurlDebug(int $HttpCode): void

protected function CurlDebug(int $HttpCode)
{
switch ($HttpCode) {
case 0:
Expand All @@ -375,6 +388,7 @@ protected function CurlDebug(int $HttpCode): void
break;
}
}

private function InitBuffers()
{
$this->token = '';
Expand All @@ -386,6 +400,7 @@ private function InitBuffers()
$this->KlapUserHash = '';
$this->KlapSequenz = null;
}

private function Init(): bool
{
$Result = $this->Handshake();
Expand Down Expand Up @@ -437,6 +452,7 @@ private function CurlRequest(string $Url, string $Payload, bool $noError = false
}
return false;
}

private static function guidv4($data = null): string
{
// Generate 16 bytes (128 bits) of random data or use the data passed into the function.
Expand Down

0 comments on commit b26a133

Please sign in to comment.