Add YAML metadata support for genericmiot#2062
Conversation
|
These changes were generated using Claude Code under my supervision. I reviewed and approved all code before submitting. I'm not very familiar with this codebase, so apologies in advance for any mistakes. |
Adds a metadata system that enriches MIoT descriptors with human-readable descriptions, icons, and device_class attributes from YAML files, replacing the often-Chinese or generic defaults from miotspec. Includes metadata for miot-spec-v2 and dreame-spec namespaces. Based on the approach from rytilahti#1618, adapted to the current codebase where descriptor creation lives in the models. Also adds MiotBaseModel.full_name and fixes a pre-existing ruff E721 lint error in MiotProperty.pretty_value.
358c5b4 to
1ec4957
Compare
…ad, rename extras.yaml to base.yaml
_enrich_with_metadata now returns a new descriptor via attr.evolve with name set to the metadata description. The original descriptor is stored in extras['original'] so callers can access the raw device-given name.
Move the type/name lookup into ServiceMeta.get() where it belongs, reducing nesting in _lookup_in_namespace to a single walrus expression.
…full_name Empty dict defaults eliminate all None guards in _lookup_in_namespace and ServiceMeta.get(). Also removes MiotBaseModel.full_name which was added on this branch but never used.
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #2062 +/- ##
==========================================
+ Coverage 84.13% 84.27% +0.14%
==========================================
Files 199 201 +2
Lines 20164 20386 +222
Branches 1063 1073 +10
==========================================
+ Hits 16964 17181 +217
- Misses 3010 3014 +4
- Partials 190 191 +1 ☔ View full report in Codecov by Harness. |
rytilahti
left a comment
There was a problem hiding this comment.
Thanks a lot for this PR, @Acrobot! Now that I have a real device to test against, I did some rewiring based on how I felt it should behave.
I did quite a few cleanups to keep it simple (and not bound to homeassistant specifics like device_classes and icons), but this might be extended later. I am planning to do some more improvements to stress test the design & to add proper support for my airmonitor (urn:miot-spec-v2:device:air-monitor:0000A008:cgllc-cgd1st:1), but I will save the improvements into separate PRs.
Implements the metadata approach from #1618, adapted to the current codebase where descriptor creation has moved into the miot models.
Adds a YAML-based metadata system that enriches genericmiot descriptors with human-readable descriptions, replacing the vendor-provided, often-Chinese defaults from miotspec files:
common__ANY__wildcard service incommonprovides cross-service property descriptions (temperature, humidity, CO2, PM2.5/PM10, voltage, etc.) without per-service repetitionextras['original']for callers that need the raw device-given nameDesign
meta.py:Metadataclass loads YAML namespace files and looks up metadata by URN namespace, service, type, and entity namemetadata/base.yaml: index mapping namespace names to YAML filesmetadata/miotspec.yaml: definitions formiot-spec-v2(battery, vacuum, filter, brush, light, identify services)metadata/dreamespec.yaml: definitions fordreame-spec(vacuum-extend, DnD, audio, clean-logs, time services); falls back tomiot-spec-v2metadata/common.yaml: cross-namespace definitions under a__ANY__wildcard service (MAC address, voltage, temperature, humidity, CO2, PM2.5/PM10, brightness, cleaning stats); implicit fallback for all namespaces including unknown onesgenericmiot.py:_enrich_with_metadata()returns a new descriptor viaattr.evolvewith the metadata name; the original descriptor is preserved inextras['original']for callers that need the raw device-given nameNamespace fallback chain
Namespaces declare their fallback with a
fallback:key.commonis the implicit fallback for all namespaces. Within each namespace, the__ANY__wildcard service matches properties regardless of which service they belong to.Model-specific namespaces (keyed by
urn.model) are a natural future extension: add a model YAML file with afallback:pointing to the relevant namespace.