From 8524d188d7736f7b19c8abb1228e0c430ba0ce65 Mon Sep 17 00:00:00 2001 From: Marko Oldenburg Date: Wed, 15 Oct 2025 06:44:38 +0200 Subject: [PATCH] Add UTF-8 encoding for reading bulk updates This commit introduces the use of the `Encode` module to ensure that values being processed in the `WriteReadings` subroutine are correctly encoded in UTF-8. The previous implementation did not account for potential non-UTF-8 encoded data which could lead to issues when updating readings. The change specifically checks if the value (`$v`) is marked as UTF-8 using `Encode::is_utf8()`. If it is, the value is re-encoded to UTF-8 before being passed to `::readingsBulkUpdate()`. This adjustment ensures that all data written to readings maintains proper character encoding, improving compatibility and preventing potential data corruption. No breaking changes are introduced, but it is important for users to validate that their readings correctly display any special characters post-update. --- controls_NukiSmart.txt | 8 ++++---- lib/FHEM/Devices/Nuki/Device.pm | 5 +++-- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/controls_NukiSmart.txt b/controls_NukiSmart.txt index ce9b57c..c7f7797 100644 --- a/controls_NukiSmart.txt +++ b/controls_NukiSmart.txt @@ -1,4 +1,4 @@ -UPD 2025-10-14_10:40:53 10358 FHEM/73_NUKIBridge.pm -UPD 2025-10-14_10:41:09 11100 FHEM/74_NUKIDevice.pm -UPD 2025-10-14_10:42:11 42820 lib/FHEM/Devices/Nuki/Bridge.pm -UPD 2025-10-14_10:42:04 16698 lib/FHEM/Devices/Nuki/Device.pm +UPD 2025-10-14_11:00:54 10358 FHEM/73_NUKIBridge.pm +UPD 2025-10-14_11:00:54 11100 FHEM/74_NUKIDevice.pm +UPD 2025-10-14_11:00:54 42820 lib/FHEM/Devices/Nuki/Bridge.pm +UPD 2025-10-15_06:43:51 16775 lib/FHEM/Devices/Nuki/Device.pm diff --git a/lib/FHEM/Devices/Nuki/Device.pm b/lib/FHEM/Devices/Nuki/Device.pm index 91766f4..4bb6637 100644 --- a/lib/FHEM/Devices/Nuki/Device.pm +++ b/lib/FHEM/Devices/Nuki/Device.pm @@ -30,7 +30,7 @@ use strict; use warnings; #use experimental qw( switch ); - +use Encode; use FHEM::Meta; use GPUtils qw(GP_Import); @@ -550,7 +550,8 @@ sub WriteReadings { while ( ( $t, $v ) = each %{$decode_json} ) { # generische readings (alles außer spezielle Felder) - ::readingsBulkUpdate( $hash, $t, $v ) + ::readingsBulkUpdate( $hash, $t, + Encode::is_utf8($v) ? Encode::encode( "UTF-8", $v ) : $v ) if ( $t ne 'state' && $t ne 'mode' && $t ne 'deviceType'