-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfloatDevice.php
More file actions
118 lines (92 loc) · 2.92 KB
/
floatDevice.php
File metadata and controls
118 lines (92 loc) · 2.92 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
<?php
declare(strict_types=1);
trait HelperGetFloatDevice
{
private static function getGetFloatCompatibility($variableID)
{
if (!IPS_VariableExists($variableID)) {
return 'Missing';
}
$targetVariable = IPS_GetVariable($variableID);
if ($targetVariable['VariableType'] != 2 /* Float */) {
return 'Float required';
}
return 'OK';
}
private static function getFloatValue($variableID)
{
if (!IPS_VariableExists($variableID)) {
return false;
}
$targetVariable = IPS_GetVariable($variableID);
$legacyValue = function ($profileName) use (&$value)
{
if ($profileName != '') {
$profile = IPS_GetVariableProfile($profileName);
$value = round($value, $profile['Digits']);
}
};
$value = GetValue($variableID);
if (!function_exists('IPS_GetVariablePresentation')) {
$profileName = '';
if ($targetVariable['VariableCustomProfile'] != '') {
$profileName = $targetVariable['VariableCustomProfile'];
} else {
$profileName = $targetVariable['VariableProfile'];
}
return $value;
} else {
$presentation = IPS_GetVariablePresentation($variableID);
switch ($presentation['PRESENTATION'] ?? 'No presentation') {
case VARIABLE_PRESENTATION_LEGACY:
$legacyValue($presentation['PROFILE']);
break;
case VARIABLE_PRESENTATION_SLIDER:
$value = round($value, $presentation['DIGITS']);
break;
default:
break;
}
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;
}
if (!(is_int($value) || is_float($value))) {
return false;
}
return RequestActionEx($variableID, $value, 'VoiceControl');
}
}
trait HelperFloatDevice
{
use HelperSetFloatDevice;
use HelperGetFloatDevice;
}