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); } } }