* Refactor Xiaomi vacuum with sensors.
This is the first step into refactoring xiaomi vacuum attributes into sensors.
What is missing are some switches and binary sensors etc.
https://github.com/home-assistant/core/issues/51361
Signed-off-by: Kevin Hellemun <17928966+OGKevin@users.noreply.github.com>
* Use generic sensor for Xiaomi vacuum sensors.
By using HA coordinator, the generic Xiaomi sensor class can be used with these
coordinators to get the status sensors from vacuum. This also means now that
sensors are available as soon as HA starts, which is a nice plus.
Now the only reason to create a subclass of the generic sensors is when custom
value parsing needs to be done.
https://github.com/home-assistant/core/issues/51361
Signed-off-by: Kevin Hellemun <17928966+OGKevin@users.noreply.github.com>
* Working vacuum sensors via 1 coordinator.
Vacuum needs a custom coordinator to ensure that it fetches all the needed data
and puts it in a dict. From this dict the sensors will then get their data
accordingly.
https://github.com/home-assistant/core/issues/51361
Signed-off-by: Kevin Hellemun <17928966+OGKevin@users.noreply.github.com>
* Remove vacuum setup method in sensor
Sensor is generic enough that vacuum does not require its own setup method.
https://github.com/home-assistant/core/issues/51361
Signed-off-by: Kevin Hellemun <17928966+OGKevin@users.noreply.github.com>
* Don't auto register generic sensors.
Let the user decide which sensor is useful for them and enable them.
https://github.com/home-assistant/core/issues/51361
Signed-off-by: Kevin Hellemun <17928966+OGKevin@users.noreply.github.com>
* Remove converted attributes from xiaomi vacuum.
The attributes that have been converted so far should be removed from the vacuum
attributes list.
https://github.com/home-assistant/core/issues/51361
Signed-off-by: Kevin Hellemun <17928966+OGKevin@users.noreply.github.com>
* Fetch data from vacuum sequentially.
It seems some vacuums do not like parallel requests. The requests that came
before are ignored.
https://github.com/home-assistant/core/issues/51361
Signed-off-by: Kevin Hellemun <17928966+OGKevin@users.noreply.github.com>
* Refactor vacuum sensors to its own container.
By moving vacuum sensors to its own container, there is no more key collisions.
This in turns means that there is need for the split hack to ensure key names
are correct.
https://github.com/home-assistant/core/issues/51361
Signed-off-by: Kevin Hellemun <17928966+OGKevin@users.noreply.github.com>
* fixup! fix bad rebase.
Signed-off-by: Kevin Hellemun <17928966+OGKevin@users.noreply.github.com>
* Fix sensor naming and default registration.
Use proper names for sensors, no need to include from which device status it
came.
Registration of the sensor by default has been parameterised. If the param is
not set, the sensor is not registered.
https://github.com/home-assistant/core/issues/51361
Signed-off-by: Kevin Hellemun <17928966+OGKevin@users.noreply.github.com>
* Make vacuum platform also use coordinator for its data.
By using the coordinator for data in vacuum platfrom, removes the cases where
request gets ignored during the case where the requests are done concurrently by
separate platforms.
https://github.com/home-assistant/core/issues/51361
Signed-off-by: Kevin Hellemun <17928966+OGKevin@users.noreply.github.com>
* Add binary sensor for vacuum
Add binary sensor for waterbox, mop, and water shortage.
https://github.com/home-assistant/core/issues/51361
Signed-off-by: Kevin Hellemun <17928966+OGKevin@users.noreply.github.com>
* Added proper icons to sensors.
https://github.com/home-assistant/core/issues/51361
Signed-off-by: Kevin Hellemun <17928966+OGKevin@users.noreply.github.com>
* Refactor sensors to use dataclass.
Signed-off-by: Kevin Hellemun <17928966+OGKevin@users.noreply.github.com>
* Make vacuum use coordinator for its data.
This commit also insures that the binary sensors are only registered for devices
that include a mop.
Signed-off-by: Kevin Hellemun <17928966+OGKevin@users.noreply.github.com>
* Apply suggestions from code review
Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
* Minor refactoring
Signed-off-by: Kevin Hellemun <17928966+OGKevin@users.noreply.github.com>
* Update data from coordinator after running command.
This is is to have a faster status change when executing a command like changing
fan speeds. If a manual refresh is not triggered. Worst case scenario it will
take 10s for the new fan speed to be reported in HA.
Signed-off-by: Kevin Hellemun <17928966+OGKevin@users.noreply.github.com>
* Refresh within coroutine is ok.
Signed-off-by: Kevin Hellemun <17928966+OGKevin@users.noreply.github.com>
* Move logging to _handle_coordinator_update
Signed-off-by: Kevin Hellemun <17928966+OGKevin@users.noreply.github.com>
* Use internal state attribute.
Signed-off-by: Kevin Hellemun <17928966+OGKevin@users.noreply.github.com>
* Fix vacuum typing
* Fix tests constants
* Fix vacuum inconsistent return values
* Fix vacuum state update
* Fix vacuum tests
* Remove impossible cases
* Parametrize custom services test
* Move goto test
* Move clean segment test
* Move clean single segment test
* Test service pause
* Include vacuum in coverage
* Delint
* Fix vacuum sensor dict collision.
This also prevents collision for unique id. As the key is used to construct
unique ids.
* Use f strings as dict keys
Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
* Convert persistent notification tests to async
* Create/dismiss persistent notifications in exposed functions, not service calls
* Fix notify persistent_notification
* Remove setting up persistent_notification
* Drop more setups
* Empty methods
* Undeprecate sync methods because too big task
* Fix setup clearing notifications
* Fix a bunch of tests
* Fix more tests
* Uno mas
* Test persistent notification events
* Clean up stale comment
Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
* xiaomi_miio: only log update exceptions once
Replaces #37695
* add som more missed exception logger cases + do not change the control flow as pointed out by @cgtobi
* Use patch&MagickMock from tests.async_mock
* Fix linting for alarm_control_panel
* update the test to verify that the warning on update is only logged when the device was previously available
* Use backend-provided fan speed presets for Xiaomi vacuums
This needs input from Xiaomi vacuum owners to verify that it does not break anything.
I have personally tested this on rockrobo v1 (old mapping).
Related issues/PRs:
home-assistant/core#32821home-assistant/core#31268home-assistant/core#27268
This is a WIP as it requires a new upstream release.
The PR is https://github.com/rytilahti/python-miio/pull/643
* Bump version requirement for 0.5.0
* Bump requirements_test_all.txt, too
* Fix linting; missing setup.cfg on local checkout caused wrong settings for black..
* Add tests for both fan speed types
* Remove useless else..
* bump python-miio to 0.5.0.1 due to broken 0.5.0 packaging
* move service constants to const.py, move all custom xiaomi_miio services to xiaomi_miio domain
* update service names
* try to fix black error
* try black formatting again
* final black formatting attempt
* update service names to reflect platform
* fix typo