-
Notifications
You must be signed in to change notification settings - Fork 1
/
99_RHASSPY_Utils_siteId2room.pm
83 lines (64 loc) · 1.88 KB
/
99_RHASSPY_Utils_siteId2room.pm
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
##############################################
# $Id: RHASSPY_Utils_siteId2room.pm 2021-04-22 Beta-User $
#
package RHASSPY::siteId2room; ## no critic 'Package declaration'
use strict;
use warnings;
use JSON;
use Encode;
use List::Util qw(max min);
use GPUtils qw(GP_Import);
## Import der FHEM Funktionen
#-- Run before package compilation
BEGIN {
# Import from main context
GP_Import(
qw(
ReadingsVal
readingsSingleUpdate
Log3
decode
defs
makeReadingName
)
);
}
sub ::RHASSPY_Utils_siteId2room_Initialize { goto &Initialize }
# initialize ##################################################################
sub Initialize {
my $hash = shift;
return;
}
# Enter you functions below _this_ line.
sub siteId2room {
my $name = shift;
my $rawd = shift;
my $hash = $defs{$name} // return;
my $data;
if ( !eval { $data = decode_json($rawd) ; 1 } ) {
Log3($hash->{NAME}, 1, "JSON decoding error, $rawd seems not to be valid JSON data: $@");
return "Error! $rawd seems not to be valid JSON data!";
}
my $site = $data->{siteId};
my $room = $data->{Room};
my $rreading = makeReadingName("siteId2room_$site");
readingsSingleUpdate($hash, $rreading, $room, 1);
Log3($name, 5, "RHASSPY: Site $site now is in room $room");
my @rets;
$rets[0] = "Habe den Raum von $site auf $room geändert";
$rets[1] = $name;
return \@rets;
}
1;
__END__
=pod
=begin html
<a name="RHASSPY_Utils_siteId2room"></a>
<h3>RHASSPY_Utils_siteId2room</h3>
<ul>
<li>siteId2room</li>
Routine to change the default room a siteId is assigned to. Might be usefull if you use e.g. your mobile phone as satellite.<br>
Example: <code>attr <rhasspyDevice> rhasspyIntents siteId2room=RHASSPY::siteId2room::siteId2room(NAME,DATA)</code></p>
</ul>
=end html
=cut