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