Skip to content

Commit

Permalink
Fix Ruf comment issue
Browse files Browse the repository at this point in the history
  • Loading branch information
sHedC committed Feb 8, 2024
1 parent 3097aff commit efa9619
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/push-main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
19 changes: 13 additions & 6 deletions masterthermconnect/api.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Mastertherm API Client Class, handle integration."""

import asyncio
import logging
import time
Expand Down Expand Up @@ -69,6 +70,7 @@ def __init__(
Raises:
MasterthermUnsupportedVersion: API Version is not supported.
"""
if api_version not in SUPPORTED_API_VERSIONS:
raise MasterthermUnsupportedVersion(
Expand Down Expand Up @@ -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
Expand All @@ -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":
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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&"
Expand Down Expand Up @@ -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 = (
Expand All @@ -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:
Expand All @@ -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,
)

Expand Down
13 changes: 13 additions & 0 deletions masterthermconnect/controller.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Mastertherm Controller, for handling Mastertherm Data."""

import logging

from datetime import datetime, timedelta
Expand Down Expand Up @@ -46,6 +47,7 @@ def __init__(
Raises:
MasterthermUnsupportedVersion: API Version is not supported.
"""
self.__api = MasterthermAPI(
username, password, session, api_version=api_version
Expand Down Expand Up @@ -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"]
Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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():
Expand All @@ -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
Expand All @@ -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
Expand All @@ -513,6 +522,7 @@ def get_device_data(self, module_id, unit_id) -> dict:
Returns:
Device Normalised Data.
"""
data = {}
key = module_id + "_" + unit_id
Expand All @@ -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)

Expand All @@ -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
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit efa9619

Please sign in to comment.