From efa96199fd2c0fec0549362c2d29215798c93b97 Mon Sep 17 00:00:00 2001 From: Richard Holmes Date: Thu, 8 Feb 2024 09:21:13 +0000 Subject: [PATCH] Fix Ruf comment issue --- .github/workflows/push-main.yml | 2 +- masterthermconnect/api.py | 19 +++++++++++++------ masterthermconnect/controller.py | 13 +++++++++++++ 3 files changed, 27 insertions(+), 7 deletions(-) diff --git a/.github/workflows/push-main.yml b/.github/workflows/push-main.yml index b444c46..0316632 100644 --- a/.github/workflows/push-main.yml +++ b/.github/workflows/push-main.yml @@ -40,5 +40,5 @@ jobs: - name: Upload coverage to Codecov if: ${{ matrix.os == 'ubuntu-latest' && matrix.python-version == '3.11' }} - uses: codecov/codecov-action@v4 + uses: codecov/codecov-action@v3 files: ./coverage.xml diff --git a/masterthermconnect/api.py b/masterthermconnect/api.py index cc98fb4..d05a86b 100644 --- a/masterthermconnect/api.py +++ b/masterthermconnect/api.py @@ -1,4 +1,5 @@ """Mastertherm API Client Class, handle integration.""" + import asyncio import logging import time @@ -69,6 +70,7 @@ def __init__( Raises: MasterthermUnsupportedVersion: API Version is not supported. + """ if api_version not in SUPPORTED_API_VERSIONS: raise MasterthermUnsupportedVersion( @@ -321,6 +323,7 @@ def get_url(self) -> str: Returns: URL(str): The API URL for the version. + """ if self.__api_version == "v1": return URL_BASE @@ -337,6 +340,7 @@ async def connect(self) -> dict: MasterthermConnectionError - Failed to Connect MasterthermAuthenticationError - Failed to Authenticate MasterthermUnsupportedRole - Role is not in supported roles + """ response_json = await self.__connect_refresh() if self.__api_version == "v2": @@ -372,6 +376,7 @@ async def get_device_info(self, module_id: str, unit_id: str) -> dict: MasterthermTokenInvalid - Token has expired or is invalid MasterthermResponseFormatError - Some other issue, probably temporary MasterthermServerTimeoutError - Server Timed Out more than once. + """ retry = False params = f"moduleid={module_id}&unitid={unit_id}&application=android" @@ -418,6 +423,7 @@ async def get_device_data( MasterthermResponseFormatError - Some other issue, probably temporary MasterthermPumpDisconnected - Pump is unavailable, disconnected or offline. MasterthermServerTimeoutError - Server Timed Out more than once. + """ retry = False params = f"moduleId={module_id}&deviceId={unit_id}&application=android&" @@ -503,6 +509,7 @@ async def set_device_data( MasterthermTokenInvalid - Token has expired or is invalid MasterthermResponseFormatError - Some other issue, probably temporary MasterthermServerTimeoutError - Server Timed Out more than once. + """ retry = False params = ( @@ -514,9 +521,9 @@ async def set_device_data( _LOGGER.info("Set Device Reg %s:%s:%s:%s", module_id, unit_id, register, value) try: response_json = await self.__post( - url=URL_POSTUPDATE - if self.__api_version == "v1" - else URL_POSTUPDATE_NEW, + url=( + URL_POSTUPDATE if self.__api_version == "v1" else URL_POSTUPDATE_NEW + ), params=params, ) except MasterthermTokenInvalid as ex: @@ -530,9 +537,9 @@ async def set_device_data( if retry: await asyncio.sleep(0.5) response_json = await self.__post( - url=URL_POSTUPDATE - if self.__api_version == "v1" - else URL_POSTUPDATE_NEW, + url=( + URL_POSTUPDATE if self.__api_version == "v1" else URL_POSTUPDATE_NEW + ), params=params, ) diff --git a/masterthermconnect/controller.py b/masterthermconnect/controller.py index 5cb8cb5..b3a14eb 100644 --- a/masterthermconnect/controller.py +++ b/masterthermconnect/controller.py @@ -1,4 +1,5 @@ """Mastertherm Controller, for handling Mastertherm Data.""" + import logging from datetime import datetime, timedelta @@ -46,6 +47,7 @@ def __init__( Raises: MasterthermUnsupportedVersion: API Version is not supported. + """ self.__api = MasterthermAPI( username, password, session, api_version=api_version @@ -189,6 +191,7 @@ async def __get_hp_updates(self, full_load: bool = False) -> None: MasterthermAuthenticationError: Failed to Authenticate MasterthermUnsupportedRole: Role is not in supported roles MasterthermServerTimeoutError: Server Timed Out more than once. + """ for device in self.__devices.values(): module_id = device["info"]["module_id"] @@ -275,6 +278,7 @@ async def connect(self, reload_modules: bool = False) -> bool: MasterthermAuthenticationError: Failed to Authenticate MasterthermUnsportedRole: Role is not supported by API MasterthermServerTimeoutError: Server Timed Out more than once. + """ result = await self.__api.connect() @@ -322,6 +326,7 @@ def set_refresh_rate( data_refresh_seconds: Default is 60 seconds, delay between refresh of data data_offset_seconds: Default is 0, offset in the past from last update time full_refresh_minutes: Default is 15, minutes between doing updates and full data refresh. + """ if info_refresh_minutes < 0: if self.__info_update_min is None: @@ -362,6 +367,7 @@ async def refresh(self, full_load: bool = False) -> bool: MasterthermAuthenticationError: Failed to Authenticate MasterthermUnsupportedRole: Role is not in supported roles MasterthermServerTimeoutError: Server Timed Out more than once. + """ if not self.__api_connected: return False @@ -459,6 +465,7 @@ def get_devices(self) -> dict: Returns: devices (dict): All the devices associated with the login + """ device_return = {} for device_id, device in self.__devices.items(): @@ -475,6 +482,7 @@ def get_device_info(self, module_id, unit_id) -> dict: Returns: info (dict): Device information. + """ info = {} key = module_id + "_" + unit_id @@ -493,6 +501,7 @@ def get_device_registers(self, module_id, unit_id, last_updated=False) -> dict: Returns: data (dict): Device Raw Data or Updated Data. + """ data = {} key = module_id + "_" + unit_id @@ -513,6 +522,7 @@ def get_device_data(self, module_id, unit_id) -> dict: Returns: Device Normalised Data. + """ data = {} key = module_id + "_" + unit_id @@ -535,6 +545,7 @@ def get_device_data_item(self, module_id: str, unit_id: str, entry: str) -> any: Raises: MasterthermEntryNotFound - Entry is not valid. + """ data = self.get_device_data(module_id, unit_id) @@ -561,6 +572,7 @@ def get_diagnostics_data(self, hide_sensitive: bool = True) -> dict: Returns: dict: Returns a dict of all the data for all modules. + """ diagnostics_data = {} new_module_id = 1111 @@ -633,6 +645,7 @@ async def set_device_data_item( MasterthermAuthenticationError - Failed to Authenticate MasterthermEntryNotFound - Entry is not valid. MasterthermServerTimeoutError - Server Timed Out more than once. + """ # Split the entry into its components and find the mapping and data type. # Check if in both read and write map, if not in both stop.