Skip to content

Commit

Permalink
Added docstrings for set_state.
Browse files Browse the repository at this point in the history
  • Loading branch information
dboulware committed Sep 8, 2022
1 parent 3eb7d95 commit b78ba31
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/its_preselector/controlbyweb_web_relay.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ def get_sensor_value(self, sensor_num):
return sensor.text

def set_state(self, key):
"""
Set the state of the relay.
:param key: The key for the desired state or states as defined in the config.
:return: None
:raises: requests.Timeout exception
"""
if key in self.config["control_states"]:
switches = self.config["control_states"][str(key)].split(",")
if self.base_url and self.base_url != "":
Expand All @@ -67,7 +73,11 @@ def set_state(self, key):
else:
raise Exception("RF path " + key + " configuration does not exist.")

def healthy(self):
def healthy(self) -> bool:
"""
Check if the relay can be reached.
:return: True if the relay can be reached, or False if it cannot be reached.
"""
try:
response = requests.get(self.base_url, timeout=self.timeout)
return response.status_code == requests.codes.ok
Expand Down
6 changes: 6 additions & 0 deletions src/its_preselector/web_relay_preselector.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ def __init__(self, sensor_definition: dict, config: dict, timeout: int = 1):
self.web_relay = ControlByWebWebRelay(config, timeout)

def set_state(self, state_name: str):
"""
Set the state of the preselector.
:param state_name: The key for the desired state or states as defined in the config.
:return: None
:raises: requests.Timeout exception
"""
self.web_relay.set_state(state_name)

def get_sensor_value(self, sensor_num) -> str:
Expand Down

0 comments on commit b78ba31

Please sign in to comment.