pytec: Add hardware testing script #148

Merged
sb10q merged 1 commits from atse/thermostat:test_script into master 2024-11-18 10:38:50 +08:00
1 changed files with 81 additions and 0 deletions
Showing only changes of commit adc25c9b2a - Show all commits

81
pytec/test.py Normal file
View File

@ -0,0 +1,81 @@
import argparse
from contextlib import contextmanager
from pytec.client import Client
CHANNELS = 2
def get_argparser():
parser = argparse.ArgumentParser(description="Thermostat hardware testing script")
parser.add_argument("host", metavar="HOST", default="192.168.1.26", nargs="?")
parser.add_argument("port", metavar="PORT", default=23, nargs="?")
atse marked this conversation as resolved Outdated
Outdated
Review

Capitalizations of metavar and argument name are the opposite of what they should be.

Capitalizations of metavar and argument name are the opposite of what they should be.
Outdated
Review

Fixed in force-push to adc25c9b2a.

Fixed in force-push to adc25c9b2a.
parser.add_argument(
"-r",
"--testing_resistance",
default=10_000,
help="Testing resistance value through SENS pin in Ohms",
)
parser.add_argument(
"-d",
"--deviation",
default=1,
help="Allowed deviation of resistance in percentage",
atse marked this conversation as resolved Outdated

Change this to tolerance in % and calculate the deviation in main

Change this to tolerance in % and calculate the deviation in `main`
Outdated
Review

Done in force-push to bc02819fca.

Done in force-push to bc02819fca.
)
return parser
def main():
args = get_argparser().parse_args()
min_allowed_resistance = args.testing_resistance * (1 - args.deviation / 100)
max_allowed_resistance = args.testing_resistance * (1 + args.deviation / 100)
print(min_allowed_resistance, max_allowed_resistance)
thermostat = Client(args.host, args.port)
for channel in range(CHANNELS):
print(f"Channel {channel} is active")
print("Checking resistance through SENS input ....", end=" ")
sens_resistance = thermostat.get_report()[channel]["sens"]
if sens_resistance is not None:
atse marked this conversation as resolved Outdated

<= since it's allowed_resistance or rename the variable

`<=` since it's `allowed_resistance` or rename the variable
Outdated
Review

Done in force-push to bc02819fca.

Done in force-push to bc02819fca.
print(sens_resistance, "Ω")
if min_allowed_resistance <= sens_resistance <= max_allowed_resistance:
print("PASSED")
else:
print("FAILED")
atse marked this conversation as resolved Outdated

remove the bracket (s) like above

remove the bracket `(s)` like above
Outdated
Review

Removed the "pins" nomenclature entirely and replaced it with "input" in the force-push to bc02819fca.

Removed the "pins" nomenclature entirely and replaced it with "input" in the force-push to bc02819fca.
else:
print("Floating SENS input! Is the channel connected?")
with preserve_thermostat_output_settings(thermostat, channel):
test_output_settings = {
"max_i_pos": 2,
"max_i_neg": 2,
"max_v": 4,
"i_set": 0.1,
"polarity": "normal",
}
for field, value in test_output_settings.items():
thermostat.set_param("output", channel, field, value)
input(f"Check if channel {channel} current = 0.1 A, and press ENTER...")
input(f"Channel {channel} testing done, press ENTER to continue.")
print()
print("Testing complete.")
@contextmanager
def preserve_thermostat_output_settings(client, channel):
original_output_settings = client.get_output()[channel]
yield original_output_settings
for setting in "max_i_pos", "max_i_neg", "max_v", "i_set", "polarity":
client.set_param("output", channel, setting, original_output_settings[setting])
if __name__ == "__main__":
main()