From d107104421bf98ea4f84b1ac04c3792de14de764 Mon Sep 17 00:00:00 2001 From: Tony Roberts Date: Mon, 15 Apr 2024 17:06:48 +0100 Subject: [PATCH] Unquote values when getting devices (#32) Fixes #31 --- custom_components/wundasmart/__init__.py | 2 +- custom_components/wundasmart/climate.py | 2 +- custom_components/wundasmart/pywundasmart.py | 7 ++++++- custom_components/wundasmart/sensor.py | 4 ++-- custom_components/wundasmart/water_heater.py | 2 +- tests/fixtures/test_get_devices1.json | 4 ++-- tests/fixtures/test_get_devices2.json | 4 ++-- tests/fixtures/test_get_devices3.json | 4 ++-- tests/fixtures/test_manual_off.json | 4 ++-- tests/fixtures/test_set_presets.json | 4 ++-- tests/fixtures/test_set_temperature.json | 4 ++-- tests/fixtures/test_trvs_only.json | 4 ++-- 12 files changed, 25 insertions(+), 20 deletions(-) diff --git a/custom_components/wundasmart/__init__.py b/custom_components/wundasmart/__init__.py index d7c75a2..52cbfaf 100644 --- a/custom_components/wundasmart/__init__.py +++ b/custom_components/wundasmart/__init__.py @@ -132,7 +132,7 @@ async def _async_update_data(self): # Get the hub switch serial number if we don't have it already if self._device_sn is None and "device_sn" in device: self._device_sn = device["device_sn"] - self._device_name = device.get("name", "Smart HubSwitch").replace("%20", " ") + self._device_name = device.get("name", "Smart HubSwitch") self._sw_version = device.get("device_soft_version", "unknown") self._hw_version = device.get("device_hard_version", "unknown") diff --git a/custom_components/wundasmart/climate.py b/custom_components/wundasmart/climate.py index e07cf00..2279db5 100644 --- a/custom_components/wundasmart/climate.py +++ b/custom_components/wundasmart/climate.py @@ -109,7 +109,7 @@ def __init__( self._wunda_user = wunda_user self._wunda_pass = wunda_pass self._wunda_id = wunda_id - self._attr_name = device["name"].replace("%20", " ") + self._attr_name = device["name"] self._attr_unique_id = device["id"] self._attr_type = device["device_type"] self._attr_device_info = coordinator.device_info diff --git a/custom_components/wundasmart/pywundasmart.py b/custom_components/wundasmart/pywundasmart.py index 25aeb1c..a91577f 100644 --- a/custom_components/wundasmart/pywundasmart.py +++ b/custom_components/wundasmart/pywundasmart.py @@ -1,4 +1,5 @@ from .const import * +import urllib.parse import asyncio import aiohttp import logging @@ -77,7 +78,11 @@ def parse_syncvalues(data: str): hw_version = 0 for device_state in data.splitlines(): raw_values = device_state.split(";") - device_values = dict(x.split(":") for x in raw_values if ":" in x) + device_values = { + k: urllib.parse.unquote(v) for k, v in ( + x.split(":") for x in raw_values if ":" in x + ) + } # This is set once for the first item and is the hub switch serial number device_sn = device_sn or device_values.get("device_sn") diff --git a/custom_components/wundasmart/sensor.py b/custom_components/wundasmart/sensor.py index 434afd6..e38fd13 100644 --- a/custom_components/wundasmart/sensor.py +++ b/custom_components/wundasmart/sensor.py @@ -153,7 +153,7 @@ def _trv_get_sensor_name(room, trv, desc: WundaSensorDescription): device_id = int(trv["device_id"]) hw_version = float(trv["hw_version"]) id_ranges = get_device_id_ranges(hw_version) - return room["name"].replace("%20", " ") + f" TRV.{device_id - id_ranges.MIN_TRV_ID} {desc.name}" + return room["name"] + f" TRV.{device_id - id_ranges.MIN_TRV_ID} {desc.name}" async def async_setup_entry( @@ -174,7 +174,7 @@ async def async_setup_entry( room_sensors = itertools.chain( Sensor(wunda_id, - room["name"].replace("%20", " ") + " " + desc.name, + room["name"] + " " + desc.name, coordinator, desc) for wunda_id, device, room in rooms for desc in ROOM_SENSORS diff --git a/custom_components/wundasmart/water_heater.py b/custom_components/wundasmart/water_heater.py index e35ac81..d6061a4 100644 --- a/custom_components/wundasmart/water_heater.py +++ b/custom_components/wundasmart/water_heater.py @@ -153,7 +153,7 @@ def __init__( self._wunda_user = wunda_user self._wunda_pass = wunda_pass self._wunda_id = wunda_id - self._attr_name = device["device_name"].replace("%20", " ") + self._attr_name = device["device_name"] self._attr_unique_id = device["id"] self._attr_type = device["device_type"] self._attr_device_info = coordinator.device_info diff --git a/tests/fixtures/test_get_devices1.json b/tests/fixtures/test_get_devices1.json index b6c0cef..360e89d 100644 --- a/tests/fixtures/test_get_devices1.json +++ b/tests/fixtures/test_get_devices1.json @@ -11,7 +11,7 @@ "hw_hist": "5", "hw_ext_temp": "0" }, - "device_name": "Smart%20HubSwitch", + "device_name": "Smart HubSwitch", "id": "wunda.0" }, "1": { @@ -76,7 +76,7 @@ "alarm": "0", "tbl": "555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555" }, - "name": "Test%20Room", + "name": "Test Room", "id": "ROOM.121", "sensor_state": { "s": "1", diff --git a/tests/fixtures/test_get_devices2.json b/tests/fixtures/test_get_devices2.json index 9f0fdc7..c57665e 100644 --- a/tests/fixtures/test_get_devices2.json +++ b/tests/fixtures/test_get_devices2.json @@ -11,7 +11,7 @@ "hw_hist": "5", "hw_ext_temp": "0" }, - "device_name": "Smart%20HubSwitch", + "device_name": "Smart HubSwitch", "id": "wunda.0" }, "1": { @@ -76,7 +76,7 @@ "alarm": "0", "tbl": "555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555" }, - "name": "Test%20Room", + "name": "Test Room", "id": "ROOM.121", "sensor_state": { "s": "1", diff --git a/tests/fixtures/test_get_devices3.json b/tests/fixtures/test_get_devices3.json index 2ea33a3..aa502da 100644 --- a/tests/fixtures/test_get_devices3.json +++ b/tests/fixtures/test_get_devices3.json @@ -11,7 +11,7 @@ "hw_hist": "5", "hw_ext_temp": "0" }, - "device_name": "Smart%20HubSwitch", + "device_name": "Smart HubSwitch", "id": "wunda.0" }, "121": { @@ -42,7 +42,7 @@ "alarm": "0", "tbl": "555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555" }, - "name": "Test%20Room", + "name": "Test Room", "id": "ROOM.121", "sensor_state": { "s": "1", diff --git a/tests/fixtures/test_manual_off.json b/tests/fixtures/test_manual_off.json index 8ef3267..2cf8351 100644 --- a/tests/fixtures/test_manual_off.json +++ b/tests/fixtures/test_manual_off.json @@ -11,7 +11,7 @@ "hw_hist": "5", "hw_ext_temp": "0" }, - "device_name": "Smart%20HubSwitch", + "device_name": "Smart HubSwitch", "id": "wunda.0" }, "1": { @@ -76,7 +76,7 @@ "alarm": "0", "tbl": "555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555" }, - "name": "Test%20Room", + "name": "Test Room", "id": "ROOM.121", "sensor_state": { "s": "1", diff --git a/tests/fixtures/test_set_presets.json b/tests/fixtures/test_set_presets.json index be12241..d1638fa 100644 --- a/tests/fixtures/test_set_presets.json +++ b/tests/fixtures/test_set_presets.json @@ -11,7 +11,7 @@ "hw_hist": "5", "hw_ext_temp": "0" }, - "device_name": "Smart%20HubSwitch", + "device_name": "Smart HubSwitch", "id": "wunda.0" }, "1": { @@ -76,7 +76,7 @@ "alarm": "0", "tbl": "555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555" }, - "name": "Test%20Room", + "name": "Test Room", "id": "ROOM.121", "sensor_state": { "s": "1", diff --git a/tests/fixtures/test_set_temperature.json b/tests/fixtures/test_set_temperature.json index 0b18d21..ebd6092 100644 --- a/tests/fixtures/test_set_temperature.json +++ b/tests/fixtures/test_set_temperature.json @@ -11,7 +11,7 @@ "hw_hist": "5", "hw_ext_temp": "0" }, - "device_name": "Smart%20HubSwitch", + "device_name": "Smart HubSwitch", "id": "wunda.0" }, "121": { @@ -42,7 +42,7 @@ "alarm": "0", "tbl": "555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555" }, - "name": "Test%20Room", + "name": "Test Room", "id": "ROOM.121", "sensor_state": { "s": "1", diff --git a/tests/fixtures/test_trvs_only.json b/tests/fixtures/test_trvs_only.json index c2d369c..a8af6b1 100644 --- a/tests/fixtures/test_trvs_only.json +++ b/tests/fixtures/test_trvs_only.json @@ -11,7 +11,7 @@ "hw_hist": "5", "hw_ext_temp": "0" }, - "device_name": "Smart%20HubSwitch", + "device_name": "Smart HubSwitch", "id": "wunda.0" }, "31": { @@ -52,7 +52,7 @@ }, "121": { "device_type": "ROOM", - "name": "Test%20Room", + "name": "Test Room", "id": "ROOM.121", "state": { "t_lo": "14.00",