Skip to content

Commit

Permalink
Partially revert #1916 (#1917)
Browse files Browse the repository at this point in the history
* Partially revert #1916

* Partially revert #1916

* Update changelog.md
  • Loading branch information
SukramJ authored Dec 14, 2024
1 parent 77a6b4c commit bf39c58
Show file tree
Hide file tree
Showing 16 changed files with 36 additions and 31 deletions.
2 changes: 1 addition & 1 deletion changelog.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Version 2024.12.4 (2024-12-14)

- Add missing encoding to unquote
- Ensure default encoding is ISO-8859-1
- Ensure default encoding is ISO-8859-1 where needed

# Version 2024.12.3 (2024-12-14)

Expand Down
4 changes: 2 additions & 2 deletions hahomematic/caches/persistent.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
FILE_DEVICES,
FILE_PARAMSETS,
INIT_DATETIME,
ISO_8859_1,
UTF_8,
DataOperationResult,
DeviceDescription,
ParameterData,
Expand Down Expand Up @@ -106,7 +106,7 @@ async def load(self) -> DataOperationResult:
def _load() -> DataOperationResult:
with open(
file=os.path.join(self._cache_dir, self._filename),
encoding=ISO_8859_1,
encoding=UTF_8,
) as fptr:
data = orjson.loads(fptr.read())
if (converted_hash := hash_sha256(value=data)) == self.last_hash_saved:
Expand Down
4 changes: 2 additions & 2 deletions hahomematic/caches/visibility.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from typing import Any, Final

from hahomematic import central as hmcu, support as hms
from hahomematic.const import CLICK_EVENTS, ISO_8859_1, UN_IGNORE_WILDCARD, Parameter, ParamsetKey
from hahomematic.const import CLICK_EVENTS, UN_IGNORE_WILDCARD, UTF_8, Parameter, ParamsetKey
from hahomematic.model.custom import get_required_parameters
from hahomematic.support import element_matches_key, reduce_args

Expand Down Expand Up @@ -706,7 +706,7 @@ def _load() -> None:
self._storage_folder,
_FILE_CUSTOM_UN_IGNORE_PARAMETERS,
),
encoding=ISO_8859_1,
encoding=UTF_8,
) as fptr:
for file_line in fptr.readlines():
if "#" not in file_line:
Expand Down
4 changes: 2 additions & 2 deletions hahomematic/client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
from hahomematic.model.device import Device
from hahomematic.model.support import convert_value
from hahomematic.support import (
build_headers,
build_xml_rpc_headers,
build_xml_rpc_uri,
get_device_address,
is_channel_address,
Expand Down Expand Up @@ -1600,7 +1600,7 @@ async def get_xml_rpc_proxy(
"""Return a XmlRPC proxy for backend communication."""
central_config = self.central.config
xml_rpc_headers = (
build_headers(
build_xml_rpc_headers(
username=central_config.username,
password=central_config.password,
)
Expand Down
7 changes: 4 additions & 3 deletions hahomematic/client/json_rpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
ISO_8859_1,
PATH_JSON_RPC,
REGA_SCRIPT_PATH,
UTF_8,
DeviceDescription,
Interface,
ParameterData,
Expand Down Expand Up @@ -307,7 +308,7 @@ def _load_script(script_name: str) -> str | None:
script_file = os.path.join(
Path(__file__).resolve().parent, REGA_SCRIPT_PATH, script_name
)
if script := Path(script_file).read_text(encoding=ISO_8859_1):
if script := Path(script_file).read_text(encoding=UTF_8):
self._script_cache[script_name] = script
return script
return None
Expand Down Expand Up @@ -400,14 +401,14 @@ async def _do_post(
async def _get_json_reponse(self, response: ClientResponse) -> dict[str, Any] | Any:
"""Return the json object from response."""
try:
return await response.json(encoding=ISO_8859_1)
return await response.json(encoding=UTF_8)
except ValueError as ver:
_LOGGER.debug(
"DO_POST: ValueError [%s] Unable to parse JSON. Trying workaround",
reduce_args(args=ver.args),
)
# Workaround for bug in CCU
return orjson.loads((await response.read()).decode(ISO_8859_1))
return orjson.loads((await response.read()).decode(encoding=UTF_8))

async def logout(self) -> None:
"""Logout of CCU."""
Expand Down
4 changes: 3 additions & 1 deletion hahomematic/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@
DEFAULT_VERIFY_TLS: Final = False
DEFAULT_WAIT_FOR_CALLBACK: Final[int | None] = None

# Default encoding for all Homematic service calls, persistent cache and script files
# Default encoding for json service calls, persistent cache
UTF_8: Final = "utf-8"
# Default encoding for xmlrpc service calls and script files
ISO_8859_1: Final = "iso-8859-1"

MAX_WAIT_FOR_CALLBACK: Final = 60
Expand Down
4 changes: 2 additions & 2 deletions hahomematic/hmcli.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

from hahomematic import __version__
from hahomematic.const import ParamsetKey
from hahomematic.support import build_headers, build_xml_rpc_uri, get_tls_context
from hahomematic.support import build_xml_rpc_headers, build_xml_rpc_uri, get_tls_context


def main() -> None:
Expand Down Expand Up @@ -104,7 +104,7 @@ def main() -> None:
path=args.path,
tls=args.tls,
)
headers = build_headers(username=args.username, password=args.password)
headers = build_xml_rpc_headers(username=args.username, password=args.password)
context = None
if args.tls:
context = get_tls_context(verify_tls=args.verify)
Expand Down
4 changes: 2 additions & 2 deletions hahomematic/rega_scripts/fetch_all_device_data.fn
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
!# fetch_all_device_data.fn v2.2 / file is ISO-8859-1 encoded
!# fetch_all_device_data.fn v2.2
!# This script fetches all device data required to initialize the entities without affecting the duty cycle.
!#
!# Original script: https://github.com/ioBroker/ioBroker.hm-rega/blob/master/regascripts/datapoints.fn
Expand All @@ -10,7 +10,7 @@
!# modified by: SukramJ https://github.com/SukramJ && Baxxy13 https://github.com/Baxxy13
!# v2.2 - 09/2023
!#
!# Das Interface wird durch die Integration an 'sUse_Interface' �bergeben.
!# Das Interface wird durch die Integration an 'sUse_Interface' übergeben.
!# Nutzbare Interfaces: BidCos-RF, BidCos-Wired, HmIP-RF, VirtualDevices
!# Zum Testen direkt auf der Homematic-Zentrale muss das Interface wie folgt eingetragen werden: sUse_Interface = "HmIP-RF";

Expand Down
4 changes: 2 additions & 2 deletions hahomematic/rega_scripts/get_program_descriptions.fn
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
!# get_program_descriptions.fn / file is ISO-8859-1 encoded
!# Erstellt in Erg�nzung zu https://github.com/eq-3/occu/blob/45b38865f6b60f16f825b75f0bdc8a9738831ee0/WebUI/www/api/methods/sysvar/getall.tcl
!# get_program_descriptions.fn
!# Erstellt in Ergänzung zu https://github.com/eq-3/occu/blob/45b38865f6b60f16f825b75f0bdc8a9738831ee0/WebUI/www/api/methods/sysvar/getall.tcl
!# Erweitert das Script um "description"
!#

Expand Down
6 changes: 3 additions & 3 deletions hahomematic/rega_scripts/get_serial.fn
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
!# get_serial / file is ISO-8859-1 encoded
!# get_serial
!#
!# Erstellt durch @baxxy13 2022-04-09
!#
!# Dieses Script liefert die Seriennummer des Funkmoduls in folgender Priorisierung zur�ck:
!# Dieses Script liefert die Seriennummer des Funkmoduls in folgender Priorisierung zurück:
!# 1. /var/board_sgtin
!# 2. /var/board_serial
!# 3. /sys/module/plat_eq3ccu2/parameters/board_serial
!#
!# Dieses Script wird als Ersatz f�r JsonRPC CCU.getSerial verwendet.
!# Dieses Script wird als Ersatz für JsonRPC CCU.getSerial verwendet.
!#

string serial;
Expand Down
4 changes: 2 additions & 2 deletions hahomematic/rega_scripts/get_system_variable_descriptions.fn
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
!# get_system_variable_descriptions.fn / file is ISO-8859-1 encoded
!# Erstellt in Erg�nzung zu https://github.com/eq-3/occu/blob/45b38865f6b60f16f825b75f0bdc8a9738831ee0/WebUI/www/api/methods/sysvar/getall.tcl
!# get_system_variable_descriptions.fn
!# Erstellt in Ergänzung zu https://github.com/eq-3/occu/blob/45b38865f6b60f16f825b75f0bdc8a9738831ee0/WebUI/www/api/methods/sysvar/getall.tcl
!# Erweitert das Script um "description"
!#

Expand Down
2 changes: 1 addition & 1 deletion hahomematic/rega_scripts/set_system_variable.fn
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
!# set_system_variable / file is ISO-8859-1 encoded
!# set_system_variable
!#
!# Erstellt durch @baxxy13 2022-04-11
!#
Expand Down
2 changes: 1 addition & 1 deletion hahomematic/support.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def build_xml_rpc_uri(
return f"{scheme}://{host}{s_port}{path}"


def build_headers(
def build_xml_rpc_headers(
username: str,
password: str,
) -> list[tuple[str, str]]:
Expand Down
4 changes: 2 additions & 2 deletions hahomematic_support/client_local.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from hahomematic.config import WAIT_FOR_CALLBACK
from hahomematic.const import (
DP_KEY_VALUE,
ISO_8859_1,
UTF_8,
CallSource,
CommandRxMode,
DeviceDescription,
Expand Down Expand Up @@ -328,7 +328,7 @@ async def _load_json_file(self, anchor: str, resource: str, filename: str) -> An
def _load() -> Any | None:
with open(
file=os.path.join(package_path, resource, filename),
encoding=ISO_8859_1,
encoding=UTF_8,
) as fptr:
return orjson.loads(fptr.read())

Expand Down
2 changes: 1 addition & 1 deletion tests/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ def _load_json_file(anchor: str, resource: str, filename: str) -> Any | None:
package_path = str(importlib.resources.files(anchor))
with open(
file=os.path.join(package_path, resource, filename),
encoding=hahomematic_const.ISO_8859_1,
encoding=hahomematic_const.UTF_8,
) as fptr:
return orjson.loads(fptr.read())

Expand Down
10 changes: 6 additions & 4 deletions tests/test_support.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
get_event_name,
)
from hahomematic.support import (
build_headers,
build_xml_rpc_headers,
build_xml_rpc_uri,
changed_within_seconds,
check_or_create_directory,
Expand Down Expand Up @@ -107,11 +107,13 @@ def test_build_xml_rpc_uri() -> None:

def test_build_headers() -> None:
"""Test build_xml_rpc_uri."""
assert build_headers(username="Martin", password="") == [
assert build_xml_rpc_headers(username="Martin", password="") == [
("Authorization", "Basic TWFydGluOg==")
]
assert build_headers(username="", password="asdf") == [("Authorization", "Basic OmFzZGY=")]
assert build_headers(username="Martin", password="asdf") == [
assert build_xml_rpc_headers(username="", password="asdf") == [
("Authorization", "Basic OmFzZGY=")
]
assert build_xml_rpc_headers(username="Martin", password="asdf") == [
("Authorization", "Basic TWFydGluOmFzZGY=")
]

Expand Down

0 comments on commit bf39c58

Please sign in to comment.