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 23, 2024
1 parent 7576bca commit d3110ed
Showing 1 changed file with 67 additions and 67 deletions.
134 changes: 67 additions & 67 deletions Xiaomi MIoT Device/module.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,6 @@ public function Destroy()

public function ApplyChanges()
{
$this->SetTimerInterval(\Xiaomi\Device\Timer::RefreshState, 0);
$this->SetTimerInterval(\Xiaomi\Device\Timer::Reconnect, 0);
$this->RegisterProfileEx(
VARIABLETYPE_INTEGER,
'XIAOMI.ExecuteAction',
Expand All @@ -89,73 +87,16 @@ public function ApplyChanges()
[0, 'Execute', '', -1]
]
);
$this->ServerStamp = 0;
$this->ServerStampTime = 0;
$this->Retries = 2;

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

// Anzeige IP in der INFO Spalte
$this->SetSummary($this->ReadPropertyString(\Xiaomi\Device\Property::Host));

// Wenn Kernel nicht fertig, dann nix machen und darauf warten
if (IPS_GetKernelRunlevel() != KR_READY) {
$this->RegisterMessage(0, IPS_KERNELSTARTED);
return;
}
if ((!$this->ReadPropertyBoolean(\Xiaomi\Device\Property::Active)) || (!$this->ReadPropertyString(\Xiaomi\Device\Property::Host))) {
$this->SetStatus(IS_INACTIVE);
return;
}
if (!$this->ReadPropertyString(\Xiaomi\Device\Property::DeviceId)) {
$this->SetStatus(\Xiaomi\Device\InstanceStatus::ConfigError);
return;
}
if (!$this->ReadAttributeString(\Xiaomi\Device\Attribute::Token)) {
// Kein Token -> Token aus Cloud holen.
if (!$this->GetToken()) {
$this->SetStatus(\Xiaomi\Device\InstanceStatus::GetTokenFailed);
return;
}
}
if (!$this->SendHandshake()) {
return;
}

// Info Paket abholen mit model
if (!$this->GetModelData()) {
$this->SetStatus(\Xiaomi\Device\InstanceStatus::GetSpecsFailed);
return;
}
$this->CreateStateVariables();
$this->SetStatus(IS_ACTIVE);
if ($this->ReadPropertyBoolean(\Xiaomi\Device\Property::ForceCloud)) {
$this->WriteAttributeBoolean(\Xiaomi\Device\Attribute::useCloud, true);
} else {
$this->WriteAttributeBoolean(\Xiaomi\Device\Attribute::useCloud, false);
}
if ($this->ReadAttributeBoolean(\Xiaomi\Device\Attribute::useCloud)) { //cloud an -> nur ein Versuch
if (!$this->RequestState()) {
$this->SetStatus(\Xiaomi\Device\InstanceStatus::InCloudOffline);
return;
}
} else {
if (!$this->RequestState()) { // wenn erster Versuch fehlschlägt
if ($this->ReadPropertyBoolean(\Xiaomi\Device\Property::DeniedCloud)) { // und Cloud verboten
$this->SetStatus(\Xiaomi\Device\InstanceStatus::TimeoutError);
return;
}
$this->WriteAttributeBoolean(\Xiaomi\Device\Attribute::useCloud, true); // umschalten auf Cloud
if (!$this->RequestState()) {
$this->SetStatus(\Xiaomi\Device\InstanceStatus::InCloudOffline);
return;
}
}
}

$this->LogMessage($this->Translate('Connection established'), KL_MESSAGE);
$this->SetTimerInterval(\Xiaomi\Device\Timer::RefreshState, $this->ReadPropertyInteger(\Xiaomi\Device\Property::RefreshInterval) * 1000);
$this->InitConnection();
}

public function MessageSink($TimeStamp, $SenderID, $Message, $Data)
Expand Down Expand Up @@ -207,9 +148,7 @@ public function RequestAction($Ident, $Value)
$this->WriteAttributeArray(\Xiaomi\Device\Attribute::ParamIdentsRead, []);
$this->WriteAttributeArray(\Xiaomi\Device\Attribute::ParamIdentsWrite, []);
// Neu laden von allen Einstellungen und Attributen
IPS_RunScriptText('IPS_Applychanges(' . $this->InstanceID . ');');
return;
case 'ReloadForm':
$this->InitConnection();
$this->ReloadForm();
return;
case 'VariablePanel':
Expand Down Expand Up @@ -489,11 +428,74 @@ protected function SetStatus($State)
parent::SetStatus($State);
}

private function InitConnection()
{
$this->SetTimerInterval(\Xiaomi\Device\Timer::RefreshState, 0);
$this->SetTimerInterval(\Xiaomi\Device\Timer::Reconnect, 0);
$this->ServerStamp = 0;
$this->ServerStampTime = 0;
$this->Retries = 2;
// Anzeige IP in der INFO Spalte
$this->SetSummary($this->ReadPropertyString(\Xiaomi\Device\Property::Host));

if ((!$this->ReadPropertyBoolean(\Xiaomi\Device\Property::Active)) || (!$this->ReadPropertyString(\Xiaomi\Device\Property::Host))) {
$this->SetStatus(IS_INACTIVE);
return;
}
if (!$this->ReadPropertyString(\Xiaomi\Device\Property::DeviceId)) {
$this->SetStatus(\Xiaomi\Device\InstanceStatus::ConfigError);
return;
}
if (!$this->ReadAttributeString(\Xiaomi\Device\Attribute::Token)) {
// Kein Token -> Token aus Cloud holen.
if (!$this->GetToken()) {
$this->SetStatus(\Xiaomi\Device\InstanceStatus::GetTokenFailed);
return;
}
}
if (!$this->SendHandshake()) {
return;
}

// Info Paket abholen mit model
if (!$this->GetModelData()) {
$this->SetStatus(\Xiaomi\Device\InstanceStatus::GetSpecsFailed);
return;
}
$this->CreateStateVariables();
$this->SetStatus(IS_ACTIVE);
if ($this->ReadPropertyBoolean(\Xiaomi\Device\Property::ForceCloud)) {
$this->WriteAttributeBoolean(\Xiaomi\Device\Attribute::useCloud, true);
} else {
$this->WriteAttributeBoolean(\Xiaomi\Device\Attribute::useCloud, false);
}
if ($this->ReadAttributeBoolean(\Xiaomi\Device\Attribute::useCloud)) { //cloud an -> nur ein Versuch
if (!$this->RequestState()) {
$this->SetStatus(\Xiaomi\Device\InstanceStatus::InCloudOffline);
return;
}
} else {
if (!$this->RequestState()) { // wenn erster Versuch fehlschlägt
if ($this->ReadPropertyBoolean(\Xiaomi\Device\Property::DeniedCloud)) { // und Cloud verboten
$this->SetStatus(\Xiaomi\Device\InstanceStatus::TimeoutError);
return;
}
$this->WriteAttributeBoolean(\Xiaomi\Device\Attribute::useCloud, true); // umschalten auf Cloud
if (!$this->RequestState()) {
$this->SetStatus(\Xiaomi\Device\InstanceStatus::InCloudOffline);
return;
}
}
}

$this->LogMessage($this->Translate('Connection established'), KL_MESSAGE);
$this->SetTimerInterval(\Xiaomi\Device\Timer::RefreshState, $this->ReadPropertyInteger(\Xiaomi\Device\Property::RefreshInterval) * 1000);
}

private function KernelReady()
{
$this->UnregisterMessage(0, IPS_KERNELSTARTED);
// Wenn Kernel fertig, dann machen wir da im Applychanges weiter, wo wir vorher abgebrochen haben.
$this->ApplyChanges();
$this->InitConnection();
}

private function SendLocal(string $Method, array $Prams = []): ?array
Expand Down Expand Up @@ -923,8 +925,6 @@ private function GetModelData(): bool
$this->WriteAttributeArray(\Xiaomi\Device\Attribute::Specs, $Specs['props']['spec']);
// Wenn nicht vorhanden, dann geht auch nicht das get/set_properties + siid/piid Protokoll
$this->loadLocale($Specs['props']['spec']['urn']);
// Form verzögert neu laden, da die Attribute erst in CreateStateVariables gefüllt werden.
IPS_RunScriptText('IPS_Sleep(500);IPS_RequestAction(' . $this->InstanceID . ',"ReloadForm",true);');
return true;
}

Expand Down

0 comments on commit d3110ed

Please sign in to comment.