Skip to content

Commit

Permalink
Merge pull request #904 from cjkrolak/copilot_fixes
Browse files Browse the repository at this point in the history
several copilot suggested fixes
  • Loading branch information
cjkrolak authored Feb 1, 2025
2 parents dc0196a + bd84cd0 commit 1dde9e7
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 27 deletions.
27 changes: 13 additions & 14 deletions thermostatsupervisor/emulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import random
import time
import traceback
from typing import Union

# local imports
from thermostatsupervisor import emulator_config
Expand Down Expand Up @@ -54,14 +55,16 @@ def get_target_zone_id(self, zone=0):
"""
return zone

def get_all_metadata(self, zone=None):
"""Get all thermostat meta data for zone from kumocloud.
def get_all_metadata(self, zone=None, retry=False):
"""Get all thermostat meta data for zone from emulator.
inputs:
zone(int): specified zone, if None will print all zones.
retry(bool): if True will retry the request, not currrently implemented.
returns:
(dict): JSON dict
"""
del retry # unused on emulator
return self.get_metadata(zone)

def get_metadata(self, zone=None, trait=None, parameter=None):
Expand Down Expand Up @@ -107,11 +110,7 @@ def print_all_thermostat_metadata(self, zone):


class ThermostatZone(tc.ThermostatCommonZone):
"""
KumoCloud single zone from kumocloud.
Class needs to be updated for multi-zone support.
"""
"""Emulator thermostat zone functions."""

def __init__(self, Thermostat_obj, verbose=True):
"""
Expand Down Expand Up @@ -219,7 +218,7 @@ def get_display_temp(self) -> float: # used
emulator_config.NORMAL_TEMP_VARIATION,
)

def get_display_humidity(self) -> (float, None):
def get_display_humidity(self) -> Union[float, None]:
"""
Refresh the cached zone information and return IndoorHumidity
with random +/-1% noise value.
Expand Down Expand Up @@ -530,13 +529,13 @@ def set_cool_setpoint(self, temp: int) -> None:

def refresh_zone_info(self, force_refresh=False):
"""
Refresh zone info from KumoCloud.
inputs:
force_refresh(bool): if True, ignore expiration timer.
returns:
None, zone_data is refreshed.
Refreshes the zone information if the current time exceeds the fetch interval
or if the force_refresh flag is set to True.
Args:
force_refresh (bool): If True, forces the refresh of zone information
regardless of the fetch interval. Default is False.
"""

now_time = time.time()
# refresh if past expiration date or force_refresh option
if force_refresh or (
Expand Down
5 changes: 3 additions & 2 deletions thermostatsupervisor/honeywell.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import pprint
import time
import traceback
from typing import Union

# local imports
from thermostatsupervisor import email_notification
Expand Down Expand Up @@ -137,7 +138,7 @@ def get_all_metadata(self, zone=honeywell_config.default_zone, retry=False) -> d

def get_metadata(
self, zone=honeywell_config.default_zone, trait=None, parameter=None
) -> (dict, str):
) -> Union[dict, str]:
"""
Return the current thermostat metadata settings.
Expand Down Expand Up @@ -459,7 +460,7 @@ def get_display_temp(self) -> float: # used
"""
return float(self.get_indoor_temperature_raw())

def get_display_humidity(self) -> (float, None):
def get_display_humidity(self) -> Union[float, None]:
"""
Refresh the cached zone information then return IndoorHumidity.
Expand Down
3 changes: 2 additions & 1 deletion thermostatsupervisor/kumocloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import pprint
import time
import traceback
from typing import Union

# third party imports

Expand Down Expand Up @@ -357,7 +358,7 @@ def get_display_temp(self) -> float: # used
)
)

def get_display_humidity(self) -> (float, None):
def get_display_humidity(self) -> Union[float, None]:
"""
Refresh the cached zone information and return IndoorHumidity.
Expand Down
3 changes: 2 additions & 1 deletion thermostatsupervisor/kumolocal.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import os
import pprint
import time
from typing import Union

# third party imports

Expand Down Expand Up @@ -280,7 +281,7 @@ def get_display_temp(self) -> float: # used
self.refresh_zone_info()
return util.c_to_f(self.device_id.get_current_temperature())

def get_display_humidity(self) -> (float, None):
def get_display_humidity(self) -> Union[float, None]:
"""
Refresh the cached zone information and return IndoorHumidity.
Expand Down
12 changes: 4 additions & 8 deletions thermostatsupervisor/nest.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@


class ThermostatClass(tc.ThermostatCommon):
"""Nest thermostat functions."""
"""Nest Thermostat class."""

def __init__(self, zone, verbose=True):
"""
Expand Down Expand Up @@ -256,11 +256,11 @@ def get_metadata(self, zone=None, trait=None, parameter=None):

try:
meta_data = self.devices[zone_num].traits
except IndexError:
except IndexError as exc:
raise IndexError(
f"zone {zone_num} not found in nest device list, "
f"device list={self.devices}"
)
) from exc
# return all meta data for zone
if parameter is None:
return meta_data
Expand Down Expand Up @@ -288,11 +288,7 @@ def print_all_thermostat_metadata(self, zone):


class ThermostatZone(tc.ThermostatCommonZone):
"""
KumoCloud single zone on local network.
Class needs to be updated for multi-zone support.
"""
"""Nest Thermostat Zone class."""

def __init__(self, Thermostat_obj, verbose=True):
"""
Expand Down
2 changes: 1 addition & 1 deletion thermostatsupervisor/thermostat_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def get_metadata(self, zone=None, trait=None, parameter=None):
(dict): dictionary of meta data.
"""
raise NotImplementedError(
"get_metadata is not implemented for this" "thermostat type"
"get_metadata is not implemented for this thermostat type"
)

def print_all_thermostat_metadata(self, zone): # noqa R0201
Expand Down

0 comments on commit 1dde9e7

Please sign in to comment.