Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ha_mqtt_models_pydantic-1.0.0.tar.gz (47.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ha_mqtt_models_pydantic-1.0.0-py3-none-any.whl (37.2 kB view details)

Uploaded Python 3

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

Hashes for ha_mqtt_models_pydantic-1.0.0.tar.gz
Algorithm Hash digest
SHA256 c1aad635411a07d6df4a066622194e7567251efa02995874543f62e67eb59e82
MD5 2731083651a6530aa667fb111c630f2d
BLAKE2b-256 0852ddb7a434194e793cb8dcfb8101d8e9a51ac21714cebf629ce30cf5eaebee

See more details on using hashes here.

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

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ha_mqtt_models_pydantic-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for ha_mqtt_models_pydantic-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 963a0b4e4fe3d4cc1268dfccbdf40aa6b492f79f6fd685fe0f8ca920317e91eb
MD5 afda5dd0372f6d7b1df4a3054c8796c6
BLAKE2b-256 4ad317b3af29cd1434b7f67fe181618d55c1caf97e6fd5da2e4e290dc388b28f

See more details on using hashes here.

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

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page