fusion_hat._utils module

fusion_hat._utils.retry(times: int = 5)[source]

Retry decorator retry specified times if any error occurs

Parameters:

times (int, optional) – number of times to retry. Defaults to 5.

Returns:

wrapper function

Return type:

function

fusion_hat._utils.command_exists(cmd: str) bool[source]

Check if command exists

Parameters:

cmd (str) – command to check

Returns:

True if exists

Return type:

bool

fusion_hat._utils.run_command(cmd: str, timeout: float | None = None) tuple[source]

Run command and return status and output

Parameters:
  • cmd (str) – command to run

  • timeout (float | None) – timeout in seconds, None for no timeout

Returns:

status, output. On timeout, returns (124, “timed out after Ns”)

Return type:

tuple

fusion_hat._utils.is_installed(cmd: str) bool[source]

Check if command is installed

Parameters:

cmd (str) – command to check

Returns:

True if installed

Return type:

bool

fusion_hat._utils.mapping(x: float, in_min: float, in_max: float, out_min: float, out_max: float) float[source]

Map value from one range to another range

Parameters:
  • x (float) – value to map

  • in_min (float) – input minimum

  • in_max (float) – input maximum

  • out_min (float) – output minimum

  • out_max (float) – output maximum

Returns:

mapped value

Return type:

float

fusion_hat._utils.get_ip(ifaces: list = ['wlan0', 'eth0']) str[source]

Get IP address

Parameters:

ifaces (list, optional) – interfaces to check, defaults to [‘wlan0’, ‘eth0’]

Returns:

IP address or False if not found

Return type:

str/False

fusion_hat._utils.get_username() str[source]

Get username

Returns:

username

Return type:

str

fusion_hat._utils.constrain(value: float, min_value: float, max_value: float) float[source]

Constrain value to a range

Parameters:
  • value (float) – value to constrain

  • min_value (float) – minimum value

  • max_value (float) – maximum value

Returns:

constrained value

Return type:

float