1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-20 06:28:09 +00:00
trezor-firmware/ci/hardware_tests/device/t1.py
Martin Milata 41bf9201b5 ci: do not rely on TREZOR_PATH, use switch ports instead
As the connected Trezors can be left in various weird states, trezorctl
list may not always return what is expected or even fail. If it failed
TREZOR_PATH was set to empty string which means random device got
selected.

For now let's avoid using incorrect device by powering down the other
usb port.

Fix log lines ordering.
2021-02-05 12:58:21 +01:00

56 lines
1.6 KiB
Python

import serial
from .device import Device
class TrezorOne(Device):
def __init__(self, uhub_location, arduino_serial, device_port):
super().__init__(uhub_location, device_port)
self.serial = serial.Serial(arduino_serial, 9600)
def touch(self, location, action):
self.now()
self.log(
"[hardware/trezor] Touching the {} button by {}...".format(location, action)
)
self.serial.write(("{} {}\n".format(location, action)).encode())
def update_firmware(self, file=None):
if file:
unofficial = True
trezorctlcmd = "firmware-update -s -f {} &".format(file)
self.log("[software] Updating the firmware to {}".format(file))
else:
unofficial = False
trezorctlcmd = "firmware-update &"
self.log("[software] Updating the firmware to latest")
self.wait(3)
self._enter_bootloader()
self.run_trezorctl("list")
self.wait(3)
self.run_trezorctl(trezorctlcmd)
self.wait(3)
self.touch("right", "click")
self.wait(25)
if unofficial:
self.touch("right", "click")
self.wait(10)
self.power_off()
self.power_on()
if unofficial:
self.touch("right", "click")
self.wait(5)
self.touch("right", "click")
self.wait(5)
return self.check_model("Trezor 1")
def _enter_bootloader(self):
self.power_off()
self.touch("all", "press")
self.wait(2)
self.power_on()
self.wait(2)
self.touch("all", "unpress")