MisterWil / abodepy

A thin Python wrapper for the Abode alarm API
MIT License
49 stars 17 forks source link

Random error in sensor.py #65

Open shred86 opened 4 years ago

shred86 commented 4 years ago

I’ve noticed this for a while but figured I’d post this here for reference. Every now and then I’ll see these errors in my Home Assistant logs that’s pointing to abodepy. This must be coming from my Abode multi-sensor but it doesn’t appear to have any issues in Home Assistant.

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 284, in async_update_ha_state
    self._async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 330, in _async_write_ha_state
    unit_of_measurement = self.unit_of_measurement
  File "/usr/src/homeassistant/homeassistant/components/abode/sensor.py", line 83, in unit_of_measurement
    return self._device.humidity_unit
  File "/usr/local/lib/python3.7/site-packages/abodepy/devices/sensor.py", line 46, in humidity_unit
    if CONST.UNIT_PERCENT in self._get_status(CONST.HUMI_STATUS_KEY):
TypeError: argument of type 'NoneType' is not iterable
Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 284, in async_update_ha_state
    self._async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 330, in _async_write_ha_state
    unit_of_measurement = self.unit_of_measurement
  File "/usr/src/homeassistant/homeassistant/components/abode/sensor.py", line 85, in unit_of_measurement
    return self._device.lux_unit
  File "/usr/local/lib/python3.7/site-packages/abodepy/devices/sensor.py", line 58, in lux_unit
    if CONST.UNIT_LUX in self._get_status(CONST.LUX_STATUS_KEY):
TypeError: argument of type 'NoneType' is not iterable
shred86 commented 4 years ago

Not really sure what's going on with this one. If I'm understanding this correctly:

def _get_status(self, key):
        return self._json_state.get(CONST.STATUSES_KEY, {}).get(key)

This should simply be looking for the key that is passed within the CONST.STATUSES_KEY key, which in this case is either CONST.LUX_STATUS_KEY or CONST.HUMI_STATUS_KEY. Example of the statuses key in the device JSON:

"statuses": {
        "temperature": "71 \u00b0F",
        "temp": "21.6",
        "lux": "1 lx",
        "humidity": "34 %"
    },

Based on TypeError: argument of type 'NoneType' is not iterable, the _get_status(self, key) method is sometimes not returning anything meaning the statuses key is sometimes empty.

ahutchings commented 4 years ago

I just saw one of these in my logs, and it looks like it's due to the device disconnecting from the gateway. In my case the exception is due to the temperature value not containing a unit of measurement. Perhaps when the status is offline, the device should be marked as unavailable in HA and the status values should be ignored - in the logs below, even if the temperature had a unit it appears to have an inaccurate value (-22.21, which this freezer never hits regardless of unit).

Screen Shot 2020-06-10 at 11 35 18 PM
2020-06-10 22:32:15 DEBUG (SocketIOThread) [abodepy.event_controller] Device update event for device ID: ZB:6b1301
2020-06-10 22:32:16 DEBUG (SocketIOThread) [abodepy.devices] Device Refresh Response: [{"id":"ZB:6b1301","type_tag":"device_type.lm","type":"LM","name":"Freezer","area":"1","zone":"17","sort_order":"","is_window":"","bypass":"0","schar_24hr":"0","sresp_24hr":"0","sresp_mode_0":"0","sresp_entry_0":"0","sresp_exit_0":"0","group_name":"Ungrouped","group_id":"1","default_group_id":"1","sort_id":"10000","sresp_mode_1":"0","sresp_entry_1":"0","sresp_exit_1":"0","sresp_mode_2":"0","sresp_entry_2":"0","sresp_exit_2":"0","sresp_mode_3":"0","uuid":"5eaf8f566162eee88282ec86e82d0c38","sresp_entry_3":"0","sresp_exit_3":"0","sresp_mode_4":"0","sresp_entry_4":"0","sresp_exit_4":"0","version":"LMHT_00.00.03.06TC","origin":"abode","has_subscription":null,"onboard":"0","s2_grnt_keys":"","s2_dsk":"","s2_propty":"","s2_keys_valid":"","zwave_secure_protocol":"","control_url":"","deep_link":null,"status_color":"#d9534f","faults":{"low_battery":0,"tempered":0,"supervision":1,"out_of_order":0,"no_response":0,"jammed":0,"zwave_fault":0},"status":"Offline","status_display":"Offline","statuses":{"temp":"-22.21","lux":"0 lx","humidity":"0 %"},"status_ex":"","actions":[{"label":"High Humidity Alarm","value":"a=1&z=17&trigger=HMH;"},{"label":"Low Humidity Alarm","value":"a=1&z=17&trigger=HML;"},{"label":"High Temperature Alarm","value":"a=1&z=17&trigger=TSH;"},{"label":"Low Temperature Alarm","value":"a=1&z=17&trigger=TSL;"}],"status_icons":[],"icon":"assets\/icons\/automation-thermostat.svg","statusEx":"0"}]
2020-06-10 22:32:16 ERROR (MainThread) [homeassistant.core] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 284, in async_update_ha_state
    self._async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 326, in _async_write_ha_state
    unit_of_measurement = self.unit_of_measurement
  File "/usr/src/homeassistant/homeassistant/components/abode/sensor.py", line 75, in unit_of_measurement
    return self._device.temp_unit
  File "/usr/local/lib/python3.7/site-packages/abodepy/devices/sensor.py", line 30, in temp_unit
    if CONST.UNIT_FAHRENHEIT in self._get_status(CONST.TEMP_STATUS_KEY):
TypeError: argument of type 'NoneType' is not iterable
2020-06-10 22:32:16 DEBUG (SocketIOThread) [lomond]  SRV -> CLI : <frame TEXT (862 bytes) fin=1>
2020-06-10 22:32:16 DEBUG (SocketIOThread) [abodepy.event_controller] Timeline event received: Freezer Not Connected to Gateway - Not Connected to Gateway (1147)
2020-06-10 22:32:16 DEBUG (MainThread) [homeassistant.core] Bus:Handling <Event abode_alarm[L]: device_id=ZB:6b1301, device_name=Freezer, device_type=LM, event_code=1147, event_name=Freezer Not Connected to Gateway, event_type=Not Connected to Gateway, event_utc=1591842735, user_name=, app_type=, event_by=, date=06/10/2020, time=10:32 PM>