Skip to content

Commit

Permalink
no message
Browse files Browse the repository at this point in the history
  • Loading branch information
Nall-chan committed Dec 27, 2023
1 parent 93af8b9 commit e00b050
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 32 deletions.
2 changes: 1 addition & 1 deletion ClimacontrolRegulator/module.php
Expand Up @@ -29,7 +29,7 @@ class HomeMaticClimateControlRegulator extends HMHeatingDevice
protected const WeekScheduleIndexEndTime = 'TIMEOUT_%2$s_%1$d';
protected const NumberOfTimeSlot = 24;
protected const ProtocolId = 0;

//################# PUBLIC

/**
Expand Down
8 changes: 4 additions & 4 deletions PowerMeter/module.php
Expand Up @@ -110,15 +110,15 @@ private function SetNewConfig()
$this->HMDeviceDatapoint = '';
$this->HMProtocol = \HMExtended\CCU::BidCos_RF;
$this->Event = 0;
$this->SetReceiveDataFilter('.*9999999999.*');
$this->SetReceiveDataFilter('.*9999999999.*');
$this->SetSummary('');
return;
}
if ($this->CheckConfig()) {
$HMDeviceDatapoint = $this->HMDeviceDatapoint;
$this->SetReceiveDataFilter('.*"DeviceID":"' . $this->HMDeviceAddress . '","VariableName":"' . $HMDeviceDatapoint . '".*');

switch ($HMDeviceDatapoint) {
switch ($HMDeviceDatapoint) {
case 'GAS_ENERGY_COUNTER':
$Profil = '~Gas';

Expand Down Expand Up @@ -232,8 +232,8 @@ private function GetPowerAddress(int $EventID)
*/
private function ReadPowerSysVar()
{
$HMDeviceDatapoint = $this->HMDeviceDatapoint;
switch ($HMDeviceDatapoint) {
$HMDeviceDatapoint = $this->HMDeviceDatapoint;
switch ($HMDeviceDatapoint) {
case 'GAS_ENERGY_COUNTER':
$Suffix = 'Gas';
$Factor = 1;
Expand Down
7 changes: 5 additions & 2 deletions libs/HMBase.php
Expand Up @@ -17,6 +17,7 @@
eval('declare(strict_types=1);namespace HMExtended {?>' . file_get_contents(__DIR__ . '/helper/ParentIOHelper.php') . '}');
eval('declare(strict_types=1);namespace HMExtended {?>' . file_get_contents(__DIR__ . '/helper/VariableHelper.php') . '}');
eval('declare(strict_types=1);namespace HMExtended {?>' . file_get_contents(__DIR__ . '/helper/VariableProfileHelper.php') . '}');
eval('declare(strict_types=1);namespace HMExtended {?>' . file_get_contents(__DIR__ . '/helper/AttributeArrayHelper.php') . '}');
require_once __DIR__ . '/HMTypes.php'; // HMTypes Data

/**
Expand All @@ -28,16 +29,18 @@
* @method bool SendDebug(string $Message, mixed $Data, int $Format)
* @method void RegisterProfileEx(int $VarTyp, string $Name, string $Icon, string $Prefix, string $Suffix, array $Associations, float $MaxValue = -1, float $StepSize = 0, int $Digits = 0)
* @method void RegisterProfileIntegerEx(string $Name, string $Icon, string $Prefix, string $Suffix, array $Associations, float $MaxValue = -1, float $StepSize = 0)
*
* @method void UnregisterProfile(string $Profile)
*
* @method void RegisterAttributeArray(string $name, array $Value, int $Size = 0)
* @method array ReadAttributeArray(string $name)
* @method void WriteAttributeArray(string $name, array $value)
*/
abstract class HMBase extends IPSModule
{
use \HMExtended\DebugHelper,
\HMExtended\VariableHelper,
\HMExtended\VariableProfileHelper,
\HMExtended\BufferHelper,
\HMExtended\AttributeArrayHelper,
\HMExtended\InstanceStatus {
\HMExtended\InstanceStatus::RegisterParent as IORegisterParent;
\HMExtended\InstanceStatus::MessageSink as IOMessageSink;
Expand Down
51 changes: 26 additions & 25 deletions libs/HMHeatingDevice.php
Expand Up @@ -87,7 +87,7 @@ public function Create()
[25, 0xE60000],
[30, 0xFF0000],
];
$this->RegisterAttributeString('ScheduleColors', json_encode($ScheduleTempsInit));
$this->RegisterAttributeArray('ScheduleColors', $ScheduleTempsInit);

$this->WeekSchedules = [];
$this->WeekProfile = 1;
Expand Down Expand Up @@ -201,7 +201,7 @@ public function RequestAction($Ident, $Value)
$this->WeekProfile = (int) $Value;
$this->SendDebug(__FUNCTION__, '', 0);
$this->SendDebug('ActivePlan', $Value, 0);
$this->RefreshScheduleObject();
$this->RefreshScheduleObject(true);
}
break;
}
Expand Down Expand Up @@ -263,7 +263,7 @@ protected function SetVariable(string $Ident, $Value)
$this->WeekProfile = (int) $Value;
$this->SendDebug(__FUNCTION__, '', 0);
$this->SendDebug('ActivePlan', $Value, 0);
$this->RefreshScheduleObject();
$this->RefreshScheduleObject(true);
}
}
parent::SetVariable($Ident, $Value);
Expand All @@ -279,16 +279,13 @@ protected function SetParamVariables(array $Params)
for ($Slot = 1; $Slot <= static::NumberOfTimeSlot; $Slot++) {
$TimeIndex = sprintf(static::WeekScheduleIndexEndTime, $Slot, $Day, $Plan);
$TempIndex = sprintf(static::WeekScheduleIndexTemp, $Slot, $Day, $Plan);
$Time = $Params[$TimeIndex];
$Temp = $Params[$TempIndex];
$this->SendDebug($TimeIndex, $Time, 0);
$this->SendDebug($TempIndex, $Temp, 0);
$this->SendDebug($TempIndex, gettype($Temp), 0);
$ScheduleData[$Plan][$Index][$Slot][self::TIME] = (int) $Time;
$ScheduleData[$Plan][$Index][$Slot][self::TEMP] = (float) $Temp;
if (!array_key_exists((int) $Temp, $ScheduleTemps)) {
$Color = $this->GetNextColor((float) $Temp, $ScheduleData);
$ScheduleTemps[$Params[$TempIndex]] = $Color;
$Time = (int) $Params[$TimeIndex];
$Temp = (float) $Params[$TempIndex];
$ScheduleData[$Plan][$Index][$Slot][self::TIME] = $Time;
$ScheduleData[$Plan][$Index][$Slot][self::TEMP] = $Temp;
if (!in_array($Temp, $ScheduleTemps)) {
$Color = $this->GetNextColor($Temp, $ScheduleTemps);
$ScheduleTemps[$Color] = $Temp;
$ScheduleActionHasChanged = true;
}
unset($Params[$TimeIndex]);
Expand All @@ -298,7 +295,7 @@ protected function SetParamVariables(array $Params)
}
if ($ScheduleActionHasChanged) {
// todo wenn array zu groß war, Meldung ausgeben.
ksort($ScheduleTemps);
asort($ScheduleTemps);
$ScheduleTemps = array_slice($ScheduleTemps, 0, 32, true);
$this->SetTempColorsAttribute($ScheduleTemps);
}
Expand Down Expand Up @@ -373,6 +370,7 @@ private function RefreshScheduleObject(bool $ScheduleActionHasChanged = false)
}
}
$Actions = $this->UpdateScheduleActions($Event, $ScheduleActionHasChanged);
$this->SendDebug('Actions', $Actions, 0);
if (static::SelectedWeekScheduleIdent) {
$ActivePlan = $this->WeekProfile;
} else {
Expand All @@ -385,6 +383,9 @@ private function RefreshScheduleObject(bool $ScheduleActionHasChanged = false)
$StartMinute = 0;
foreach ($ScheduleData[$Group['Days']] as $PointId => $Slot) {
$ActionId = array_search($Slot[self::TEMP], $Actions);
if ($ActionId === false) {
$this->SendDebug('not found', $Slot[self::TEMP], 0);
}
IPS_SetEventScheduleGroupPoint($EventId, $Group['ID'], $PointId, $StartHour, $StartMinute, 0, $ActionId);
if ($Slot[self::TIME] == 1440) {
break;
Expand Down Expand Up @@ -441,7 +442,7 @@ private function SaveSchedule(int $Plan)
}
$this->SendDebug('ActivePlan', $ActivePlan, 0);
if ($ActivePlan != $Plan) {
$this->RefreshScheduleObject();
$this->RefreshScheduleObject(true);
}
}

Expand Down Expand Up @@ -586,14 +587,15 @@ private function UpdateScheduleActions(array $Event, bool $ScheduleActionHasChan
IPS_SetEventScheduleAction($Event['EventID'], $Action['ID'], '', 0, '');
}
$i = 0;
foreach ($ScheduleActionColors as $Temp => $Color) {
foreach ($ScheduleActionColors as $Color => $Temp) {
IPS_SetEventScheduleAction($Event['EventID'], $i++, sprintf('%0.1f °C', $Temp), $Color, "/** Do not edit this code,\r\n It will be automatically overwritten.\r\n*/\r\n\r\n" . 'HM_RequestParams($_IPS[\'TARGET\']);');
if ($i == 32) {
break;
}
}
}
return array_keys($ScheduleActionColors);
$this->SendDebug(__FUNCTION__, $ScheduleActionColors, 0);
return array_values($ScheduleActionColors);
}

private function CreateWeekPlan()
Expand All @@ -616,28 +618,27 @@ private function CreateWeekPlan()

private function SetTempColorsAttribute(array $Values)
{
ksort($Values);
foreach ($Values as $Temp => $Color) {
foreach ($Values as $Color => $Temp) {
$ScheduleTemps[] = [$Temp, $Color];
}
$this->WriteAttributeString('ScheduleColors', json_encode($ScheduleTemps));
$this->WriteAttributeArray('ScheduleColors', $ScheduleTemps);
}

private function GetTempColorsAttribute()
{
$Values = [];
$ScheduleTemps = json_decode($this->ReadAttributeString('ScheduleColors'), true);
$ScheduleTemps = $this->ReadAttributeArray('ScheduleColors');
foreach ($ScheduleTemps as $TempColor) {
$Values[$TempColor[0]] = $TempColor[1];
$Values[$TempColor[1]] = $TempColor[0];
}
ksort($Values);
asort($Values);
return $Values;
}

private function GetNextColor(float $Temp, $Colors)
private function GetNextColor(float $Temp, array $Colors)
{
$Found = 0x000080;
foreach ($Colors as $TempColor => $Color) {
foreach ($Colors as $Color => $TempColor) {
if ($TempColor < $Temp) {
if ($Color > 0x010101) {
$Found = $Color - 0x010101;
Expand Down

0 comments on commit e00b050

Please sign in to comment.