Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
gapple opened this issue Dec 8, 2022 · 0 comments
Open

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

gapple opened this issue Dec 8, 2022 · 0 comments
Labels
good first issue Good for newcomers

Comments

@gapple
Copy link

gapple commented Dec 8, 2022

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

@sanghviharshit sanghviharshit added the good first issue Good for newcomers label Feb 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants