homeassistant-mi-water-purifier icon indicating copy to clipboard operation
homeassistant-mi-water-purifier copied to clipboard

NameError: name 'DeviceException' is not defined

Open RavenKong opened this issue 5 years ago • 6 comments

I'm using hass.io version 0.82.1 My device model is Xiaomi water purifier 1A. It seems the setup of the platform failed due to a "name error" which could possibly be caused by mismatching versions of the python dependencies. Below is the error logs:

`018-11-25 00:18:42 ERROR (SyncWorker_7) [miio.protocol] unable to parse json '{"result":[net],"id":1}': Expecting value: line 1 column 12 (char 11) 2018-11-25 00:18:42 ERROR (MainThread) [homeassistant.components.sensor] Error while setting up platform mi_water_purifier Traceback (most recent call last): File "/config/custom_components/sensor/mi_water_purifier.py", line 159, in parse_data status = self._device.send('get_prop', []) File "/usr/local/lib/python3.6/site-packages/miio/device.py", line 263, in send self.__id = m.data.value["id"] TypeError: 'NoneType' object is not subscriptable

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/usr/local/lib/python3.6/site-packages/homeassistant/helpers/entity_platform.py", line 128, in _async_setup_platform SLOW_SETUP_MAX_WAIT, loop=hass.loop) File "/usr/local/lib/python3.6/asyncio/tasks.py", line 358, in wait_for return fut.result() File "/usr/local/lib/python3.6/concurrent/futures/thread.py", line 56, in run result = self.fn(*self.args, **self.kwargs) File "/config/custom_components/sensor/mi_water_purifier.py", line 34, in setup_platform waterPurifier = XiaomiWaterPurifier(device, name) File "/config/custom_components/sensor/mi_water_purifier.py", line 116, in init self.parse_data() File "/config/custom_components/sensor/mi_water_purifier.py", line 177, in parse_data except DeviceException: NameError: name 'DeviceException' is not defined`

RavenKong avatar Nov 29 '18 07:11 RavenKong

Sorry to raise this issue with the duplicated title. The previous one does not provide logs.

RavenKong avatar Nov 29 '18 07:11 RavenKong

Also wonder if components support 1A as well? If not, any possible to update it? Or if you need any data to support it.

Thank you. BTW it has been work great with my gen 1. Thanks for the great work.

bluefoxlee avatar Dec 02 '18 14:12 bluefoxlee

1A error 1A

Sun Dec 02 2018 16:10:20 GMT+0800 (CST)

Error while setting up platform mi_water_purifier Traceback (most recent call last): File "/config/custom_components/sensor/mi_water_purifier.py", line 159, in parse_data status = self._device.send('get_prop', []) File "/usr/local/lib/python3.6/site-packages/miio/device.py", line 263, in send self.__id = m.data.value["id"] TypeError: 'NoneType' object is not subscriptable

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/usr/src/app/homeassistant/helpers/entity_platform.py", line 128, in _async_setup_platform SLOW_SETUP_MAX_WAIT, loop=hass.loop) File "/usr/local/lib/python3.6/asyncio/tasks.py", line 358, in wait_for return fut.result() File "/usr/local/lib/python3.6/concurrent/futures/thread.py", line 56, in run result = self.fn(*self.args, **self.kwargs) File "/config/custom_components/sensor/mi_water_purifier.py", line 34, in setup_platform waterPurifier = XiaomiWaterPurifier(device, name) File "/config/custom_components/sensor/mi_water_purifier.py", line 116, in init self.parse_data() File "/config/custom_components/sensor/mi_water_purifier.py", line 177, in parse_data except DeviceException: NameError: name 'DeviceException' is not defined

Sun Dec 02 2018 16:10:20 GMT+0800 (CST)

unable to parse json '{"result":[net],"id":1}': Expecting value: line 1 column 12 (char 11)

ptlinzx avatar Dec 03 '18 08:12 ptlinzx

@RavenKong @bluefoxlee @ptlinzx

name 'DeviceException' is not defined

This is a weird error message since I saw it sometimes when the component can't get data from device and try to raise an exception. I also confused why we saw this error message since DeviceException is already imported in code.

But I think the main problem of the logs you pasted is the miio library which this component uses to fetch data from xiaomi IOT devices can't get data from water purifier. I guess there are two possible reasons:

  1. the water purifier isn't reachable at that time for some reasons(network or device can't respond command). I encountered it before and just restarted home assistant to let it reconnect water purifier. It means the code isn't stable enough to handle this exception. Hope someone can help since I'm not familiar python and home assistant also :(
  2. The 1A model doesn't support the command I used for gen 1. As I know there are only three filters in 1A model, the command for getting data and the data format should be different from gen 1. Since I don't have 1A model, I can't test with miio command line tool to see which command and data format should be used for 1A. If someone can try with miio command line tool by himself and find correct command and data format, I can try to add code to support 1A model.

bit3725 avatar Jan 24 '19 12:01 bit3725

I just updated code and try to solve the weird issue that raised "name 'DeviceException' is not defined" when device isn't reachable. If you are using 1A model, you should just see the error message raised from miio library.

bit3725 avatar Jan 24 '19 12:01 bit3725

@bit3725 I will download the updated one and report here.

Update: Still got "TypeError: 'NoneType' object is not subscriptable." Will check miio tool to see if I can get more info from there. Still thanks,

bluefoxlee avatar Jan 29 '19 16:01 bluefoxlee