midea_inventor_dehumidifier
midea_inventor_dehumidifier copied to clipboard
Avoid throwing exception when device offline
It is quite common for the dehumidifier to be offline, e.g. somebody unplugged it etc. In this situation it would be good to report this rather than throw exceptions.
In such an instance still, create the climate/sensor components but have them report null? Or the device to simply report as offline state? This is the error message that gets reported in the log:
2019-01-07 16:21:01 ERROR (MainThread) [root] MideaClient::send_api_request: errorCode=3123, errorMessage="the appliance is off line."
2019-01-07 16:21:01 ERROR (MainThread) [root] MideaClient::appliance_transparent_send: result=ERROR in API response: result key not found
2019-01-07 16:21:01 ERROR (MainThread) [root] MideaClient::get_device_status: invalid API response
2019-01-07 16:21:01 ERROR (MainThread) [custom_components.climate.midea_dehumi] climate.midea_dehui: errog getting appliance's status via Web API.
2019-01-07 16:21:01 ERROR (MainThread) [homeassistant.helpers.entity] Update for sensor.midea_dehumi_18691697681380_humidity fails
Traceback (most recent call last):
File "/usr/local/lib/python3.6/site-packages/homeassistant/helpers/entity.py", line 221, in async_update_ha_state
await self.async_device_update()
File "/usr/local/lib/python3.6/site-packages/homeassistant/helpers/entity.py", line 347, in async_device_update
await self.async_update()
File "/config/custom_components/sensor/midea_dehumi.py", line 111, in async_update
self.__updateStateFromClimateEntity()
File "/config/custom_components/sensor/midea_dehumi.py", line 74, in __updateStateFromClimateEntity
self._state = state.attributes["current_humidity"]
KeyError: 'current_humidity'
It will be likely fixed in next release: let the created entity reporting null appears resonable in this condition.