Add your description here
Project description
ha-mqtt-models-pydantic
Typed Pydantic v2 models for Home Assistant MQTT discovery payloads.
This library validates Home Assistant MQTT discovery payloads as plain Python data, without depending on Home Assistant itself. It is useful when you want to inspect, validate, transform, or generate discovery payloads before publishing them to MQTT.
What It Includes
- Pydantic models for Home Assistant MQTT discovery components
- Helpers to parse raw discovery payloads into the right model
- Support for Home Assistant discovery abbreviations such as
stat_t,cmd_t, anddev - Dedicated light parsing for
basic,json, andtemplateschemas - Typed shared models for entity metadata, device info, and origin info
Installation
From PyPI:
pip install ha-mqtt-models-pydantic
With uv:
uv add ha-mqtt-models-pydantic
Quick Start
from ha_mqtt_models_pydantic import parse_component_payload
payload = {
"dev_cla": "temperature",
"name": "Living Room Temperature",
"stat_t": "homeassistant/sensor/living_room_temperature/state",
"unit_of_meas": "°C",
"val_tpl": "{{ value_json.temperature }}",
"def_ent_id": "sensor.living_room_temperature",
"dev": {
"ids": ["living_room_sensor_01"],
"name": "Living Room Sensor",
},
}
sensor = parse_component_payload("sensor", payload)
print(sensor.name)
print(sensor.state_topic)
print(sensor.device.identifiers)
parse_component_payload() expands Home Assistant abbreviations before validation, so both abbreviated and expanded payloads are accepted.
Main APIs
Parse a component payload
from ha_mqtt_models_pydantic import parse_component_payload
switch = parse_component_payload(
"switch",
{
"cmd_t": "devices/lamp/set",
"stat_t": "devices/lamp/state",
"pl_on": "ON",
"pl_off": "OFF",
"uniq_id": "lamp_switch_01",
},
)
Parse a light payload
from ha_mqtt_models_pydantic import parse_light_payload
light = parse_light_payload(
{
"schema": "json",
"cmd_t": "devices/light/set",
"stat_t": "devices/light/state",
"name": "Desk Light",
}
)
Parse a device discovery payload
from ha_mqtt_models_pydantic import parse_device_discovery_payload
device_payload = parse_device_discovery_payload(
{
"dev": {"ids": ["device_01"], "name": "Example Device"},
"o": {"name": "example-generator"},
"cmps": {
"temperature": {
"p": "sensor",
"dev_cla": "temperature",
"stat_t": "devices/example/temperature",
"unit_of_meas": "°C",
}
},
}
)
Supported Components
alarm_control_panelbinary_sensorbuttoncameraclimatecoverdevice_automationdevice_trackereventfanhumidifierimagelawn_mowerlightlocknotifynumbersceneselectsensorsirenswitchtagtextupdatevacuumvalvewater_heater
Notes
- The import package is
ha_mqtt_models_pydantic. - The PyPI distribution name is
ha-mqtt-models-pydantic. - The library targets Python
3.11+. - The package is marked as typed with
py.typed.
Development
Install development dependencies:
uv sync --dev
Run checks:
uv run ruff check .
uv run ruff format --check .
uv run mypy .
uv run pytest -q
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ha_mqtt_models_pydantic-1.0.1.tar.gz.
File metadata
- Download URL: ha_mqtt_models_pydantic-1.0.1.tar.gz
- Upload date:
- Size: 48.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3def3aa89f7a53b9222af6b17908508cbfe2b21b35bc28c715b96061f77e87e1
|
|
| MD5 |
890225cc7a3114db8ca2609d7c0092d4
|
|
| BLAKE2b-256 |
6dcec16cc71701849086121e726f7f16656fcacb5a58a666c76719445432bd4b
|
Provenance
The following attestation bundles were made for ha_mqtt_models_pydantic-1.0.1.tar.gz:
Publisher:
publish.yml on PolarBearEs/ha_mqtt_models_pydantic
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ha_mqtt_models_pydantic-1.0.1.tar.gz -
Subject digest:
3def3aa89f7a53b9222af6b17908508cbfe2b21b35bc28c715b96061f77e87e1 - Sigstore transparency entry: 1100374908
- Sigstore integration time:
-
Permalink:
PolarBearEs/ha_mqtt_models_pydantic@ec48244cebf6d13f3e6b80a7d64e11e556313307 -
Branch / Tag:
refs/tags/v1.0.1 - Owner: https://github.com/PolarBearEs
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@ec48244cebf6d13f3e6b80a7d64e11e556313307 -
Trigger Event:
release
-
Statement type:
File details
Details for the file ha_mqtt_models_pydantic-1.0.1-py3-none-any.whl.
File metadata
- Download URL: ha_mqtt_models_pydantic-1.0.1-py3-none-any.whl
- Upload date:
- Size: 37.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
da03b6cead0402e7e427f33293942405a83a6a7be305a63b778b763ccbfa3e27
|
|
| MD5 |
f09c3c7c1f64ae2c57fa3e4f02492edb
|
|
| BLAKE2b-256 |
98e56d9071b41c0c6f997a9ec46394bbd2ac5fa1d4528e097f65c611a3f973e2
|
Provenance
The following attestation bundles were made for ha_mqtt_models_pydantic-1.0.1-py3-none-any.whl:
Publisher:
publish.yml on PolarBearEs/ha_mqtt_models_pydantic
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ha_mqtt_models_pydantic-1.0.1-py3-none-any.whl -
Subject digest:
da03b6cead0402e7e427f33293942405a83a6a7be305a63b778b763ccbfa3e27 - Sigstore transparency entry: 1100374920
- Sigstore integration time:
-
Permalink:
PolarBearEs/ha_mqtt_models_pydantic@ec48244cebf6d13f3e6b80a7d64e11e556313307 -
Branch / Tag:
refs/tags/v1.0.1 - Owner: https://github.com/PolarBearEs
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@ec48244cebf6d13f3e6b80a7d64e11e556313307 -
Trigger Event:
release
-
Statement type: