purei9_unofficial icon indicating copy to clipboard operation
purei9_unofficial copied to clipboard

KeyError: 'notConnected' on reading dustbin status

Open erikosvaldsson opened this issue 2 years ago • 8 comments

When using this library through a home-assistant integration (https://github.com/Ekman/home-assistant-pure-i9) I get the following message in the log:

2021-12-25 19:31:25 ERROR (MainThread) [homeassistant.components.vacuum] purei9: Error on device update!
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 431, in _async_add_entity
await entity.async_device_update(warning=False)
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 684, in async_device_update
await task
File "/usr/local/lib/python3.9/concurrent/futures/thread.py", line 52, in run
result = self.fn(*self.args, **self.kwargs)
File "/config/custom_components/purei9/vacuum.py", line 195, in update
purei9_dustbin = self._robot.getdustbinstatus()
File "/usr/local/lib/python3.9/site-packages/purei9_unofficial/cloudv2.py", line 43, in getdustbinstatus
return DustbinStates[dustbinstatus]
File "/usr/local/lib/python3.9/enum.py", line 432, in __getitem__
return cls._member_map_[name]
KeyError: 'notConnected'

The robot works fine from purei9_unofficial commandline with the following status output:

+--------------------------+----------+------+----------+-----------+----------+---------+---------+----------+-----------+
|            id            |  model   | name | localpw  | connected |  status  | dustbin | battery | firmware | powermode |
+--------------------------+----------+------+----------+-----------+----------+---------+---------+----------+-----------+
| XXXXXXXXXXXXXXXXXXXXXXXX | PUREi9.2 | PI92 | XXXXXXXX |   True    | Sleeping |  unset  |  High   |  42.19   |  MEDIUM   |
+--------------------------+----------+------+----------+-----------+----------+---------+---------+----------+-----------+

The dustbin is installed and the robot works fine through the app,

It seems there are issues interpreting the dustbin status in the getdustbinstatus function?

erikosvaldsson avatar Dec 26 '21 09:12 erikosvaldsson

For whatever reason the integration started working after about a week with no changes on my part. I assume something changed in the backend!

erikosvaldsson avatar Jan 08 '22 14:01 erikosvaldsson

For whatever reason the integration started working after about a week with no changes on my part. I assume something changed in the backend!

I think this is just because you've removed the dustbin and now that its back in the robot it is fine. It seems like the Purei9 v2 uses another state when communication the dustbin state, because in your case the state was notConnected, but with my robot it is empty when you remove the dustbin. So i guess i need to implement another state translation map.

Phype avatar Jan 16 '22 13:01 Phype

I think this is just because you've removed the dustbin and now that its back in the robot it is fine.

Unforturnately I'm not sure its that simple. During the week that it did not work I tried removing and putting the dustbin back as well as rebooting the vacuum. It was correctly reported in the app, but no success with the library.

I just did another check and the dustbin status is correct and immediate in the app. However the "status" call currently returns "unset" constantly.

erikosvaldsson avatar Jan 16 '22 19:01 erikosvaldsson

The robot works fine from purei9_unofficial commandline with the following status output

I think you started purei9_unofficial with the old cloud API (this happens by default currently), otherwise there would be no localpw shown. Could you maybe try it with the -d and -v 2 flag when starting the library client manually? Like this:

python3 -m purei9_unofficial -d cloud -v 2 -c 'user:password' status

Phype avatar Jan 17 '22 17:01 Phype

Correct, with the additional options the status is reported as "connected" and "empty" respectively! Sorry for the confusion :)

erikosvaldsson avatar Jan 17 '22 18:01 erikosvaldsson

Hmm ok, so i guess it really works. Still weird that the API seems to have returned notConnected instead of empty at some point.

Phype avatar Jan 20 '22 10:01 Phype

I also been having this problem for a few days. The module should at least fail gracefully.

techillin avatar Apr 08 '22 11:04 techillin

I've created a new release 0.0.10 which attempts to work around this issue, though i cannot test it because the issue does not happen for me.

Phype avatar Apr 21 '22 09:04 Phype