Add your description here
Project description
Home Assistant MQTT Pydantic Models
Pydantic models for Home Assistant MQTT discovery payloads. This project provides a set of robust, type-safe models to validate and work with MQTT discovery data in Home Assistant.
Features
- Pydantic V2: Leveraging the latest Pydantic features for high-performance validation.
- Type Safety: Full type hinting for MQTT discovery payloads.
- Centralized Constants: All MQTT configuration keys and default values are centralized in
ha_mqtt_models_pydantic/const.py, mirroring Home Assistant core conventions. - Abbreviation Expansion: Helper tools to expand abbreviated MQTT discovery keys.
- Comprehensive Coverage: Supporting a wide range of Home Assistant entities (Sensor, Climate, Light, Lock, Vacuum, etc.).
Installation
uv pip install .
Usage
Validating a Discovery Payload
from ha_mqtt_models_pydantic.discovery import parse_component_payload
# Example MQTT discovery payload (abbreviated)
payload = {
"dev_cla": "temperature",
"name": "Temperature",
"stat_t": "homeassistant/sensor/temp/state",
"unit_of_meas": "°C",
"val_tpl": "{{ value_json.temperature }}",
"def_ent_id": "sensor.temperature",
"dev": {
"ids": ["temp_sensor_01"],
"name": "Living Room Sensor"
}
}
# Expand abbreviations and validate with the correct component model
sensor = parse_component_payload("sensor", payload)
print(sensor.name)
# Output: Temperature
Using Constants
from ha_mqtt_models_pydantic.const import CONF_STATE_TOPIC, DEFAULT_PAYLOAD_AVAILABLE
print(f"Discovery key for state topic: {CONF_STATE_TOPIC}")
print(f"Default online payload: {DEFAULT_PAYLOAD_AVAILABLE}")
Supported Components
- Alarm Control Panel
- Binary Sensor
- Button
- Camera
- Climate
- Cover
- Device Tracker
- Event
- Fan
- Humidifier
- Image
- Lawn Mower
- Light
- Lock
- Notify
- Number
- Scene
- Select
- Sensor
- Siren
- Switch
- Tag
- Text
- Update
- Vacuum
- Valve
- Water Heater
Development
Prerequisites
- Python 3.11+
- uv
Running Verification
You can verify the models against the vendored Home Assistant snapshot with:
./.venv/bin/python -m pytest
Code Quality
The project uses ruff for linting and formatting. Line length is configured to 120 characters.
ruff check .
ruff format .
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.0.tar.gz.
File metadata
- Download URL: ha_mqtt_models_pydantic-1.0.0.tar.gz
- Upload date:
- Size: 47.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c1aad635411a07d6df4a066622194e7567251efa02995874543f62e67eb59e82
|
|
| MD5 |
2731083651a6530aa667fb111c630f2d
|
|
| BLAKE2b-256 |
0852ddb7a434194e793cb8dcfb8101d8e9a51ac21714cebf629ce30cf5eaebee
|
Provenance
The following attestation bundles were made for ha_mqtt_models_pydantic-1.0.0.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.0.tar.gz -
Subject digest:
c1aad635411a07d6df4a066622194e7567251efa02995874543f62e67eb59e82 - Sigstore transparency entry: 1097277169
- Sigstore integration time:
-
Permalink:
PolarBearEs/ha_mqtt_models_pydantic@32e3df8721407f39bf9e4d0c4f8c205ed4ba2565 -
Branch / Tag:
refs/tags/v1.0.0 - Owner: https://github.com/PolarBearEs
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@32e3df8721407f39bf9e4d0c4f8c205ed4ba2565 -
Trigger Event:
release
-
Statement type:
File details
Details for the file ha_mqtt_models_pydantic-1.0.0-py3-none-any.whl.
File metadata
- Download URL: ha_mqtt_models_pydantic-1.0.0-py3-none-any.whl
- Upload date:
- Size: 37.2 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 |
963a0b4e4fe3d4cc1268dfccbdf40aa6b492f79f6fd685fe0f8ca920317e91eb
|
|
| MD5 |
afda5dd0372f6d7b1df4a3054c8796c6
|
|
| BLAKE2b-256 |
4ad317b3af29cd1434b7f67fe181618d55c1caf97e6fd5da2e4e290dc388b28f
|
Provenance
The following attestation bundles were made for ha_mqtt_models_pydantic-1.0.0-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.0-py3-none-any.whl -
Subject digest:
963a0b4e4fe3d4cc1268dfccbdf40aa6b492f79f6fd685fe0f8ca920317e91eb - Sigstore transparency entry: 1097277176
- Sigstore integration time:
-
Permalink:
PolarBearEs/ha_mqtt_models_pydantic@32e3df8721407f39bf9e4d0c4f8c205ed4ba2565 -
Branch / Tag:
refs/tags/v1.0.0 - Owner: https://github.com/PolarBearEs
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@32e3df8721407f39bf9e4d0c4f8c205ed4ba2565 -
Trigger Event:
release
-
Statement type: