IPS_SetVariableProfileAssociation bei bool

Hallo,

ich habe eine Bool Variable die ich mit einem Profil versehen habe.
Das funktioniert auch super.


 $Name = 'TK.Test';
 IPS_CreateVariableProfile($Name, 0);
 IPS_SetVariableProfileAssociation($Name, false, 'off', '', 0xFF0000);
 IPS_SetVariableProfileAssociation($Name, true, 'on', '', 0x00FF00);

legt mir das Boolean Profil TK.Test an, und ich habe die Werte „off“ und „on“.

Wenn ich nun aber einen Unit Test schreibe bekomme ich den Fehler:
„TypeError: Argument 2 passed to IPS_SetVariableProfileAssociation() must be of the type float, bool given, called in…“
Und siehe da, die Doku sagt auch, dass es float sein muss.

Mach ich etwas falsch?
Oder sind Doku und Stub falsch?

Danke,
Thorsten

Die Doku ist richtig. Es muss tatsächlich ein float sein. Bin auch schon mal darüber gestolpert. Die Funktion ist für alle Profiltypen gültig, daher float.

Hallo,

das verstehe ich nicht.
Wenn ich ein Boolean habe, kann ich keinen float Wert mitgeben.
Oder wäre das dann 0 und 1?

Danke,
Thorsten

Jep.
0 und 1 ist ja sowohl int als auch float.
Alternativ:


 IPS_SetVariableProfileAssociation($Name, (float)0, 'off', '', 0xFF0000);
 IPS_SetVariableProfileAssociation($Name, (float)1, 'on', '', 0x00FF00);  

Oder gar so?
Alternativ:


 IPS_SetVariableProfileAssociation($Name, (float)false, 'off', '', 0xFF0000);
 IPS_SetVariableProfileAssociation($Name, (float)true, 'on', '', 0x00FF00);  

Michael

Hi,


 IPS_SetVariableProfileAssociation($Name, (float)false, 'off', '', 0xFF0000);
 IPS_SetVariableProfileAssociation($Name, (float)true, 'on', '', 0x00FF00);  

Damit geht es.
Sowohl produktiv, als auch um unittest.

Danke,
Thorsten

Sorry, hatte ich vergessen zu erwähnen: einfach casten:D

Durch

declare(strict_types=1);

muss man etwas genauer sein. Vorher hat es PHP im Verborgenen erledigt.

Burkhard

Das tritt auch nur bei tests auf, da hier ja das Symcon Backend durch PHP ‚simuliert‘ wird.
Die Funktion IPS_SetVariableProfileAssociation verarbeitet auch bei strict alle andere Typen im echten Symcon.
Michael