line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
######################################################################################### |
2
|
|
|
|
|
|
|
# Package HiPi::RF::OpenThings |
3
|
|
|
|
|
|
|
# Description : OpenThings protocol element naming |
4
|
|
|
|
|
|
|
# Copyright : Copyright (c) 2017 Mark Dootson |
5
|
|
|
|
|
|
|
# License : This is free software; you can redistribute it and/or modify it under |
6
|
|
|
|
|
|
|
# the same terms as the Perl 5 programming language system itself. |
7
|
|
|
|
|
|
|
######################################################################################### |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
package HiPi::RF::OpenThings; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
######################################################################################### |
12
|
|
|
|
|
|
|
|
13
|
1
|
|
|
1
|
|
7
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
27
|
|
14
|
1
|
|
|
1
|
|
12
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
27
|
|
15
|
1
|
|
|
1
|
|
4
|
use HiPi qw( :openthings :energenie ); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
1422
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
my $products = {}; |
19
|
|
|
|
|
|
|
my $manufacturers = {}; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
our $VERSION ='0.80'; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
for my $manutemplate |
24
|
|
|
|
|
|
|
( |
25
|
|
|
|
|
|
|
[ OPENTHINGS_MANUFACTURER_ENERGENIE, 'Energenie' ], |
26
|
|
|
|
|
|
|
[ OPENTHINGS_MANUFACTURER_HILDERBRAND, 'Hilderbrand' ], |
27
|
|
|
|
|
|
|
[ OPENTHINGS_MANUFACTURER_SENTEC, 'Sentec' ], |
28
|
|
|
|
|
|
|
[ OPENTHINGS_MANUFACTURER_RASPBERRY , 'Raspberry Pi Projects' ], |
29
|
|
|
|
|
|
|
) |
30
|
|
|
|
|
|
|
{ |
31
|
|
|
|
|
|
|
__PACKAGE__->register_manufacturer( @$manutemplate ); |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
for my $prodtemplate |
35
|
|
|
|
|
|
|
( |
36
|
|
|
|
|
|
|
[ OPENTHINGS_MANUFACTURER_ENERGENIE, ENERGENIE_PRODUCT_ID_MIHO004, 'Mi|Home Monitor', 0 ], |
37
|
|
|
|
|
|
|
[ OPENTHINGS_MANUFACTURER_ENERGENIE, ENERGENIE_PRODUCT_ID_MIHO005, 'Mi|Home Adapter Plus', 1 ], |
38
|
|
|
|
|
|
|
[ OPENTHINGS_MANUFACTURER_ENERGENIE, ENERGENIE_PRODUCT_ID_MIHO006, 'Mi|Home Whole House Monitor', 0 ], |
39
|
|
|
|
|
|
|
[ OPENTHINGS_MANUFACTURER_ENERGENIE, ENERGENIE_PRODUCT_ID_MIHO013, 'Mi|Home Heating Valve', 0 ], |
40
|
|
|
|
|
|
|
[ OPENTHINGS_MANUFACTURER_ENERGENIE, ENERGENIE_PRODUCT_ID_MIHO032, 'Mi|Home Motion Sensor', 0 ], |
41
|
|
|
|
|
|
|
[ OPENTHINGS_MANUFACTURER_ENERGENIE, ENERGENIE_PRODUCT_ID_MIHO033, 'Mi|Home Open Sensor', 0 ], |
42
|
|
|
|
|
|
|
) |
43
|
|
|
|
|
|
|
{ |
44
|
|
|
|
|
|
|
__PACKAGE__->register_product( @$prodtemplate ); |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub register_product { |
49
|
6
|
|
|
6
|
0
|
8
|
my($class, $manu, $product, $name, $canswitch ) = @_; |
50
|
6
|
|
|
|
|
22
|
$products->{$manu}->{$product} = { name => $name, switch => $canswitch }; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub register_manufacturer { |
54
|
4
|
|
|
4
|
0
|
7
|
my($class, $manu, $name ) = @_; |
55
|
4
|
|
|
|
|
21
|
$manufacturers->{$manu} = $name; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub product_name { |
59
|
0
|
|
|
0
|
0
|
|
my($class, $manu, $product ) = @_; |
60
|
0
|
0
|
0
|
|
|
|
if(exists($products->{$manu}) && exists($products->{$manu}->{$product}) ) { |
61
|
0
|
|
|
|
|
|
return $products->{$manu}->{$product}->{name}; |
62
|
|
|
|
|
|
|
} |
63
|
0
|
|
|
|
|
|
return 'Unknown Product ' . $class ->format_product_id( $product ); |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub product_can_switch { |
67
|
0
|
|
|
0
|
0
|
|
my($class, $manu, $product ) = @_; |
68
|
0
|
0
|
0
|
|
|
|
if(exists($products->{$manu}) && exists($products->{$manu}->{$product}) ) { |
69
|
0
|
|
|
|
|
|
return $products->{$manu}->{$product}->{switch}; |
70
|
|
|
|
|
|
|
} |
71
|
0
|
|
|
|
|
|
return 0; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub manufacturer_name { |
75
|
0
|
|
|
0
|
0
|
|
my($class, $manu ) = @_; |
76
|
0
|
0
|
|
|
|
|
if(exists($manufacturers->{$manu})) { |
77
|
0
|
|
|
|
|
|
return $manufacturers->{$manu}; |
78
|
|
|
|
|
|
|
} |
79
|
0
|
|
|
|
|
|
return 'Unknown Manufacturer ' . $class ->format_manufacturer_id( $manu ); |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
sub format_sensor_key { |
83
|
0
|
|
|
0
|
0
|
|
my( $class, $mid, $pid, $sid ) = @_; |
84
|
0
|
|
0
|
|
|
|
my $key = sprintf(qq(%04X-%04X-%06X), $mid || 0, $pid || 0, $sid || 0); |
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
85
|
0
|
|
|
|
|
|
return $key; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
sub format_manufacturer_id { |
89
|
0
|
|
|
0
|
0
|
|
my ($class, $id) = @_; |
90
|
0
|
|
|
|
|
|
return sprintf('0x%04X', $id); |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
sub format_product_id { |
94
|
0
|
|
|
0
|
0
|
|
my ($class, $id) = @_; |
95
|
0
|
|
|
|
|
|
return sprintf('0x%04X', $id); |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
sub format_sensor_id { |
99
|
0
|
|
|
0
|
0
|
|
my ($class, $id) = @_; |
100
|
0
|
|
|
|
|
|
return sprintf('0x%06X', $id); |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
sub parameter_map { |
104
|
0
|
|
|
0
|
0
|
|
my ($class, $param ) = @_; |
105
|
|
|
|
|
|
|
|
106
|
0
|
0
|
|
|
|
|
unless( defined( $param ) ) { |
107
|
0
|
|
|
|
|
|
my $undefname = 'Parameter Undefined'; |
108
|
0
|
0
|
|
|
|
|
return ( wantarray ) ? ( $undefname, '' ) : $undefname; |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
|
111
|
0
|
|
|
|
|
|
my($name, $units) = ('Unknown - ' . $param, ''); |
112
|
|
|
|
|
|
|
|
113
|
0
|
0
|
|
|
|
|
if ( $param == OPENTHINGS_PARAM_ALARM ) { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
114
|
0
|
|
|
|
|
|
$name = 'Alarm'; |
115
|
|
|
|
|
|
|
} elsif( $param == OPENTHINGS_PARAM_DEBUG_OUTPUT ) { |
116
|
0
|
|
|
|
|
|
$name = 'Debug Output'; |
117
|
|
|
|
|
|
|
} elsif( $param == OPENTHINGS_PARAM_IDENTIFY ) { |
118
|
0
|
|
|
|
|
|
$name = 'Identify'; |
119
|
|
|
|
|
|
|
} elsif( $param == OPENTHINGS_PARAM_SOURCE_SELECTOR ) { |
120
|
0
|
|
|
|
|
|
$name = 'Source Selector'; |
121
|
|
|
|
|
|
|
} elsif( $param == OPENTHINGS_PARAM_WATER_DETECTOR ) { |
122
|
0
|
|
|
|
|
|
$name = 'Water Detector'; |
123
|
|
|
|
|
|
|
} elsif( $param == OPENTHINGS_PARAM_GLASS_BREAKAGE ) { |
124
|
0
|
|
|
|
|
|
$name = 'Glass Breakage'; |
125
|
|
|
|
|
|
|
} elsif( $param == OPENTHINGS_PARAM_CLOSURES ) { |
126
|
0
|
|
|
|
|
|
$name = 'Closures'; |
127
|
|
|
|
|
|
|
} elsif( $param == OPENTHINGS_PARAM_DOOR_BELL ) { |
128
|
0
|
|
|
|
|
|
$name = 'Door Bell'; |
129
|
|
|
|
|
|
|
} elsif( $param == OPENTHINGS_PARAM_ENERGY ) { |
130
|
0
|
|
|
|
|
|
$name = 'Energy'; |
131
|
0
|
|
|
|
|
|
$units = 'kWh' |
132
|
|
|
|
|
|
|
} elsif( $param == OPENTHINGS_PARAM_FALL_SENSOR ) { |
133
|
0
|
|
|
|
|
|
$name = 'Fall Sensor'; |
134
|
|
|
|
|
|
|
} elsif( $param == OPENTHINGS_PARAM_GAS_VOLUME ) { |
135
|
0
|
|
|
|
|
|
$name = 'Gas Volume'; |
136
|
0
|
|
|
|
|
|
$units = 'm3'; |
137
|
|
|
|
|
|
|
} elsif( $param == OPENTHINGS_PARAM_AIR_PRESSURE ) { |
138
|
0
|
|
|
|
|
|
$name = 'Air Pressure'; |
139
|
0
|
|
|
|
|
|
$units = 'mbar'; |
140
|
|
|
|
|
|
|
} elsif( $param == OPENTHINGS_PARAM_ILLUMINANCE ) { |
141
|
0
|
|
|
|
|
|
$name = 'Illuminance'; |
142
|
0
|
|
|
|
|
|
$units = 'Lux'; |
143
|
|
|
|
|
|
|
} elsif( $param == OPENTHINGS_PARAM_LEVEL ) { |
144
|
0
|
|
|
|
|
|
$name = 'Level'; |
145
|
|
|
|
|
|
|
} elsif( $param == OPENTHINGS_PARAM_RAINFALL ) { |
146
|
0
|
|
|
|
|
|
$name = 'Rainfall'; |
147
|
0
|
|
|
|
|
|
$units = 'mm'; |
148
|
|
|
|
|
|
|
} elsif( $param == OPENTHINGS_PARAM_APPARENT_POWER ) { |
149
|
0
|
|
|
|
|
|
$name = 'Apparent Power'; |
150
|
0
|
|
|
|
|
|
$units = 'VA'; |
151
|
|
|
|
|
|
|
} elsif( $param == OPENTHINGS_PARAM_POWER_FACTOR ) { |
152
|
0
|
|
|
|
|
|
$name = 'Power Factor'; |
153
|
|
|
|
|
|
|
} elsif( $param == OPENTHINGS_PARAM_REPORT_PERIOD ) { |
154
|
0
|
|
|
|
|
|
$name = 'Report Period'; |
155
|
0
|
|
|
|
|
|
$units = 's'; |
156
|
|
|
|
|
|
|
} elsif( $param == OPENTHINGS_PARAM_SMOKE_DETECTOR ) { |
157
|
0
|
|
|
|
|
|
$name = 'Smoke Detector'; |
158
|
|
|
|
|
|
|
} elsif( $param == OPENTHINGS_PARAM_TIME_AND_DATE ) { |
159
|
0
|
|
|
|
|
|
$name = 'Time and Date'; |
160
|
0
|
|
|
|
|
|
$units = 's'; |
161
|
|
|
|
|
|
|
} elsif( $param == OPENTHINGS_PARAM_VIBRATION ) { |
162
|
0
|
|
|
|
|
|
$name = 'Vibration'; |
163
|
|
|
|
|
|
|
} elsif( $param == OPENTHINGS_PARAM_WATER_VOLUME ) { |
164
|
0
|
|
|
|
|
|
$name = 'Water Volume'; |
165
|
0
|
|
|
|
|
|
$units = 'l'; |
166
|
|
|
|
|
|
|
} elsif( $param == OPENTHINGS_PARAM_WIND_SPEED ) { |
167
|
0
|
|
|
|
|
|
$name = 'Wind Speed'; |
168
|
0
|
|
|
|
|
|
$units = 'm/s'; |
169
|
|
|
|
|
|
|
} elsif( $param == OPENTHINGS_PARAM_GAS_PRESSURE ) { |
170
|
0
|
|
|
|
|
|
$name = 'Gas Pressure'; |
171
|
0
|
|
|
|
|
|
$units = 'Pa'; |
172
|
|
|
|
|
|
|
} elsif( $param == OPENTHINGS_PARAM_BATTERY_LEVEL ) { |
173
|
0
|
|
|
|
|
|
$name = 'Battery Level'; |
174
|
0
|
|
|
|
|
|
$units = 'V'; |
175
|
|
|
|
|
|
|
} elsif( $param == OPENTHINGS_PARAM_CO_DETECTOR ) { |
176
|
0
|
|
|
|
|
|
$name = 'Carbon Monoxide Detector'; |
177
|
|
|
|
|
|
|
} elsif( $param == OPENTHINGS_PARAM_DOOR_SENSOR ) { |
178
|
0
|
|
|
|
|
|
$name = 'Door Sensor'; |
179
|
|
|
|
|
|
|
} elsif( $param == OPENTHINGS_PARAM_EMERGENCY ) { |
180
|
0
|
|
|
|
|
|
$name = 'Emergency'; |
181
|
|
|
|
|
|
|
} elsif( $param == OPENTHINGS_PARAM_FREQUENCY ) { |
182
|
0
|
|
|
|
|
|
$name = 'Frequency'; |
183
|
0
|
|
|
|
|
|
$units = 'Hz'; |
184
|
|
|
|
|
|
|
} elsif( $param == OPENTHINGS_PARAM_GAS_FLOW_RATE ) { |
185
|
0
|
|
|
|
|
|
$name = 'Gas Flow Rate'; |
186
|
0
|
|
|
|
|
|
$units = 'm3/hr'; |
187
|
|
|
|
|
|
|
} elsif( $param == OPENTHINGS_PARAM_RELATIVE_HUMIDITY ) { |
188
|
0
|
|
|
|
|
|
$name = 'Relative Humidity'; |
189
|
0
|
|
|
|
|
|
$units = '%'; |
190
|
|
|
|
|
|
|
} elsif( $param == OPENTHINGS_PARAM_CURRENT ) { |
191
|
0
|
|
|
|
|
|
$name = 'Current'; |
192
|
0
|
|
|
|
|
|
$units = 'A'; |
193
|
|
|
|
|
|
|
} elsif( $param == OPENTHINGS_PARAM_JOIN ) { |
194
|
0
|
|
|
|
|
|
$name = 'Join'; |
195
|
|
|
|
|
|
|
} elsif( $param == OPENTHINGS_PARAM_LIGHT_LEVEL ) { |
196
|
0
|
|
|
|
|
|
$name = 'Light Level'; |
197
|
|
|
|
|
|
|
} elsif( $param == OPENTHINGS_PARAM_MOTION_DETECTOR ) { |
198
|
0
|
|
|
|
|
|
$name = 'Motion Detector'; |
199
|
|
|
|
|
|
|
} elsif( $param == OPENTHINGS_PARAM_OCCUPANCY ) { |
200
|
0
|
|
|
|
|
|
$name = 'Occupancy'; |
201
|
|
|
|
|
|
|
} elsif( $param == OPENTHINGS_PARAM_REAL_POWER ) { |
202
|
0
|
|
|
|
|
|
$name = 'Real Power'; |
203
|
0
|
|
|
|
|
|
$units = 'W'; |
204
|
|
|
|
|
|
|
} elsif( $param == OPENTHINGS_PARAM_REACTIVE_POWER ) { |
205
|
0
|
|
|
|
|
|
$name = 'Reactive Power'; |
206
|
0
|
|
|
|
|
|
$units = 'VAR'; |
207
|
|
|
|
|
|
|
} elsif( $param == OPENTHINGS_PARAM_SWITCH_STATE ) { |
208
|
0
|
|
|
|
|
|
$name = 'Switch State'; |
209
|
|
|
|
|
|
|
} elsif( $param == OPENTHINGS_PARAM_TEMPERATURE ) { |
210
|
0
|
|
|
|
|
|
$name = 'Temperature'; |
211
|
0
|
|
|
|
|
|
$units = 'C'; |
212
|
|
|
|
|
|
|
} elsif( $param == OPENTHINGS_PARAM_VOLTAGE ) { |
213
|
0
|
|
|
|
|
|
$name = 'Voltage'; |
214
|
0
|
|
|
|
|
|
$units = 'V'; |
215
|
|
|
|
|
|
|
} elsif( $param == OPENTHINGS_PARAM_WATER_FLOW_RATE ) { |
216
|
0
|
|
|
|
|
|
$name = 'Water Flow Rate'; |
217
|
0
|
|
|
|
|
|
$units = 'l/hr'; |
218
|
|
|
|
|
|
|
} elsif( $param == OPENTHINGS_PARAM_WATER_PRESSURE ) { |
219
|
0
|
|
|
|
|
|
$name = 'Water Pressure'; |
220
|
0
|
|
|
|
|
|
$units = 'Pa'; |
221
|
|
|
|
|
|
|
} elsif( $param == OPENTHINGS_PARAM_PHASE_1_POWER ) { |
222
|
0
|
|
|
|
|
|
$name = 'Phase 1 Power'; |
223
|
0
|
|
|
|
|
|
$units = 'W'; |
224
|
|
|
|
|
|
|
} elsif( $param == OPENTHINGS_PARAM_PHASE_2_POWER ) { |
225
|
0
|
|
|
|
|
|
$name = 'Phase 2 Power'; |
226
|
0
|
|
|
|
|
|
$units = 'W'; |
227
|
|
|
|
|
|
|
} elsif( $param == OPENTHINGS_PARAM_PHASE_3_POWER ) { |
228
|
0
|
|
|
|
|
|
$name = 'Phase 3 Power'; |
229
|
0
|
|
|
|
|
|
$units = 'W'; |
230
|
|
|
|
|
|
|
} elsif( $param == OPENTHINGS_PARAM_3_PHASE_TOTAL ) { |
231
|
0
|
|
|
|
|
|
$name = '3 Phase Total Power'; |
232
|
0
|
|
|
|
|
|
$units = 'W'; |
233
|
|
|
|
|
|
|
} elsif( $param == OPENTHINGS_PARAM_TEST ) { |
234
|
0
|
|
|
|
|
|
$name = 'Test'; |
235
|
|
|
|
|
|
|
} |
236
|
0
|
0
|
|
|
|
|
return ( wantarray ) ? ( $name, $units ) : $name; |
237
|
|
|
|
|
|
|
} |
238
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
1; |
240
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
__END__ |