From 68ec2f09ac189821b9d7233a750571adb2201ca1 Mon Sep 17 00:00:00 2001 From: neumann <> Date: Sun, 19 Nov 2017 19:05:42 +0000 Subject: [PATCH] 31_Nello: minor improvements git-svn-id: https://svn.fhem.de/fhem/trunk@15460 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/FHEM/31_Nello.pm | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/fhem/FHEM/31_Nello.pm b/fhem/FHEM/31_Nello.pm index 74bd366e4..07199c29a 100644 --- a/fhem/FHEM/31_Nello.pm +++ b/fhem/FHEM/31_Nello.pm @@ -146,11 +146,23 @@ sub Nello_Attr(@) { CommandDefine(undef, $eventdevice . ' MQTT_DEVICE'); CommandAttr(undef, $eventdevice . ' room hidden'); CommandAttr(undef, $eventdevice . ' IODEV '. $bridge); - CommandAttr(undef, $eventdevice . ' subscribeReading_'. $attrValue .'_door /nello_one/'. $attrValue . '/door/'); - CommandAttr(undef, $eventdevice . ' subscribeReading_'. $attrValue .'_ring /nello_one/'. $attrValue . '/ring/'); - CommandAttr(undef, $eventdevice . ' subscribeReading_'. $attrValue .'_tw /nello_one/'. $attrValue . '/tw/'); - CommandSave(undef, undef); - } + } + + my $prefix = 'subscribeReading_'. $attrValue .'_'; + CommandAttr(undef, $eventdevice . ' '. $prefix . 'door /nello_one/'. $attrValue . '/door/') if(!defined $attr{$eventdevice}{$prefix . 'door'}); + CommandAttr(undef, $eventdevice . ' '. $prefix . 'ring /nello_one/'. $attrValue . '/ring/') if(!defined $attr{$eventdevice}{$prefix . 'ring'});; + CommandAttr(undef, $eventdevice . ' '. $prefix . 'tw /nello_one/'. $attrValue . '/tw/') if(!defined $attr{$eventdevice}{$prefix . 'tw'}); + + if(defined $hash->{helper}{deviceID} && $hash->{helper}{deviceID} ne $attrValue) { + $prefix = 'subscribeReading_'. $hash->{helper}{deviceID} .'_'; + CommandDeleteAttr(undef, $eventdevice . ' '. $prefix . 'door'); + CommandDeleteAttr(undef, $eventdevice . ' '. $prefix . 'ring'); + CommandDeleteAttr(undef, $eventdevice . ' '. $prefix . 'tw'); + } + + CommandSave(undef, undef); + + $hash->{helper}{deviceID} = $attrValue; } return undef; @@ -161,6 +173,7 @@ sub Nello_loadInternals($) { my $name = $hash->{NAME}; $hash->{helper}{expires} = ReadingsVal($name, '.expires', undef); $hash->{helper}{session} = ReadingsVal($name, '.session', undef); + $hash->{helper}{deviceID} = $attr{$name}{"deviceID"}; if(!defined(ReadingsVal($name, '.session', undef))) { $hash->{STATE} = 'authorization pending'; @@ -432,6 +445,7 @@ sub Nello_poll { my $pollInterval = $attr{$name}{updateInterval}; InternalTimer(gettimeofday()+(defined $pollInterval ? $pollInterval : (!defined $attr{$name}{deviceID} ? 15 : 15*60)), "Nello_poll", $hash); + Nello_updateLocations($hash) if(!defined Nello_defaultLocationID($hash)); Nello_updateActivities($hash); }