From 3ca2acc9f850ca9965265d204a54d7492746a993 Mon Sep 17 00:00:00 2001 From: Krisjanis Lejejs Date: Thu, 29 Dec 2022 17:02:53 +0000 Subject: [PATCH] Fix typing errors for older Python versions --- ThermiaOnlineAPI/api/ThermiaAPI.py | 3 ++- ThermiaOnlineAPI/model/HeatPump.py | 18 +++++++++--------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/ThermiaOnlineAPI/api/ThermiaAPI.py b/ThermiaOnlineAPI/api/ThermiaAPI.py index 7850881..aa856ee 100644 --- a/ThermiaOnlineAPI/api/ThermiaAPI.py +++ b/ThermiaOnlineAPI/api/ThermiaAPI.py @@ -5,6 +5,7 @@ from requests import cookies import json import hashlib +from typing import Dict, Union from ThermiaOnlineAPI.const import ( REG_GROUP_HOT_WATER, @@ -281,7 +282,7 @@ def __get_switch_register_index_and_value_from_group_by_register_name( "registerValue": int(register_value), } - def get_group_hot_water(self, device: ThermiaHeatPump) -> dict[str, int | None]: + def get_group_hot_water(self, device: ThermiaHeatPump) -> Dict[str, Union[int, None]]: register_data: list = self.__get_register_group(device.id, REG_GROUP_HOT_WATER) hot_water_switch_data = ( diff --git a/ThermiaOnlineAPI/model/HeatPump.py b/ThermiaOnlineAPI/model/HeatPump.py index c1b08d0..edd8390 100644 --- a/ThermiaOnlineAPI/model/HeatPump.py +++ b/ThermiaOnlineAPI/model/HeatPump.py @@ -4,7 +4,7 @@ import sys from ..utils.utils import pretty_print_except -from typing import TYPE_CHECKING, Dict +from typing import TYPE_CHECKING, Dict, Union from ThermiaOnlineAPI.const import ( REG_BRINE_IN, @@ -34,7 +34,7 @@ if TYPE_CHECKING: from ..api.ThermiaAPI import ThermiaAPI -DEFAULT_REGISTER_INDEXES: Dict[str, int | None] = { +DEFAULT_REGISTER_INDEXES: Dict[str, Union[int, None]] = { "temperature": None, "operation_mode": None, "hot_water_switch": None, @@ -58,7 +58,7 @@ def __init__(self, device_data: dict, api_interface: "ThermiaAPI"): self.__group_operational_status = None self.__group_operational_time = None self.__group_operational_operation = None - self.__group_hot_water: dict[str, int | None] = { + self.__group_hot_water: Dict[str, Union[int, None]] = { "hot_water_switch": None, "hot_water_boost_switch": None, } @@ -101,10 +101,10 @@ def get_register_indexes(self): def set_register_index_operation_mode(self, register_index: int): self.__register_indexes["operation_mode"] = register_index - def set_register_index_hot_water_switch(self, register_index: int | None): + def set_register_index_hot_water_switch(self, register_index: Union[int, None]): self.__register_indexes["hot_water_switch"] = register_index - def set_register_index_hot_water_boost_switch(self, register_index: int | None): + def set_register_index_hot_water_boost_switch(self, register_index: Union[int, None]): self.__register_indexes["hot_water_boost_switch"] = register_index def set_temperature(self, temperature: int): @@ -304,7 +304,7 @@ def __set_historical_data_registers(self): self.__historical_data_registers_map = data_map - def __get_register_from_operational_status(self, register_name: str) -> dict | None: + def __get_register_from_operational_status(self, register_name: str) -> Union[dict, None]: data = [ d for d in self.__group_operational_status or [] @@ -337,7 +337,7 @@ def __get_value_by_key_and_register_name_from_operational_status( return None - def __get_all_operational_statuses_from_operational_status(self) -> ChainMap | None: + def __get_all_operational_statuses_from_operational_status(self) -> Union[ChainMap, None]: data = self.__get_register_from_operational_status(REG_OPERATIONAL_STATUS_PRIO1) if data is None: @@ -680,11 +680,11 @@ def is_hot_water_switch_available(self): return self.__group_hot_water is not None @property - def hot_water_switch_state(self) -> int | None: + def hot_water_switch_state(self) -> Union[int, None]: return self.__group_hot_water["hot_water_switch"] @property - def hot_water_boost_switch_state(self) -> int | None: + def hot_water_boost_switch_state(self) -> Union[int, None]: return self.__group_hot_water["hot_water_boost_switch"] ###########################################################################