Service

Service Base class for a HAP Accessory.

class pyhap.service.Service(type_id, display_name=None, unique_id=None)[source]

A representation of a HAP service.

A Service contains multiple characteristics. For example, a TemperatureSensor service has the characteristic CurrentTemperature.

add_characteristic(*chars)[source]

Add the given characteristics as “mandatory” for this Service.

add_linked_service(service)[source]

Add the given service as “linked” to this Service.

configure_char(char_name, properties=None, valid_values=None, value=None, setter_callback=None, getter_callback=None)[source]

Helper method to return fully configured characteristic.

classmethod from_dict(name, json_dict, loader)[source]

Initialize a service object from a dict.

Parameters:json_dict (dict) – Dictionary containing at least the keys UUID and RequiredCharacteristics
get_characteristic(name)[source]

Return a Characteristic object by the given name from this Service.

Parameters:name (str) – The name of the characteristic to search for.

:raise ValueError if characteristic is not found.

Returns:A characteristic with the given name.
Return type:Characteristic
to_HAP()[source]

Create a HAP representation of this Service.

Returns:A HAP representation.
Return type:dict.