Repository navigation
Expand file tree
/
Copy pathfloatDevice.php
More file actions
88 lines (66 loc) · 1.94 KB
/
Copy pathfloatDevice.php
File metadata and controls
88 lines (66 loc) · 1.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<?php
declare(strict_types=1);
include_once __DIR__ . '/variablePresentation.php';
trait HelperGetFloatDevice
{
use HelperVariablePresentation;
private static function getGetFloatCompatibility($variableID)
{
if (!IPS_VariableExists($variableID)) {
return 'Missing';
}
$targetVariable = IPS_GetVariable($variableID);
if ($targetVariable['VariableType'] != VARIABLETYPE_FLOAT) {
return 'Float required';
}
return 'OK';
}
private static function getFloatValue($variableID)
{
if (!IPS_VariableExists($variableID)) {
return false;
}
$value = GetValue($variableID);
$presentation = self::resolvePresentation($variableID);
if (($presentation !== false) && ($presentation['digits'] !== null)) {
$value = round($value, $presentation['digits']);
}
return $value;
}
}
trait HelperSetFloatDevice
{
private static function getFloatCompatibility($variableID)
{
if (!IPS_VariableExists($variableID)) {
return 'Missing';
}
$targetVariable = IPS_GetVariable($variableID);
if ($targetVariable['VariableType'] != VARIABLETYPE_FLOAT) {
return 'Float required';
}
if (!HasAction($variableID)) {
return 'Action required';
}
return 'OK';
}
private static function setFloatValue($variableID, $value)
{
if (!IPS_VariableExists($variableID)) {
return false;
}
$targetVariable = IPS_GetVariable($variableID);
if (!HasAction($variableID)) {
return false;
}
if ($targetVariable['VariableType'] != VARIABLETYPE_FLOAT) {
return false;
}
return RequestActionEx($variableID, $value, 'VoiceControl');
}
}
trait HelperFloatDevice
{
use HelperSetFloatDevice;
use HelperGetFloatDevice;
}