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

sensor AssertionError with 2022.4 #112

Closed
Aohzan opened this issue Apr 6, 2022 · 9 comments · Fixed by #113
Closed

sensor AssertionError with 2022.4 #112

Aohzan opened this issue Apr 6, 2022 · 9 comments · Fixed by #113

Comments

@Aohzan
Copy link

Aohzan commented Apr 6, 2022

Hello
I'm trying the last beta and I got an error. I added two lines to /usr/src/homeassistant/homeassistant/components/sensor/__init__.py to know which integration raise this error

            _LOGGER.warning(self.name)
            _LOGGER.warning(native_unit_of_measurement)

logs:

2022-04-06 09:21:34 WARNING (MainThread) [homeassistant.components.sensor] Pure Hot+Cool Temperature
2022-04-06 09:21:34 WARNING (MainThread) [homeassistant.components.sensor] None
2022-04-06 09:21:34 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 137, in _handle_refresh_interval
    await self._async_refresh(log_failures=True, scheduled=True)
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 268, in _async_refresh
    update_callback()
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 328, in _handle_coordinator_update
    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/components/sensor/__init__.py", line 456, in state
    assert native_unit_of_measurement
AssertionError
2022-04-06 09:21:34 WARNING (MainThread) [homeassistant.components.sensor] Pure Hot+Cool Temperature
2022-04-06 09:21:34 WARNING (MainThread) [homeassistant.components.sensor] None
2022-04-06 09:21:34 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 519, in async_update_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/components/sensor/__init__.py", line 456, in state
    assert native_unit_of_measurement
AssertionError
/bin/sh: False: not found

Thank you

@Aohzan Aohzan changed the title Error with 2022.4 AssertionError with 2022.4 Apr 6, 2022
@Aohzan Aohzan changed the title AssertionError with 2022.4 sensor AssertionError with 2022.4 Apr 6, 2022
@jasperslits
Copy link
Contributor

I have the same and change the code to:

            assert unit_of_measurement
            _LOGGER.warning("Entity %s",self.entity_id)
            assert native_unit_of_measurement

This returns:
2022-04-06 10:48:37 WARNING (MainThread) [homeassistant.components.sensor] Entity sensor.dyson_temperature

If I disable that entity the error goes away

@jasperslits
Copy link
Contributor

jasperslits commented Apr 6, 2022

Adding

    native_unit_of_measurement = TEMP_CELSIUS

I'll make a PR later but this is what sensor.py should be changed to in Dyson_local:

class DysonTemperatureSensor(DysonSensorEnvironmental):
    """Dyson temperature sensor."""

    _SENSOR_TYPE = "temperature"
    _SENSOR_NAME = "Temperature"
    _attr_device_class = SensorDeviceClass.TEMPERATURE
    native_unit_of_measurement = TEMP_CELSIUS

@MJHeijster
Copy link

Ah that explains some things! :D

@monsieurlatte
Copy link

Glad to see I'm not the only one, so many entries that dont work that I use a lot (mostly the night mode toggle lol).

@jasperslits
Copy link
Contributor

Glad to see I'm not the only one, so many entries that dont work that I use a lot (mostly the night mode toggle lol).

Probably there might be more in need of a replacement with unit of measurement but this was the only one - for now - that kept spamming the logs.

I actually used the latest git main branch of the component as it contains quite a few other changes compared to the latest release from last year. My changes were based on the current branch.

@lezmaka
Copy link

lezmaka commented Apr 6, 2022

I had the same issue but I had to keep the _attr_device_class to the existing "DEVICE_CLASS_TEMPERATURE", it didn't like changing it to SensorDeviceClass.TEMPERATURE. I've got v0.16.2 installed through HACS and I was editing directly in the custom_components/dyson_local/ folder using Studio Code Server. Also like everything HACS, had to restart HA after making changes for them to show up.

As for the switches and other sensors, I was able to get them working by editing sensor.py and switch.py using this change from the Alexa Media Player.

I basically added
from homeassistant.helpers.entity import EntityCategory
to the top sections of the two files and then changed any instance of ENTITY_CATEGORY_DIAGNOSTIC to EntityCategory.DIAGNOSTIC and instances of ENTITY_CATEGORY_CONFIG to EntityCategory.CONFIG.

Don't know how to do a pull request, but hopefully this might help.

@jasperslits
Copy link
Contributor

I had the same issue but I had to keep the _attr_device_class to the existing "DEVICE_CLASS_TEMPERATURE", it didn't like changing it to SensorDeviceClass.TEMPERATURE. I've got v0.16.2 installed through HACS and I was editing directly in the custom_components/dyson_local/ folder using Studio Code Server. Also like everything HACS, had to restart HA after making changes for them to show up.

As for the switches and other sensors, I was able to get them working by editing sensor.py and switch.py using this change from the Alexa Media Player.

I basically added from homeassistant.helpers.entity import EntityCategory to the top sections of the two files and then changed any instance of ENTITY_CATEGORY_DIAGNOSTIC to EntityCategory.DIAGNOSTIC and instances of ENTITY_CATEGORY_CONFIG to EntityCategory.CONFIG.

Don't know how to do a pull request, but hopefully this might help.

The current brach - unreleased - already has these fixes.
I think for users already upgraded to 2022.04 it makes sense that @shenxn creates a new release which includes my PR. I don't have any Dyson errors / warnings in my HA with this.

@Kakise
Copy link
Collaborator

Kakise commented Apr 6, 2022

PR merged and new release made, sorry for my absence these days I am really sick :S

Tell me if it fixes everything :)

@jasperslits
Copy link
Contributor

jasperslits commented Apr 6, 2022

PR merged and new release made, sorry for my absence these days I am really sick :S

Tell me if it fixes everything :)

Thanks and get well soon! Now the part that needed to be cleaned up was the libdyson reference as it looks that also needed to be bumped as current code depended on an unreleased version?

That's this commit: e742bae

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants