Base components

class nirahmq.components.base.Availability[source]

Bases: BaseModel

A dataclass representing a component that supports availability.

All components that support availability, inherit from this class.

get_availability_topics() list[tuple[str, str, str]][source]

Get all the available availability topics and their AVAILABLE and NOT AVAILABLE payloads.

Returns:

The available availability topics and corresponding payloads

Return type:

list[tuple[str, str, str]]

availability: Annotated[list[AvailabilityItem], Len(min_length=1, max_length=None)]
availability_mode: Literal['all', 'any', 'latest']
availability_template: str
availability_topic: StateTopic
payload_available: str
payload_not_available: str
class nirahmq.components.base.AvailabilityItem[source]

Bases: BaseModel

Dataclass representing an item in the availability list of an Availability class.

payload_available: str
payload_not_available: str
topic: StateTopic
value_template: str
class nirahmq.components.base.BareEntityBase[source]

Bases: Availability, ComponentBase

A component class that represents a bare Home Assistant entity.

set_availability(state: bool) None[source]

Set availability of the entity.

Parameters:

state (bool) – Whether the entity should be available

icon: str
json_attributes_template: str
json_attributes_topic: StateTopic
name: str | None
object_id: str
qos: QoS
unique_id: str
class nirahmq.components.base.CallableComponent[source]

Bases: ComponentBase

A component class that has command topics to receive data from.

All components that receive commands, inherit from this class.

class nirahmq.components.base.ComponentBase[source]

Bases: BaseModel

Base component class.

All the components in nirahmq.components are derived from this class.

publish(topic: str, payload: str | bytes | bytearray | int | float | None, qos: QoS = QoS.MOST, retain: bool = True) None[source]

Publish an arbitrary payload to the specified MQTT topic.

Publish an arbitrary payload to the specified MQTT topic. Optionally, set the Quality of Service (QoS) and retain flag for the message.

Does nothing if the instance is not connected to an MQTT broker or the topic is Unset.

Parameters:
  • topic (str) – The MQTT topic to publish the payload to

  • payload (str | bytes | bytearray | int | float | None) – The payload to publish

  • qos (QoS) – The QoS to use

  • retain (bool) – Retain flag

base_topic: Annotated[str, FieldInfo(annotation=NoneType, required=True, alias_priority=2, serialization_alias='~')]
ha_status_callback: ComponentCallback[ComponentBase]
platform: Annotated[Platform, Required]
class nirahmq.components.base.EntityBase[source]

Bases: BareEntityBase

A component class that represents a Home Assistant entity.

enabled_by_default: bool
encoding: str
entity_category: Category
entity_picture: str
class nirahmq.components.base.StatefulComponent[source]

Bases: ComponentBase

A component class that has state topics to publish to.

All components that report a state, inherit from this class.

nirahmq.components.base.ComponentDefaultCallback = FieldInfo(annotation=Optional[ComponentCallback[nirahmq.components.components.WaterHeater]], required=False, default=<_Unset.TOKEN: None>, exclude=True)

Default component callback value.