no message
This commit is contained in:
@@ -7,6 +7,6 @@
|
||||
"prefix": "VGT",
|
||||
"parentRequirements": [],
|
||||
"childRequirements": [],
|
||||
"implemented": ["{018EF6B5-AB94-40C6-AA53-46943E824ACF}"],
|
||||
"implemented": [],
|
||||
"version": "1.0"
|
||||
}
|
||||
|
||||
@@ -7,8 +7,14 @@ class VGT_Sub extends IPSModule
|
||||
public function Create()
|
||||
{
|
||||
parent::Create();
|
||||
|
||||
$this->RegisterPropertyString('DeviceID', '');
|
||||
|
||||
$this->RegisterVariableString("InputJSON", "MQTT Input", "", 1);
|
||||
$this->EnableAction("InputJSON");
|
||||
|
||||
$this->RegisterVariableString("OutputJSON", "MQTT Output", "", 2);
|
||||
|
||||
$this->RegisterVariableFloat('PowerProduction', 'Power Production', '', 10);
|
||||
$this->EnableAction('PowerProduction');
|
||||
|
||||
@@ -34,30 +40,38 @@ class VGT_Sub extends IPSModule
|
||||
IPS_SetVariableCustomAction($this->GetIDForIdent('Strategy'), 0);
|
||||
}
|
||||
|
||||
public function ForwardData($JSONString)
|
||||
public function RequestAction($Ident, $Value)
|
||||
{
|
||||
$data = json_decode($JSONString, true);
|
||||
|
||||
if (!isset($data['Topic']) || !isset($data['Payload'])) {
|
||||
return '';
|
||||
if ($Ident === "InputJSON") {
|
||||
$this->ProcessIncoming($Value);
|
||||
return;
|
||||
}
|
||||
|
||||
$topic = $data['Topic'];
|
||||
$payload = $data['Payload'];
|
||||
SetValue($this->GetIDForIdent($Ident), $Value);
|
||||
}
|
||||
|
||||
private function ProcessIncoming($jsonString)
|
||||
{
|
||||
$data = @json_decode($jsonString, true);
|
||||
if (!is_array($data) || !isset($data['topic']) || !isset($data['payload'])) {
|
||||
return;
|
||||
}
|
||||
|
||||
$topic = $data['topic'];
|
||||
$payload = $data['payload'];
|
||||
|
||||
$device = $this->ReadPropertyString('DeviceID');
|
||||
|
||||
if ($topic === "feedback-request/$device") {
|
||||
$this->handleFeedback($device);
|
||||
$this->SendFeedback($device);
|
||||
}
|
||||
|
||||
if ($topic === "remote-control-request/$device") {
|
||||
$this->handleRemote($device, $payload);
|
||||
$this->ProcessRemote($device, $payload);
|
||||
}
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
private function handleFeedback($device)
|
||||
private function SendFeedback($device)
|
||||
{
|
||||
$response = [
|
||||
"power_production" => GetValue($this->GetIDForIdent('PowerProduction')),
|
||||
@@ -68,39 +82,37 @@ class VGT_Sub extends IPSModule
|
||||
"max_soc" => GetValue($this->GetIDForIdent('MaxSoc'))
|
||||
];
|
||||
|
||||
$this->publish("feedback-response/$device", json_encode($response));
|
||||
SetValueString(
|
||||
$this->GetIDForIdent("OutputJSON"),
|
||||
json_encode([
|
||||
"topic" => "feedback-response/$device",
|
||||
"payload" => json_encode($response)
|
||||
])
|
||||
);
|
||||
}
|
||||
|
||||
private function handleRemote($device, $payload)
|
||||
private function ProcessRemote($device, $payload)
|
||||
{
|
||||
$in = json_decode($payload, true);
|
||||
if (!is_array($in)) {
|
||||
$json = @json_decode($payload, true);
|
||||
if (!is_array($json)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (isset($in['power_setpoint'])) {
|
||||
SetValue($this->GetIDForIdent('PowerSetpoint'), (int)$in['power_setpoint']);
|
||||
if (isset($json['power_setpoint'])) {
|
||||
SetValue($this->GetIDForIdent('PowerSetpoint'), (int)$json['power_setpoint']);
|
||||
}
|
||||
|
||||
if (isset($in['strategy'])) {
|
||||
SetValueString($this->GetIDForIdent('Strategy'), (string)$in['strategy']);
|
||||
if (isset($json['strategy'])) {
|
||||
SetValueString($this->GetIDForIdent('Strategy'), (string)$json['strategy']);
|
||||
}
|
||||
|
||||
$this->publish("remote-control-response/$device", json_encode($in));
|
||||
}
|
||||
|
||||
private function publish($topic, $payload)
|
||||
{
|
||||
$this->SendDataToParent(json_encode([
|
||||
"DataID" => "{018EF6B5-AB94-40C6-AA53-46943E824ACF}",
|
||||
"Topic" => $topic,
|
||||
"Payload" => $payload
|
||||
]));
|
||||
}
|
||||
|
||||
public function RequestAction($Ident, $Value)
|
||||
{
|
||||
SetValue($this->GetIDForIdent($Ident), $Value);
|
||||
SetValueString(
|
||||
$this->GetIDForIdent("OutputJSON"),
|
||||
json_encode([
|
||||
"topic" => "remote-control-response/$device",
|
||||
"payload" => json_encode($json)
|
||||
])
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user