fixed renaming

This commit is contained in:
jhartworks committed 2026-11-05 11:04:36 +01:00
1 parent 9ddef51789
commit b2bc44c0c5
2 files changed
+107 -35

No files matched your search

+106 -35
View File
@@ -13,30 +13,13 @@ class Multialarmer extends IPSModule
$this->EnsureLimitEnProfile();
$this->RegisterProperties();
$this->RegisterRecipientVariables();
$this->RegisterAlarmVariables();
$this->RegisterPropertyInteger('ValueId01', 0);
$this->RegisterPropertyInteger('ValueId02', 0);
$this->RegisterPropertyInteger('ValueId03', 0);
$this->RegisterPropertyInteger('ValueId04', 0);
$this->RegisterVariableBoolean('NotifyEn01', 'Variable 01 Melden?', 'LimitEn', 95);
$this->EnableAction('NotifyEn01');
$this->RegisterVariableBoolean('NotifyEn02', 'Variable 02 Melden?', 'LimitEn', 115);
$this->EnableAction('NotifyEn02');
$this->RegisterVariableBoolean('NotifyEn03', 'Variable 03 Melden?', 'LimitEn', 135);
$this->EnableAction('NotifyEn03');
$this->RegisterVariableBoolean('NotifyEn04', 'Variable 04 Melden?', 'LimitEn', 155);
$this->EnableAction('NotifyEn04');
SetValue($this->RegisterVariableString('NotifyTitel01', 'Titel der Benachrichtigung Var 01', '~TextBox', 100), 'Störung!');
$this->EnableAction('NotifyTitel01');
SetValue($this->RegisterVariableString('NotifyTitel02', 'Titel der Benachrichtigung Var 02', '~TextBox', 120), 'Störung!');
$this->EnableAction('NotifyTitel02');
SetValue($this->RegisterVariableString('NotifyTitel03', 'Titel der Benachrichtigung Var 03', '~TextBox', 140), 'Störung!');
$this->EnableAction('NotifyTitel03');
SetValue($this->RegisterVariableString('NotifyTitel04', 'Titel der Benachrichtigung Var 04', '~TextBox', 160), 'Störung!');
$this->EnableAction('NotifyTitel04');
$this->RegisterTimer('Update', 0, 'VTMA_checkValues(' . $this->InstanceID . ');');
}
@@ -44,13 +27,15 @@ class Multialarmer extends IPSModule
{
$this->EnsureLimitEnProfile();
// Ensure that existing Multialarmer instances also receive the
// recipient variables after the module update.
// Ensure that existing Multialarmer instances also receive newly
// added status variables without changing manually assigned names.
$this->RegisterRecipientVariables();
$this->RegisterAlarmVariables();
parent::ApplyChanges();
$this->UpdateRecipientVisibility();
$this->UpdateAlarmVariableVisibility();
$this->SetTimerInterval('Update', 5 * 1000);
}
@@ -81,24 +66,28 @@ class Multialarmer extends IPSModule
$NotifyEn04 = GetValue($this->GetIDForIdent('NotifyEn04'));
$NotifyTitel01 = GetValue($this->GetIDForIdent('NotifyTitel01'));
$NotifyText01 = $this->GetNotificationText('NotifyText01', $IdVariable01);
$NotifyTitel02 = GetValue($this->GetIDForIdent('NotifyTitel02'));
$NotifyText02 = $this->GetNotificationText('NotifyText02', $IdVariable02);
$NotifyTitel03 = GetValue($this->GetIDForIdent('NotifyTitel03'));
$NotifyText03 = $this->GetNotificationText('NotifyText03', $IdVariable03);
$NotifyTitel04 = GetValue($this->GetIDForIdent('NotifyTitel04'));
$NotifyText04 = $this->GetNotificationText('NotifyText04', $IdVariable04);
if ($NotifyEn01 === true && $IdVariable01 > 0) {
$this->notify($IdVariable01, $webId, $IdVariable01, $NotifyTitel01, IPS_GetName($IdVariable01), 'Flame');
if ($NotifyEn01 === true && $this->IsConfiguredAlarmVariable($IdVariable01)) {
$this->notify($IdVariable01, $webId, $IdVariable01, $NotifyTitel01, $NotifyText01, 'Flame');
}
if ($NotifyEn02 === true && $IdVariable02 > 0) {
$this->notify($IdVariable02, $webId, $IdVariable02, $NotifyTitel02, IPS_GetName($IdVariable02), 'Flame');
if ($NotifyEn02 === true && $this->IsConfiguredAlarmVariable($IdVariable02)) {
$this->notify($IdVariable02, $webId, $IdVariable02, $NotifyTitel02, $NotifyText02, 'Flame');
}
if ($NotifyEn03 === true && $IdVariable03 > 0) {
$this->notify($IdVariable03, $webId, $IdVariable03, $NotifyTitel03, IPS_GetName($IdVariable03), 'Flame');
if ($NotifyEn03 === true && $this->IsConfiguredAlarmVariable($IdVariable03)) {
$this->notify($IdVariable03, $webId, $IdVariable03, $NotifyTitel03, $NotifyText03, 'Flame');
}
if ($NotifyEn04 === true && $IdVariable04 > 0) {
$this->notify($IdVariable04, $webId, $IdVariable04, $NotifyTitel04, IPS_GetName($IdVariable04), 'Flame');
if ($NotifyEn04 === true && $this->IsConfiguredAlarmVariable($IdVariable04)) {
$this->notify($IdVariable04, $webId, $IdVariable04, $NotifyTitel04, $NotifyText04, 'Flame');
}
}
@@ -129,6 +118,7 @@ class Multialarmer extends IPSModule
{
$this->RegisterPropertyInteger('VisuId', 0);
$this->RegisterPropertyInteger('MailerId', 0);
$this->RegisterPropertyBoolean('AppendVariableName', true);
// MailAddresses remains as the migration source for existing instances.
$this->RegisterPropertyString('MailAddresses', 'jh@se-inno.de, info@se-inno.de');
@@ -151,8 +141,7 @@ class Multialarmer extends IPSModule
private function RegisterRecipientVariables()
{
$mailRecipientsWereMissing = !@$this->GetIDForIdent('MailRecipients');
$mailRecipientsId = $this->RegisterVariableString('MailRecipients', 'E-Mail Empfänger', '~TextBox', 180);
$this->EnableAction('MailRecipients');
$mailRecipientsId = $this->RegisterEditableStringVariable('MailRecipients', 'E-Mail Empfänger', '~TextBox', 180, '');
// Existing MailAddresses configurations are transferred on the first
// registration. Both e-mail methods intentionally use this one list.
@@ -160,8 +149,49 @@ class Multialarmer extends IPSModule
SetValue($mailRecipientsId, $this->ReadPropertyString('MailAddresses'));
}
$this->RegisterVariableString('WhatsAppRecipients', 'WhatsApp Empfänger', '~TextBox', 190);
$this->EnableAction('WhatsAppRecipients');
$this->RegisterEditableStringVariable('WhatsAppRecipients', 'WhatsApp Empfänger', '~TextBox', 190, '');
}
private function RegisterAlarmVariables()
{
$this->RegisterEditableBooleanVariable('NotifyEn01', 'Variable 01 Melden?', 'LimitEn', 95);
$this->RegisterEditableStringVariable('NotifyTitel01', 'Titel der Benachrichtigung Var 01', '~TextBox', 100, 'Störung!');
$this->RegisterEditableStringVariable('NotifyText01', 'Meldungstext Var 01', '~TextBox', 110, '');
$this->RegisterEditableBooleanVariable('NotifyEn02', 'Variable 02 Melden?', 'LimitEn', 115);
$this->RegisterEditableStringVariable('NotifyTitel02', 'Titel der Benachrichtigung Var 02', '~TextBox', 120, 'Störung!');
$this->RegisterEditableStringVariable('NotifyText02', 'Meldungstext Var 02', '~TextBox', 130, '');
$this->RegisterEditableBooleanVariable('NotifyEn03', 'Variable 03 Melden?', 'LimitEn', 135);
$this->RegisterEditableStringVariable('NotifyTitel03', 'Titel der Benachrichtigung Var 03', '~TextBox', 140, 'Störung!');
$this->RegisterEditableStringVariable('NotifyText03', 'Meldungstext Var 03', '~TextBox', 150, '');
$this->RegisterEditableBooleanVariable('NotifyEn04', 'Variable 04 Melden?', 'LimitEn', 155);
$this->RegisterEditableStringVariable('NotifyTitel04', 'Titel der Benachrichtigung Var 04', '~TextBox', 160, 'Störung!');
$this->RegisterEditableStringVariable('NotifyText04', 'Meldungstext Var 04', '~TextBox', 170, '');
}
private function RegisterEditableBooleanVariable($ident, $name, $profile, $position)
{
$variableId = @$this->GetIDForIdent($ident);
if (!$variableId) {
$variableId = $this->RegisterVariableBoolean($ident, $name, $profile, $position);
}
$this->EnableAction($ident);
return $variableId;
}
private function RegisterEditableStringVariable($ident, $name, $profile, $position, $initialValue)
{
$variableId = @$this->GetIDForIdent($ident);
if (!$variableId) {
$variableId = $this->RegisterVariableString($ident, $name, $profile, $position);
SetValue($variableId, $initialValue);
}
$this->EnableAction($ident);
return $variableId;
}
private function UpdateRecipientVisibility()
@@ -177,6 +207,46 @@ class Multialarmer extends IPSModule
}
}
private function UpdateAlarmVariableVisibility()
{
$visibility = array(
1 => $this->IsConfiguredAlarmVariable($this->ReadPropertyInteger('ValueId01')),
2 => $this->IsConfiguredAlarmVariable($this->ReadPropertyInteger('ValueId02')),
3 => $this->IsConfiguredAlarmVariable($this->ReadPropertyInteger('ValueId03')),
4 => $this->IsConfiguredAlarmVariable($this->ReadPropertyInteger('ValueId04'))
);
foreach ($visibility as $number => $visible) {
foreach (array('NotifyEn', 'NotifyTitel', 'NotifyText') as $prefix) {
$variableId = @$this->GetIDForIdent($prefix . sprintf('%02d', $number));
if ($variableId > 0) {
IPS_SetHidden($variableId, !$visible);
}
}
}
}
private function GetNotificationText($textIdent, $sourceVariableId)
{
$textVariableId = @$this->GetIDForIdent($textIdent);
$message = $textVariableId > 0 ? GetValueString($textVariableId) : '';
if (!$this->ReadPropertyBoolean('AppendVariableName') || !$this->IsConfiguredAlarmVariable($sourceVariableId)) {
return $message;
}
$variableName = IPS_GetName($sourceVariableId);
if ($message === '') {
return $variableName;
}
return $message . "\n" . $variableName;
}
private function IsConfiguredAlarmVariable($variableId)
{
return $variableId > 0 && IPS_VariableExists($variableId);
}
private function sendMail($art, $smname)
{
if (!$this->ReadPropertyBoolean('SendInternalMail') && !$this->ReadPropertyBoolean('SendMailApi')) {
@@ -305,8 +375,9 @@ class Multialarmer extends IPSModule
private function notify($trigid, $webfrontid, $targetid, $art, $smname, $ico)
{
if (GetValueBoolean($trigid) === true && $this->GetBuffer($smname) === 'true') {
$this->SetBuffer($smname, 'false');
$bufferIdent = 'Alarm_' . $trigid;
if (GetValueBoolean($trigid) === true && $this->GetBuffer($bufferIdent) === 'true') {
$this->SetBuffer($bufferIdent, 'false');
if ($webfrontid > 0) {
VISU_PostNotification($webfrontid, $art, $smname, $ico, $targetid);
@@ -314,7 +385,7 @@ class Multialarmer extends IPSModule
$this->sendMail($art, $smname);
$this->sendWhatsApp($art, $smname);
} elseif (GetValueBoolean($trigid) === false) {
$this->SetBuffer($smname, 'true');
$this->SetBuffer($bufferIdent, 'true');
}
return GetValueBoolean($trigid);