Welcome to hut2’s documentation!

Contents:

hut2.protocol module

class hut2.protocol.HUT2(user=b'admin', password=b'anel')[source]

ANEL HUT2 Driver

Power relay switch with 8 channels, and 8 channels general purpose IO.

  • Relay and IO indices start with 1.

  • Commands tend to keep the device busy for a while.

    Pace them, read back the status after a while and retry them.

  • Some commands sometimes return a status update. Since they are UDP,

    neither commands nor replies are guaranteed to arrive.

Parameters
  • user – Device user name (bytes)

  • password – Device password (bytes)

classmethod connect(host, port=7500, local_addr=('255.255.255.255', 7700), loop=None, **kwargs)[source]

Connect to a Anel HUT2 via UDP

Parameters
  • host – IO or host name of the device

  • port – UDP port on the device. Default is 7500 (unprivileged) as opposed to 75 (privileged). Ensure this is set correctly in the web interface.

  • local_addr – Tuple of local address (or hostname) and UDP port. Default is (“255.255.255.255”, 7500) (broadcast, unprivileged). The device default is to reply to port 75 (privileged). Ensure this is set correctly in the web interface.

Returns

HUT2 instance connected to the device

connection_lost(exc)[source]

Called when the connection is lost or closed.

The argument is an exception object or None (the latter meaning a regular EOF is received or the connection was aborted or closed).

connection_made(transport)[source]

Called when a connection is made.

The argument is the transport representing the pipe connection. To receive data, wait for data_received() calls. When the connection is closed, connection_lost() is called.

datagram_received(data, addr)[source]

Called when some datagram is received.

do(cmd)[source]

Execute a command.

Parameters

(bytes) (cmd) – Command

get_io_states()[source]

Return current IO states as a list.

Returns

List of eight integers

get_port_states()[source]

Return current relay states as a list.

Returns

List of eight integers

get_status()[source]

Get a status update.

This is a coroutine that performs the status query and returns the result.

Returns

Status with the parsed fields

get_temp()[source]

Return current temperature.

Returns

Temperature in C

io(ios)[source]

Set all IO lines.

Parameters

(int) (ios) – Bitmask of the IO state

io_off(io)[source]

Turn an IO off

Parameters

(int) (switch) – IO line index

io_on(io)[source]

Turn an IO on.

Parameters

(int) (io) – IO line index

query()[source]

Query device status and settings.

st_off(switch, delay)[source]

Turn a relay off after a delay

Parameters
  • (int) (delay) – Relay index

  • (int) – Delay in seconds

sw(switches)[source]

Set all relays.

Parameters

switches – Bitmask of the relay settings

sw_off(switch)[source]

Turn a relay off

Parameters

(int) (switch) – Relay index

sw_on(switch)[source]

Turn a relay on

Parameters

(int) (switch) – Relay index

wait()[source]

Return a new status message.

This returns a future.

Returns

Status with the parsed fields

class hut2.protocol.Status[source]

HUT2 Status message parser and representation

classmethod from_bytes(data, time=None)[source]

Parse status message and return a namedtuple of the fields

Indices and tables