-
-
Notifications
You must be signed in to change notification settings - Fork 563
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement introspectable sensors #1488
Conversation
I think this is awesom and will reduce the maintenance work in HomeAssistant. However inside python-miio, how is this going to work for diffrent models of lets say a vacuum. |
I'm not sure I understand what you mean, but I'll try to explain how I'm thinking about it. Here's how the sensors are initialized in the homeassistant integration (from
and it looks like this in the log for the power strip:
For vacuums on homeassistant's end, I'm planning to convert the existing custom implementation inside homeassistant to use the generic data update coordinator that is already used for many devices. This will require modification to the vacuumstatus container to expose some information (like consumables) somehow sanely so it's still a WIP. In the end, this will simplify adding support for non-roborock vacuums that may expose different types of sensors and settings. I have now homeassistant implementation for As some of the things (like fanspeed preset) is already something the
See my answer above, I hope there should be need for that but I only have two devices to test and develop on. I want to start this from simple to build upon and fix issues as they come, that's why the details will likely change when we get some more testing done :-) It is likely that there's might need for some sort of feature flags for some cases, but I'm trying to have a base implementation working before tackling that issue. edit: to add a bit more, the @sensor decorator is just a shortcut to define |
@rytilahti sounds very good, nice implementation. So all roborock vacuum models will have the same "VacuumStatus" class containing all posible status properties/sensors. The once that are not supported by a specific model will just be None and won't be added to HomeAssistant. |
Looks grate 👍 |
This fixes "Decorated property not supported" errors for the time being without hopefully many downsides. The impact is hard to measure as the list of misc errors is not to be found. This should be revisited if/when python/mypy#1362 gets solved.
bc784a9
to
5c684a9
Compare
Codecov Report
@@ Coverage Diff @@
## master #1488 +/- ##
==========================================
+ Coverage 82.50% 82.59% +0.09%
==========================================
Files 140 142 +2
Lines 13908 14009 +101
Branches 3305 3341 +36
==========================================
+ Hits 11475 11571 +96
- Misses 2214 2219 +5
Partials 219 219
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
@starkillerOG oh, forgot push comment to answer you previously, but you got it right! If you want to experiment how it works like with your devices, I pushed my local working copy of the homeassistant modifications in my repo: https://github.com/rytilahti/home-assistant/tree/xiaomi_miio/feat/entities_from_upstream - note that parts are rather hacked together and may require some changes to make it work on other devices. Let me know if you give it a try! |
@rytilahti thanks a lot, this certainly looks like a greath improvement and a good way to go for python-miio! |
This is the first PR to add support for introspectable integration interfaces to allow downstream users to query the device in order to obtain information about available sensors (e.g., "Voltage"), settings ("Wifi LED"), and actions (e.g., "Reset brush filter").
This will reduce the need to hard-code any details (e.g., inside homeassistant) about what exactly is supported by a device object.
The way this works is to have descriptor classes that define the information necessary to present the information to end users.
This PR adds all currently existing descriptors, but only the implementation for sensors. The rest of the types will follow soon in follow-up pull requests.
Integration developers can modify their
DeviceStatus
implementations to add@sensor
decorators to expose properties that can be interesting for end-users:The sensor descriptor objects will be available using
DeviceStatus.sensors()
and will contain the supplied information.The decorator inspects the return type of the property to deliver information whether a sensor is a binary sensor or just a regular one, here's an example how it looks like in homeassistant:
The API is currently provisional and will likely change in the near future, I'm currently looking for feedback from other developers using the library as well as those developing integrations. Ping @Kirmas @starkillerOG @syssi
TBD:
# type: ignore
for all properties gets tiresome pretty fast.