Skip to content

Commit

Permalink
Unquote values when getting devices (#32)
Browse files Browse the repository at this point in the history
Fixes #31
  • Loading branch information
tonyroberts authored Apr 15, 2024
1 parent b7de28f commit d107104
Show file tree
Hide file tree
Showing 12 changed files with 25 additions and 20 deletions.
2 changes: 1 addition & 1 deletion custom_components/wundasmart/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
2 changes: 1 addition & 1 deletion custom_components/wundasmart/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion custom_components/wundasmart/pywundasmart.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from .const import *
import urllib.parse
import asyncio
import aiohttp
import logging
Expand Down Expand Up @@ -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")
Expand Down
4 changes: 2 additions & 2 deletions custom_components/wundasmart/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion custom_components/wundasmart/water_heater.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions tests/fixtures/test_get_devices1.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"hw_hist": "5",
"hw_ext_temp": "0"
},
"device_name": "Smart%20HubSwitch",
"device_name": "Smart HubSwitch",
"id": "wunda.0"
},
"1": {
Expand Down Expand Up @@ -76,7 +76,7 @@
"alarm": "0",
"tbl": "555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555"
},
"name": "Test%20Room",
"name": "Test Room",
"id": "ROOM.121",
"sensor_state": {
"s": "1",
Expand Down
4 changes: 2 additions & 2 deletions tests/fixtures/test_get_devices2.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"hw_hist": "5",
"hw_ext_temp": "0"
},
"device_name": "Smart%20HubSwitch",
"device_name": "Smart HubSwitch",
"id": "wunda.0"
},
"1": {
Expand Down Expand Up @@ -76,7 +76,7 @@
"alarm": "0",
"tbl": "555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555"
},
"name": "Test%20Room",
"name": "Test Room",
"id": "ROOM.121",
"sensor_state": {
"s": "1",
Expand Down
4 changes: 2 additions & 2 deletions tests/fixtures/test_get_devices3.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"hw_hist": "5",
"hw_ext_temp": "0"
},
"device_name": "Smart%20HubSwitch",
"device_name": "Smart HubSwitch",
"id": "wunda.0"
},
"121": {
Expand Down Expand Up @@ -42,7 +42,7 @@
"alarm": "0",
"tbl": "555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555"
},
"name": "Test%20Room",
"name": "Test Room",
"id": "ROOM.121",
"sensor_state": {
"s": "1",
Expand Down
4 changes: 2 additions & 2 deletions tests/fixtures/test_manual_off.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"hw_hist": "5",
"hw_ext_temp": "0"
},
"device_name": "Smart%20HubSwitch",
"device_name": "Smart HubSwitch",
"id": "wunda.0"
},
"1": {
Expand Down Expand Up @@ -76,7 +76,7 @@
"alarm": "0",
"tbl": "555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555"
},
"name": "Test%20Room",
"name": "Test Room",
"id": "ROOM.121",
"sensor_state": {
"s": "1",
Expand Down
4 changes: 2 additions & 2 deletions tests/fixtures/test_set_presets.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"hw_hist": "5",
"hw_ext_temp": "0"
},
"device_name": "Smart%20HubSwitch",
"device_name": "Smart HubSwitch",
"id": "wunda.0"
},
"1": {
Expand Down Expand Up @@ -76,7 +76,7 @@
"alarm": "0",
"tbl": "555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555"
},
"name": "Test%20Room",
"name": "Test Room",
"id": "ROOM.121",
"sensor_state": {
"s": "1",
Expand Down
4 changes: 2 additions & 2 deletions tests/fixtures/test_set_temperature.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"hw_hist": "5",
"hw_ext_temp": "0"
},
"device_name": "Smart%20HubSwitch",
"device_name": "Smart HubSwitch",
"id": "wunda.0"
},
"121": {
Expand Down Expand Up @@ -42,7 +42,7 @@
"alarm": "0",
"tbl": "555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555"
},
"name": "Test%20Room",
"name": "Test Room",
"id": "ROOM.121",
"sensor_state": {
"s": "1",
Expand Down
4 changes: 2 additions & 2 deletions tests/fixtures/test_trvs_only.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"hw_hist": "5",
"hw_ext_temp": "0"
},
"device_name": "Smart%20HubSwitch",
"device_name": "Smart HubSwitch",
"id": "wunda.0"
},
"31": {
Expand Down Expand Up @@ -52,7 +52,7 @@
},
"121": {
"device_type": "ROOM",
"name": "Test%20Room",
"name": "Test Room",
"id": "ROOM.121",
"state": {
"t_lo": "14.00",
Expand Down

0 comments on commit d107104

Please sign in to comment.