Skip to content

Type error in entities/appliance/fan.py #23

@gapple

Description

@gapple

I'm getting a large number of errors appearing in the logs

Error doing job: Task exception was never retrieved

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 899, in _async_registry_updated
    await self.platform.async_add_entities([self])
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 428, in async_add_entities
    await asyncio.gather(*tasks)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 673, in _async_add_entity
    await entity.add_to_platform_finish()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 776, in add_to_platform_finish
    self.async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 532, in async_write_ha_state
    self._async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 570, in _async_write_ha_state
    state = self._stringify_state(available)
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 538, in _stringify_state
    if (state := self.state) is None:
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 969, in state
    if (is_on := self.is_on) is None:
  File "/config/custom_components/mila/entities/appliance/fan.py", line 66, in is_on
    return self.speed is not None and self.speed > 0
  File "/config/custom_components/mila/entities/appliance/fan.py", line 57, in speed
    return sensor["latest"]["value"] if sensor else None
TypeError: 'NoneType' object is not subscriptable

The relevant code:

@property
def speed(self) -> float:
sensors: List = self.device.get_value("sensors")
sensor = next((i for i in sensors if i["kind"] == ApplianceSensorKind.FanSpeed), None)
return sensor["latest"]["value"] if sensor else None

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions