Skip to content

Commit

Permalink
Merge pull request #906 from cjkrolak/lint_fixes_02_2025
Browse files Browse the repository at this point in the history
several lint fixes
  • Loading branch information
cjkrolak authored Feb 2, 2025
2 parents 1dde9e7 + 4665182 commit 0bdb558
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 36 deletions.
22 changes: 12 additions & 10 deletions conf.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
# Configuration file for the Sphinx documentation builder.
#
# For the full list of built-in configuration values, see the documentation:
# https://www.sphinx-doc.org/en/master/usage/configuration.html
"""
Configuration file for the Sphinx documentation builder.
# -- Path setup --------------------------------------------------------------
For the full list of built-in configuration values, see the documentation:
https://www.sphinx-doc.org/en/master/usage/configuration.html
-- Path setup --------------------------------------------------------------
If extensions (or modules to document with autodoc) are in another directory,
add these directories to sys.path here. If the directory is relative to the
documentation root, use os.path.abspath to make it absolute, like shown here.
"""

# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#
import os
import sys

Expand All @@ -18,7 +20,7 @@
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information

project = "ThermostatSupervisor"
copyright = "2024, Christopher Krolak"
copyright = "2024, Christopher Krolak" # noqa W0622
author = "Christopher Krolak"

# -- General configuration ---------------------------------------------------
Expand Down
13 changes: 13 additions & 0 deletions tests/test_blink_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,19 @@ class IntegrationTest(utc.IntegrationTest):
"""

def setUpIntTest(self):
"""
Set up the integration test environment for the Blink thermostat.
This method initializes common setup procedures and prints the test name.
It also configures the command-line arguments required for the Blink thermostat
integration test, including the module name, thermostat type, default zone,
poll time, reconnect time, tolerance, thermostat mode, and the number of
measurements.
Attributes:
unit_test_argv (list): List of command-line arguments for the Blink
thermostat.
mod (module): The Blink thermostat module.
mod_config (module): The configuration module for the Blink thermostat.
"""
self.setup_common()
self.print_test_name()

Expand Down
18 changes: 18 additions & 0 deletions tests/test_sht31_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,24 @@ class IntegrationTest(utc.IntegrationTest):
"""

def setUpIntTest(self):
"""
Set up the integration test environment for the SHT31 thermostat.
This method initializes common setup procedures and prints the test name.
It also configures the command-line arguments required for the test.
The command-line arguments include:
- Module name ("supervise.py")
- Thermostat type ("sht31")
- Zone configuration (default zone from sht31_config)
- Poll time in seconds (5)
- Reconnect time in seconds (12)
- Tolerance value (2)
- Thermostat mode ("UNKNOWN_MODE")
- Number of measurements (6)
Attributes:
unit_test_argv (list): List of command-line arguments for the test.
mod (module): The SHT31 module.
mod_config (module): The SHT31 configuration module.
"""
self.setup_common()
self.print_test_name()

Expand Down
38 changes: 20 additions & 18 deletions tests/unit_test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ class FunctionalIntegrationTest(IntegrationTest):

metadata_field = None # thermostat-specific
metadata_type = str # thermostat-specific
trait_field = None # thermostat-specific

def test_a_thermostat_basic_checkout(self):
"""
Expand Down Expand Up @@ -597,10 +598,10 @@ def parse_user_inputs_dict(self, key):
(list) of actual values.
"""
actual_values = []
for x in range(0, len(self.test_fields)):
for _, test_field in enumerate(self.test_fields):
actual_values.append(
self.uip.get_user_inputs(
list(self.uip.user_inputs.keys())[0], key, self.test_fields[x][1]
list(self.uip.user_inputs.keys())[0], key, test_field[1]
)
)
return actual_values
Expand All @@ -625,16 +626,16 @@ def verify_parsed_values(self, parent_key=None):
else:
expected_values = self.get_expected_vals_dict(parent_key)

for parent_key, child_dict in expected_values.items():
for local_parent_key, child_dict in expected_values.items():
for c_key, _ in child_dict.items():
self.assertEqual(
expected_values[parent_key][c_key],
self.uip.get_user_inputs(parent_key, c_key),
f"expected({type(expected_values[parent_key][c_key])})"
f" {expected_values[parent_key][c_key]} != "
expected_values[local_parent_key][c_key],
self.uip.get_user_inputs(local_parent_key, c_key),
f"expected({type(expected_values[local_parent_key][c_key])})"
f" {expected_values[local_parent_key][c_key]} != "
f"actual("
f"{type(self.uip.get_user_inputs(parent_key, c_key))})"
f" {self.uip.get_user_inputs(parent_key, c_key)}",
f"{type(self.uip.get_user_inputs(local_parent_key, c_key))})"
f" {self.uip.get_user_inputs(local_parent_key, c_key)}",
)

def initialize_user_inputs(self):
Expand Down Expand Up @@ -682,23 +683,24 @@ def test_parser_input_file(self):
parser.add_argument("-f", type=argparse.FileType("r", encoding="UTF-8"))
argv = ["-f" + input_file] # space after sflag is appended onto str
args = parser.parse_args(argv)
print(
"args returned: %s" % (" ".join(f"{k}={v}" for k, v in vars(args).items()))
)
print(f"args returned: {' '.join(f'{k}={v}' for k, v in vars(args).items())}")
# assert(args.thermostat_type == "emulator")

def is_valid_file(self, parser, arg):
"""
Verify file input is valid.
inputs:
arg(str): file name with path.
returns:
open file handle
Verify if the provided file path is valid and return a file handle.
Args:
parser (argparse.ArgumentParser): The argument parser instance.
arg (str): The file name with path.
Returns:
file object: The opened file handle if the file exists.
Raises:
ArgumentError: If the file does not exist.
"""
arg = arg.strip() # remove any leading spaces
if not os.path.exists(arg):
parser.error(f"The file {os.path.abspath(arg)} does not exist!")
return None
else:
return open(arg, "rt", encoding="utf8") # return a file handle

Expand Down
5 changes: 3 additions & 2 deletions thermostatsupervisor/mmm.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import traceback
import urllib
from dns.exception import DNSException
from typing import Union

# local imports
from thermostatsupervisor import mmm_config
Expand Down Expand Up @@ -149,7 +150,7 @@ def get_all_metadata(self, zone, retry=False) -> list:
del retry # not used
return self.get_meta_data_dict(zone)

def get_metadata(self, zone, trait=None, parameter=None) -> (dict, str):
def get_metadata(self, zone, trait=None, parameter=None) -> Union[dict, str]:
"""
Get the current thermostat metadata settings.
Expand All @@ -167,7 +168,7 @@ def get_metadata(self, zone, trait=None, parameter=None) -> (dict, str):
else:
return self.get_meta_data_dict(zone)[parameter]["raw"]

def get_latestdata(self, zone, debug=False) -> (dict, str):
def get_latestdata(self, zone, debug=False) -> Union[dict, str]:
"""
Get the current thermostat latest data.
Expand Down
11 changes: 6 additions & 5 deletions thermostatsupervisor/sht31.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import threading
import time
import traceback
from typing import Union

# third party imports
import requests
Expand Down Expand Up @@ -220,7 +221,7 @@ def get_metadata(self, zone, trait=None, parameter=None, retry=True):
func_name=1,
)
time.sleep(self.retry_delay)
self.get_metadata(zone, parameter=parameter, retry=False)
return self.get_metadata(zone, parameter=parameter, retry=False)
else:
raise RuntimeError(
"FATAL ERROR: SHT31 server is not responding"
Expand Down Expand Up @@ -315,7 +316,7 @@ def get_metadata(self, trait=None, parameter=None, retry=True):
func_name=1,
)
time.sleep(self.retry_delay)
self.get_metadata(parameter=None, retry=False)
return self.get_metadata(parameter=None, retry=False)
else:
raise RuntimeError(
"FATAL ERROR: SHT31 server is not responding"
Expand All @@ -333,7 +334,7 @@ def get_metadata(self, trait=None, parameter=None, retry=True):
func_name=1,
)
time.sleep(self.retry_delay)
self.get_metadata(parameter=parameter, retry=False)
return self.get_metadata(parameter=parameter, retry=False)
else:
raise RuntimeError(
"FATAL ERROR: SHT31 server is not responding"
Expand All @@ -355,7 +356,7 @@ def get_metadata(self, trait=None, parameter=None, retry=True):
func_name=1,
)
time.sleep(self.retry_delay)
self.get_metadata(parameter=parameter, retry=False)
return self.get_metadata(parameter=parameter, retry=False)
else:
raise KeyError(
f"FATAL ERROR: SHT31 server response did not contain "
Expand All @@ -373,7 +374,7 @@ def get_display_temp(self) -> float:
"""
return float(self.get_metadata(parameter=self.tempfield))

def get_display_humidity(self) -> (float, None):
def get_display_humidity(self) -> Union[float, None]:
"""
Return Humidity.
Expand Down
2 changes: 1 addition & 1 deletion thermostatsupervisor/sht31_flask_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ def get_iwlist_wifi_strength(self, cell=0) -> float: # noqa R0201
r"\s+Signal level=(?P<signal_level_dBm>.+) d.+$"
),
re.compile(
r"^Signal level=(?P<signal_quality>\d+)/" r"(?P<signal_total>\d+).*$"
r"^Signal level=(?P<signal_quality>\d+)/(?P<signal_total>\d+).*$"
),
]

Expand Down
1 change: 1 addition & 0 deletions thermostatsupervisor/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -779,6 +779,7 @@ def is_valid_file(self, arg):
arg = arg.strip() # remove any leading spaces
if not os.path.exists(arg):
self.parser.error(f"The file {os.path.abspath(arg)} does not exist!")
return None
else:
return open(arg, "r", encoding="utf8") # return a file handle

Expand Down

0 comments on commit 0bdb558

Please sign in to comment.