initial commit

This commit is contained in:
jhartworks committed 2026-10-21 13:12:13 +02:00
commit faa518ccd8
10 files changed
+704

No files matched your search

+81
View File
@@ -0,0 +1,81 @@
<?php
class EnergyCounterChild extends IPSModule
{
private const ENERGY_PROFILE = 'EnergyCounter.kWh';
private const COST_PROFILE = 'EnergyCounter.EUR';
public function Create()
{
parent::Create();
// Diese Eigenschaften werden vom Hauptmodul verwaltet und absichtlich
// nicht im Formular angeboten. Die Childinstanz bleibt reine Anzeige.
$this->RegisterPropertyInteger('ParentInstanceID', 0);
$this->RegisterPropertyString('CounterKey', '');
$this->RegisterPropertyBoolean('ShowTotalEnergy', true);
$this->RegisterPropertyBoolean('ShowTotalCost', true);
$this->RegisterPropertyBoolean('ShowDayEnergy', true);
$this->RegisterPropertyBoolean('ShowDayCost', true);
$this->RegisterPropertyBoolean('ShowMonthEnergy', true);
$this->RegisterPropertyBoolean('ShowMonthCost', true);
$this->EnsureProfiles();
$this->RegisterValueVariables();
}
public function ApplyChanges()
{
parent::ApplyChanges();
$this->EnsureProfiles();
$this->RegisterValueVariables();
$this->ApplyVisibility();
$this->SetStatus(102);
}
private function RegisterValueVariables()
{
$this->RegisterVariableFloat('TotalEnergy', $this->Translate('Total Energy'), self::ENERGY_PROFILE, 10);
$this->RegisterVariableFloat('TotalCost', $this->Translate('Total Cost'), self::COST_PROFILE, 20);
$this->RegisterVariableFloat('DayEnergy', $this->Translate('Daily Energy'), self::ENERGY_PROFILE, 30);
$this->RegisterVariableFloat('DayCost', $this->Translate('Daily Cost'), self::COST_PROFILE, 40);
$this->RegisterVariableFloat('MonthEnergy', $this->Translate('Monthly Energy'), self::ENERGY_PROFILE, 50);
$this->RegisterVariableFloat('MonthCost', $this->Translate('Monthly Cost'), self::COST_PROFILE, 60);
}
private function ApplyVisibility()
{
$visibility = [
'TotalEnergy' => $this->ReadPropertyBoolean('ShowTotalEnergy'),
'TotalCost' => $this->ReadPropertyBoolean('ShowTotalCost'),
'DayEnergy' => $this->ReadPropertyBoolean('ShowDayEnergy'),
'DayCost' => $this->ReadPropertyBoolean('ShowDayCost'),
'MonthEnergy' => $this->ReadPropertyBoolean('ShowMonthEnergy'),
'MonthCost' => $this->ReadPropertyBoolean('ShowMonthCost')
];
foreach ($visibility as $ident => $visible) {
$variableID = $this->GetIDForIdent($ident);
if ($variableID > 0) {
IPS_SetHidden($variableID, !$visible);
}
}
}
private function EnsureProfiles()
{
if (!IPS_VariableProfileExists(self::ENERGY_PROFILE)) {
IPS_CreateVariableProfile(self::ENERGY_PROFILE, 2);
IPS_SetVariableProfileText(self::ENERGY_PROFILE, '', ' kWh');
IPS_SetVariableProfileDigits(self::ENERGY_PROFILE, 3);
}
if (!IPS_VariableProfileExists(self::COST_PROFILE)) {
IPS_CreateVariableProfile(self::COST_PROFILE, 2);
IPS_SetVariableProfileText(self::COST_PROFILE, '', ' €');
IPS_SetVariableProfileDigits(self::COST_PROFILE, 2);
}
}
}