Util

Utilities Module

pyhap.util.base64_to_bytes(str_input) → bytes[source]
pyhap.util.byte_bool(boolv)[source]
pyhap.util.callback(func)[source]

Decorator for non blocking functions.

pyhap.util.event_wait(event, timeout)[source]

Wait for the given event to be set or for the timeout to expire.

Parameters:
  • event (asyncio.Event) – The event to wait for.
  • timeout (float) – The timeout for which to wait, in seconds.
Returns:

event.is_set()

Return type:

bool

pyhap.util.from_hap_json(json_str)[source]

Convert json to an object.

pyhap.util.generate_mac()[source]

Generates a fake mac address used in broadcast.

Returns:MAC address in format XX:XX:XX:XX:XX:XX
Return type:str
pyhap.util.generate_pincode()[source]

Generates a random pincode.

Returns:pincode in format xxx-xx-xxx
Return type:bytearray
pyhap.util.generate_setup_id()[source]

Generates a random Setup ID for an Accessory or Bridge.

Used in QR codes and the setup hash.

Returns:4 digit alphanumeric code.
Return type:str
pyhap.util.get_local_address() → str[source]

Grabs the local IP address using a socket.

Returns:Local IP Address in IPv4 format.
Return type:str
pyhap.util.hap_type_to_uuid[source]

Convert a HAP type to a UUID.

pyhap.util.is_callback(func)[source]

Check if function is callback.

pyhap.util.iscoro(func)[source]

Check if the function is a coroutine or if the function is a functools.partial, check the wrapped function for the same.

pyhap.util.long_to_bytes(n)[source]

Convert a long int to bytes

Parameters:n (int) – Long Integer
Returns:long int in bytes format.
Return type:bytes
pyhap.util.to_base64_str(bytes_input) → str[source]
pyhap.util.to_hap_json(dump_obj)[source]

Convert an object to HAP json.

pyhap.util.to_sorted_hap_json(dump_obj)[source]

Convert an object to sorted HAP json.

pyhap.util.uuid_to_hap_type[source]

Convert a UUID to a HAP type.