Error doing job: Task exception was never retrieved
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 408, in _async_add_entity
await entity.async_update_ha_state()
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 286, in async_update_ha_state
self._async_write_ha_state()
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 320, in _async_write_ha_state
state = self.state
File "/usr/src/homeassistant/homeassistant/components/weather/__init__.py", line 188, in state
return self.condition
File "/config/custom_components/hf_weather/weather.py", line 161, in condition
return [k for k, v in CONDITION_CLASSES.items() if self._condition in v][0]
IndexError: list index out of range
然后我把161行的
return [k for k, v in CONDITION_CLASSES.items() if self._condition in v][0]
改成了
for key in CONDITION_CLASSES.keys():
if self._condition in CONDITION_CLASSES[key]:
return key
这样就能正常触发下面的return 'unknown',这样万一API又多了什么新的中文关键词,也能正确触发unknown,不会报错