$ show syssi/xiaomi_fan
This repository is a Home Assistant custom component for integrating Xiaomi Smart Pedestal Fans (and several other fan models) into the Home Assistant ecosystem. The code in `fan.py` defines a hierarchy of Python classes, starting from a generic `XiaomiGenericDevice` base and specializing through `XiaomiFan`, `XiaomiFanP5`, `XiaomiFanMiot`, and many model-specific subclasses (e.g., `XiaomiFanZA5`, `XiaomiFanP76`). Each subclass maps the device-specific miIO/MIoT properties to Home Assistant's `FanEntity` interface, providing controls for power, speed percentage, preset modes, oscillation angles, LED brightness, buzzers, child locks, and timer delays. The integration also includes custom service definitions (e.g., `fan_set_oscillation_angle`, `fan_set_buzzer_on`) declared in `services.yaml` and `strings.json`. The architecture cleanly separates device communication logic (MiotDevice subclasses with property mappings) from Home Assistant entity logic (FanEntity subclasses). The code is well-structured, uses type hints, follows Home Assistant best practices, and includes CI workflows (HACS validation, hassfest, mypy, pre-commit, yamllint). It targets Python 3.13 and modern HA versions (2024.8+). There are no data research or analytics elements; it is strictly an application integration.
The LLM identified 1 files worth highlighting for reuse:
The entire `fan.py` (approx. 68000 tokens) demonstrates a clean class hierarchy for multi-device support. The base `XiaomiGenericDevice` class provides a reusable `_try_command` pattern for resilient miIO device calls with retry logic. The `SERVICE_TO_METHOD` dictionary maps service names to async methods and schemas, enabling centralized service registration. Each MiotDevice subclass (e.g., `FanZA5`, `FanP33`) defines a `mapping` that maps MIoT property identifiers to Home Assistant attributes, which is a reusable pattern for any Home Assistant MIoT integration. The code is professional-grade with proper docstrings, type annotations, and error logging.