Metadata-Version: 2.3
Name: mqtt-entity
Version: 1.0.16
Summary: MQTT client supporting Home Assistant MQTT entity auto-discovery
Keywords: home-assistant,mqtt,library,discovery,asyncio
Author: Johann Kellerman
Author-email: Johann Kellerman <johann.kellerman@nokia.com>
License: MIT License
         
         Copyright (c) 2021-2025 Johann Kellerman
         
         Permission is hereby granted, free of charge, to any person obtaining a copy
         of this software and associated documentation files (the "Software"), to deal
         in the Software without restriction, including without limitation the rights
         to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
         copies of the Software, and to permit persons to whom the Software is
         furnished to do so, subject to the following conditions:
         
         The above copyright notice and this permission notice shall be included in all
         copies or substantial portions of the Software.
         
         THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
         IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
         FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
         AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
         LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
         OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
         SOFTWARE.
Requires-Dist: attrs>=25,<26
Requires-Dist: paho-mqtt>=2.1.0,<3
Requires-Dist: aiohttp>3.12,<4
Requires-Dist: cattrs>=25,<26 ; extra == 'options'
Requires-Dist: colorlog ; extra == 'options'
Requires-Dist: pyyaml>=6,<7 ; extra == 'options'
Requires-Python: >=3.12
Provides-Extra: options
Description-Content-Type: text/markdown

# MQTT Entity helper library for Home Assistant

[![Workflow Status](https://github.com/kellerza/mqtt_entity/actions/workflows/main.yml/badge.svg?branch=master)](https://github.com/kellerza/mqtt_entity/actions)
[![codecov](https://codecov.io/gh/kellerza/mqtt_entity/branch/main/graph/badge.svg?token=PG4N1YBUGW)](https://codecov.io/gh/kellerza/mqtt_entity)

A Python helper library to manage Home Assistant entities over MQTT.

Updated for device based MQTT discovery.

Features:

- MQTT client based on paho-mqtt
  - Retrieve MQTT service info from the Home Assistant Supervisor
- Manage MQTT discovery info (adding/removing entities)
- MQTTDevice class to manage devices
  - Availability management
  - Manage entities per device
- Home Assistant Entities modelled as attrs classes:
  - Read-only: Sensor, BinarySensor
  - Read & write: Select, Switch, Number, Text, Light
  - MQTT device events
- Asyncio based
- Helpers for Home Assistant add-ons (optional)
  - Add-on configuration modeled as attrs classes
    - Load from environment variables, HA's options.yaml or options.json
    - Load MQTT connection settings from the Supervisor
  - Enable add-on logging (incl colors & debug by config)

## Why?

This MQTT code was included in several of my home Assistant addons (SMA-EM / Sunsynk). It is easier to update a single library & add new features, like discovery removal.

Alternatives options (not based on asyncio)

- <https://pypi.org/project/ha-mqtt-discoverable/>
- <https://pypi.org/project/homeassistant-mqtt-binding/>

## Credits

@Ivan-L contributed some of the writable entities to the Sunsynk addon project

## Release

Semantic versioning is used for release.

To create a new release, include a commit with a :dolphin: emoji as a prefix in the commit message. This will trigger a release on the master branch.

```bash
# Patch
git commit -m ":dolphin: Release 0.0.x"

# Minor
git commit -m ":rocket: Release 0.x.0"
```

### Development

To run the tests, you need to have Python 3.12+ installed.

The `--mqtt` connects to a live Home Assistant instance using the MQTT broker.

```bash
uv run pytest --mqtt
```
