############################################## # $Id$ # package RHASSPY::Demo; ## 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( AttrVal InternalVal ReadingsVal ReadingsNum ReadingsAge fhem Log3 decode defs round ) ); } sub ::RHASSPY_Utils_Demo_Initialize { goto &Initialize } # initialize ################################################################## sub Initialize { my $hash = shift; return; } # Enter you functions below _this_ line. sub BasicTest { my $site = shift; my $type = shift; Log3('rhasspy',3 , "RHASSPY: Site $site, Type $type"); return "RHASSPY: Site $site, Type $type"; } sub DataTest { 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 $type = $data->{Type}; Log3('rhasspy',3 , "RHASSPY: Site $site, Type $type"); my @devices = sort keys %{$hash->{helper}{devicemap}->{devices}}; while (@devices > 2) { shift @devices; # limit triggered devices two to minimize unwanted side effects } my @rets; $rets[0] = "RHASSPY: Site $site, Type $type"; $rets[1] = join q{,}, @devices; return \@rets; } sub DialogueTest{ 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 $type = $data->{Type}; Log3('rhasspy',3 , "RHASSPY: Site $site, Type $type"); my @devices = sort keys %{$hash->{helper}{devicemap}->{devices}}; while (@devices > 2) { shift @devices; # limit triggered devices two to minimize unwanted side effects } my @rets; #interactive dialogue as described in https://rhasspy.readthedocs.io/en/latest/reference/#dialoguemanager_continuesession and https://docs.snips.ai/articles/platform/dialog/multi-turn-dialog #This example here just lets you confirm the action, as intent filter is limited to ConfirmAction my $response = "RHASSPY asking for OK or cancellation: Site $site, Type $type"; my $ca_string = qq{$hash->{LANGUAGE}.$hash->{fhemId}:ConfirmAction}; my $reaction = { text => $response, intentFilter => ["$ca_string"] }; $rets[0] = $reaction; $rets[2] = 30; #timeout to replace default timeout return \@rets; } 1; __END__ =pod =begin html

RHASSPY_Demo_Utils

=end html =cut