From b654b832fc694f5767adee9e47f4cfbbc64e84b7 Mon Sep 17 00:00:00 2001 From: vuffiraa <> Date: Sun, 11 Apr 2021 14:29:19 +0000 Subject: [PATCH] 70_BRAVIA.pm: fix registration renewal git-svn-id: https://svn.fhem.de/fhem/trunk@24219 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/CHANGED | 1 + fhem/FHEM/70_BRAVIA.pm | 12 +++++-- fhem/t/FHEM/70_BRAVIA/CheckRegistration.t | 40 +++++++++++++++++++++++ 3 files changed, 50 insertions(+), 3 deletions(-) create mode 100644 fhem/t/FHEM/70_BRAVIA/CheckRegistration.t diff --git a/fhem/CHANGED b/fhem/CHANGED index 3193ac031..2f448a3e3 100644 --- a/fhem/CHANGED +++ b/fhem/CHANGED @@ -1,5 +1,6 @@ # Add changes at the top of the list. Keep it in ASCII, and 80-char wide. # Do not insert empty lines here, update check depends on it. + - bugfix: 70_BRAVIA: fix registration renewal - change: 49_IPCAM: imageWithCallback wrapped in internalTimer with 0 delay - bugfix: 47_OBIS: Reintegrate buggy DZG meters support - change: 49_IPCAM: introduced attribute httpTimeout diff --git a/fhem/FHEM/70_BRAVIA.pm b/fhem/FHEM/70_BRAVIA.pm index d96589773..07553dc84 100644 --- a/fhem/FHEM/70_BRAVIA.pm +++ b/fhem/FHEM/70_BRAVIA.pm @@ -2214,8 +2214,10 @@ sub CheckRegistration { my ( $hash, $service, $cmd, $param, @successor ) = @_; my $name = $hash->{NAME}; - if (ReadingsVal($name, "authCookie", "") ne "" and - ReadingsTimestamp($name, "authCookie", "") =~ m/^(\d{4})-(\d{2})-(\d{2}) ([0-2]\d):([0-5]\d):([0-5]\d)$/xms) { + my $authCookie = ReadingsVal($name, "authCookie", ""); + my $authCookieTS = ReadingsTimestamp($name, "authCookie", ""); + if ($authCookie ne "" and + $authCookieTS =~ m/^(\d{4})-(\d{2})-(\d{2})\ ([0-2]\d):([0-5]\d):([0-5]\d)$/xms) { my $time = fhemTimeLocal($6, $5, $4, $3, $2 - 1, $1 - 1900); # max age defaults to 14 days @@ -2235,12 +2237,16 @@ sub CheckRegistration { $msg .= " $i: "; $msg .= join(",", map { defined($_) ? $_ : '' } @succ_item); } - Log3($name, 4, "BOTVAC created".$msg); + Log3($name, 4, "BRAVIA $name: created".$msg); SendCommand( $hash, "register", "renew", undef, @successor ); return 1; + } else { + Log3($name, 5, "BRAVIA $name: registration valid until $authCookieTS"); } + } else { + Log3($name, 4, "BRAVIA $name: authCookie not valid '$authCookie $authCookieTS'"); } return; } diff --git a/fhem/t/FHEM/70_BRAVIA/CheckRegistration.t b/fhem/t/FHEM/70_BRAVIA/CheckRegistration.t new file mode 100644 index 000000000..dc329541c --- /dev/null +++ b/fhem/t/FHEM/70_BRAVIA/CheckRegistration.t @@ -0,0 +1,40 @@ +################################################ +# test Set +################################################ +package FHEM::BRAVIA; + +use strict; +use warnings; +use Test::More; + +# used to import of FHEM functions from fhem.pl +use GPUtils qw(:all); +BEGIN { + GP_Import( + qw( + fhem + FhemTestUtils_gotLog + FhemTestUtils_resetLogs + ) + ); +} + +# execute checkRegistration +{ + CheckRegistration($::defs{tv}); +} +is(FhemTestUtils_gotLog("BRAVIA tv: authCookie not valid ' '"), 1, "Registration missing"); + +FhemTestUtils_resetLogs(); + +fhem('setreading tv authCookie test'); +{ + CheckRegistration($::defs{tv}); +} +is(FhemTestUtils_gotLog("BRAVIA tv: authCookie not valid '.*'"), 0, "Registration valid"); +is(FhemTestUtils_gotLog("BRAVIA tv: registration valid until .*"), 1, "Registration period"); + +done_testing; +exit(0); + +1; \ No newline at end of file