Device¶
- class nirahmq.device.Device[source]¶
Bases:
objectA wrapper class for a Home Assistant device.
The class stores an instance of an
nirahmq.mqtt.MQTTClientandDiscoveryInfo. At initialization, they are configured, command topics are subscribed to and callbacks are registered. At runtime, availability and dynamic component addition and removal are managed automatically.Tip
The class can be used as a dictionary proxy to the provided
DiscoveryInfo.componentsattribute.- __init__(mqtt_client: MQTTClient, discovery_info: DiscoveryInfo, node_id: str | None = None, discovery_prefix: str = 'homeassistant', state_prefix: str = 'nirahmq', use_status: bool = False, remove_on_exit: bool = False, status_callback: ComponentCallback[Device] | None = None) None[source]¶
Initialize the Home Assistant device wrapper.
- Parameters:
mqtt_client (MQTTClient) – The MQTT client instance to use
discovery_info (DiscoveryInfo) – The Home Assistant device discovery information
node_id (str | None) – The node_id to use in MQTT topics
discovery_prefix (str) – The MQTT topic prefix Home Assistant uses for discovery
state_prefix (str) – The MQTT topic prefix to use for state and command topics
use_status (bool) – Use availability
remove_on_exit (bool) – Remove device on disconnect
status_callback (ComponentCallback['Device'] | None) – The callback to call when Home Assistant publishes and availability message
Tip
Set the
node_idwhen using multiple devices to group them together for better organization.
- component_register(name: str, component: ComponentBase, announce: bool = True) None[source]¶
Register a new component with Home Assistant.
- Parameters:
name (str) – The internal name of the component to use
component (ComponentBase) – The component to register
announce (bool) – Whether to announce the registration
- Raises:
ValueError – If the component with the specified name is already registered
- class nirahmq.device.DeviceInfo[source]¶
Bases:
BaseModelDataclass that stores information about a Home Assistant device.
- class nirahmq.device.DiscoveryInfo[source]¶
Bases:
AvailabilityDataclass that stores the discovery info used for Home Assistant device discovery.
- command_topic: CommandTopic¶
- components: dict[str, Annotated[ComponentBase, SerializeAsAny()]]¶
- device: DeviceInfo¶
- origin: OriginInfo¶
- state_topic: StateTopic¶