ich habe ein Formular, mit einem Button, worüber ich eine Funktion aufrufen möchte. In meinem Modul würde ich die Funktion mit $this->SendMsg(DUOFERN_MSG_GET_ALL_DEVICES_STATUS) aufrufen. Die Konstante ist mit define(„DUOFERN_MSG_GET_ALL_DEVICES_STATUS“, „0DFF0F400000000000000000000000000000FFFFFF01“); definiert.
Gibt es eine bessere Lösung als über eine public Funktion und ohne Konstante zu gehen?
Da ich bisher noch keine Antwort bekommen habe, habe ich mir einen Workaround gebaut, der echt unschön ist, gibts da echt keine bessere Lösung? Gerade das man die Nachrichten nicht übersetzen kann, ohne eine eigene Methode zu schreiben, ist echt blöd…
// define onClick method for create instance button
$data['actions'][4]['onClick'] = <<< 'EOT'
// include library definitions
require_once(IPS_GetKernelDir() . DIRECTORY_SEPARATOR . "modules"
. DIRECTORY_SEPARATOR . "IPSDuoFern"
. DIRECTORY_SEPARATOR . "library.php");
// define helper function to translate
function Translate($string)
{
$translations = json_decode(file_get_contents(IPS_GetKernelDir()
. DIRECTORY_SEPARATOR . "modules"
. DIRECTORY_SEPARATOR . "IPSDuoFern"
. DIRECTORY_SEPARATOR . "DuoFernConfigurator"
. DIRECTORY_SEPARATOR . "locale.json"), true);
$translations = $translations["translations"]["de"];
// found translation
if (array_key_exists($string, $translations)) {
return $translations[$string];
}
// do not translate
return $string;
}
// check device has already an instance
if ($deviceList == null) {
echo Translate("No DuoFern device selected");
return;
}
// check device has already an instance
if ($deviceList['instanceId'] > 0) {
echo Translate("Instance already exists");
return;
}
// check invalid duo fern code
$duoFernCode = str_replace(' ', '', $deviceList['duoFernCode']);
if (!preg_match(DUOFERN_REGEX_DUOFERN_CODE, $duoFernCode)) {
trigger_error(Translate("Invalid DuoFern code (Format: XX XX XX with X = 0-9, A-F)") . PHP_EOL, E_USER_ERROR);
return;
}
// create instance
$instanceId = IPS_CreateInstance('{BE62B172-BABA-4EB1-8C4C-507526645ED5}');
if ($instanceId == false) {
trigger_error(Translate("Instance could not be created") . PHP_EOL, E_USER_ERROR);
return;
}
// connect instance to actual gateway if not connected
if (IPS_GetInstance($instanceId)['ConnectionID'] != IPS_GetInstance($id)['ConnectionID']) {
if (IPS_GetInstance($instanceId)['ConnectionID'] > 0) {
IPS_DisconnectInstance($instanceId);
}
IPS_ConnectInstance($instanceId, IPS_GetInstance($id)['ConnectionID']);
}
// set duo fern code property
@IPS_SetProperty($instanceId, 'duoFernCode', $duoFernCode);
@IPS_ApplyChanges($instanceId);
// set instance name
$instanceName = 'DuoFern ' . $deviceList['type'] . ' (' . $deviceList['duoFernCode'] . ')' ;
IPS_SetName($instanceId, $instanceName);
echo Translate("Instance created") . ": " . $instanceName;
EOT;