OpenEPaperLink / Home_Assistant_Integration

Home assistant Integration for the OpenEPaperLink project
Apache License 2.0
137 stars 32 forks source link

Fix TypeError when temperature isn't present #38

Closed jwoglom closed 10 months ago

jwoglom commented 10 months ago

Fixes an error I was seeing in the homeassistant logs, due to my openepaper AP not reporting temperature:

2023-10-14 03:58:00.733 ERROR (MainThread) [homeassistant.helpers.entity] Update for sensor.ap_temp fails
Traceback (most recent call last):
  File "/srv/homeassistant/lib/python3.10/site-packages/homeassistant/helpers/entity.py", line 554, in async_update_ha_state
    await self.async_device_update()
  File "/srv/homeassistant/lib/python3.10/site-packages/homeassistant/helpers/entity.py", line 781, in async_device_update
    await hass.async_add_executor_job(self.update)
  File "/usr/lib/python3.10/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/root/.homeassistant/custom_components/open_epaper_link/sensor.py", line 124, in update
    self._attr_native_value = round(self._hub.data["ap"]["temp"],1)
TypeError: type NoneType doesn't define __round__ method

HomeAssistant then reports the sensor as "Unknown" rather than crashing:

image