From 2a85b4974bef9bfa4d4bc5fff44cde32e1f3b80b Mon Sep 17 00:00:00 2001 From: drhirn <> Date: Fri, 29 Oct 2021 06:39:23 +0000 Subject: [PATCH] 10_RHASSPY.pm: fixed crash if no CLIENT is defined; some clean-up; small cref-changes git-svn-id: https://svn.fhem.de/fhem/trunk@25143 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/contrib/RHASSPY/10_RHASSPY.pm | 45 +++++++++++++++++++----------- 1 file changed, 29 insertions(+), 16 deletions(-) diff --git a/fhem/contrib/RHASSPY/10_RHASSPY.pm b/fhem/contrib/RHASSPY/10_RHASSPY.pm index a1c5d0f15..9443b92dc 100644 --- a/fhem/contrib/RHASSPY/10_RHASSPY.pm +++ b/fhem/contrib/RHASSPY/10_RHASSPY.pm @@ -1,4 +1,4 @@ -# $Id: 10_RHASSPY.pm 24786 2021-09-21 + Beta-User$ +# $Id: 10_RHASSPY.pm 24786 2021-10-17 + Beta-User$ ########################################################################### # # FHEM RHASSPY module (https://github.com/rhasspy) @@ -246,8 +246,9 @@ my $de_mappings = { BEGIN { - GP_Import(qw( + GP_Import( qw( addToAttrList + addToDevAttrList delFromDevAttrList delFromAttrList readingsSingleUpdate @@ -295,9 +296,7 @@ BEGIN { FileRead getAllSets trim - )) - #round - + ) ) }; # MQTT Topics die das Modul automatisch abonniert @@ -348,7 +347,7 @@ sub Define { $hash->{defaultRoom} = $defaultRoom; my $language = $h->{language} // shift @{$anon} // lc AttrVal('global','language','en'); - $hash->{MODULE_VERSION} = '0.4.40'; + $hash->{MODULE_VERSION} = '0.4.41a'; $hash->{baseUrl} = $Rhasspy; initialize_Language($hash, $language) if !defined $hash->{LANGUAGE} || $hash->{LANGUAGE} ne $language; $hash->{LANGUAGE} = $language; @@ -376,16 +375,23 @@ sub firstInit { # IO AssignIoPort($hash); - my $IODev = AttrVal( $name, 'IODev', ReadingsVal( $name, 'IODev', InternalVal($name, 'IODev', undef )->{NAME})); + my $IODev = AttrVal( $name, 'IODev', ReadingsVal( $name, 'IODev', defined InternalVal($name, 'IODev', undef ) ? InternalVal($name, 'IODev', undef )->{NAME} : undef )); - return if !$init_done || !defined $IODev; + return if !$init_done; # || !defined $IODev; RemoveInternalTimer($hash); deleteAllRegIntTimer($hash); fetchSiteIds($hash) if !ReadingsVal( $name, 'siteIds', 0 ); initialize_rhasspyTweaks($hash, AttrVal($name,'rhasspyTweaks', undef )); fetchIntents($hash); - IOWrite($hash, 'subscriptions', join q{ }, @topics) if InternalVal($IODev,'TYPE',undef) eq 'MQTT2_CLIENT'; + delete $hash->{ERRORS}; + if ( !defined InternalVal($name, 'IODev',undef) ) { + Log3( $hash, 1, "[$name] no suitable IO found, please define one and/or also add :RHASSPY: to clientOrder"); + $hash->{ERRORS} = 'no suitable IO found, please define one and/or also add :RHASSPY: to clientOrder!'; + } + IOWrite($hash, 'subscriptions', join q{ }, @topics) + if defined InternalVal($name, 'IODev',undef) + && InternalVal( InternalVal($name, 'IODev',undef)->{NAME}, 'IODev', 'none') eq 'MQTT2_CLIENT'; initialize_devicemap($hash); return; @@ -436,20 +442,25 @@ sub initialize_prefix { addToAttrList("${prefix}Name",'RHASSPY'); addToAttrList("${prefix}Room",'RHASSPY'); addToAttrList("${prefix}Mapping:textField-long",'RHASSPY'); - #addToAttrList("${prefix}Channels:textField-long"); - #addToAttrList("${prefix}Colors:textField-long"); addToAttrList("${prefix}Group:textField",'RHASSPY'); addToAttrList("${prefix}Specials:textField-long",'RHASSPY'); + for (devspec2array("${prefix}Colors=.+")) { + addToDevAttrList($_, "${prefix}Colors:textField-long",'RHASSPY'); + } + for (devspec2array("${prefix}Channels=.+")) { + addToDevAttrList($_, "${prefix}Channels:textField-long",'RHASSPY'); + } return if !$init_done || !defined $old_prefix; my @devs = devspec2array("$hash->{devspec}"); my @rhasspys = devspec2array("TYPE=RHASSPY:FILTER=prefix=$old_prefix"); - for my $detail (qw( Name Room Mapping Group Specials)) { + for my $detail ( qw( Name Room Mapping Group Specials Channels Colors ) ) { for my $device (@devs) { - my $aval = AttrVal($device, "${old_prefix}$detail", undef); + my $aval = AttrVal($device, "${old_prefix}$detail", undef); CommandAttr($hash, "$device ${prefix}$detail $aval") if $aval; CommandDeleteAttr($hash, "$device ${old_prefix}$detail") if @rhasspys < 2; + delFromDevAttrList($device,"${old_prefix}$detail") if @rhasspys < 2 && ($detail eq "Channels" || $detail eq "Colors"); } delFromAttrList("${old_prefix}$detail") if @rhasspys < 2; } @@ -4805,12 +4816,13 @@ i="i am hungry" f="set Stove on" d="Stove" c="would you like roast pork"<
This key may contain <Intent>=<regex> pairs beeing +
This key may contain <Intent>=<regex> pairs beeing
confirmIntents=SetOnOffGroup=light|blinds SetOnOff=blind.*
Atm. Rhasspy will activate all known intents at startup. As some of the intents used by FHEM are only needed in case some dialogue is open, it will deactivate these intents (atm: ConfirmAction, CancelAction, ChoiceRoom and ChoiceDevice(including the additional parts derived from language and fhemId))) at startup or when no active filtering is detected. You may disable additional intents by just adding their names in intentFilter line or using an explicit state assignment in the form intentname=true (Note: activating the 4 mentionned intents is not possible!). For details on how configure works see Rhasspy documentation. +
Atm. Rhasspy will activate all known intents at startup. As some of the intents used by FHEM are only needed in case some dialogue is open, it will deactivate these intents (atm: ConfirmAction, CancelAction, ChoiceRoom and ChoiceDevice(including the additional parts derived from language and fhemId))) at startup or when no active filtering is detected. You may disable additional intents by just adding their names in intentFilter line or using an explicit state assignment in the form intentname=true (Note: activating the 4 mentionned intents is not possible!). For details on how configure works see Rhasspy documentation.