qqaatw / JciHitachiHA

A home assistant integration for controlling Jci-Hitachi devices, using LibJciHitachi backend. 台灣日立雲端模組
Apache License 2.0
114 stars 31 forks source link

pm25_value could be "unsupported" if dehumidifier didn't have pm2.5 sensor. #45

Closed RiANOl closed 1 year ago

RiANOl commented 1 year ago

pm25_value could be "unsupported" if dehumidifier didn't have pm2.5 sensor. Tested on RDI-640HH

qqaatw commented 1 year ago

That’s the desired behavior.

RiANOl commented 1 year ago

But it will crash whole integration. Home Assistant consider this entity must not be string because of pm25 device class. Maybe it should return None if get the "unsupported" value?

qqaatw commented 1 year ago

Does the crash cause the integration being fully unusable or just throwing an error message?

Can you please paste the log or screenshot here? We accept PRs fixing that if the former is the case.

RiANOl commented 1 year ago

It will throw exception while setting up integration.

Log Details (ERROR)
Logger: homeassistant.components.sensor
Source: components/sensor/__init__.py:583
Integration: Sensor ([documentation](https://www.home-assistant.io/integrations/sensor), [issues](https://github.com/home-assistant/home-assistant/issues?q=is%3Aissue+is%3Aopen+label%3A%22integration%3A+sensor%22))
First occurred: 11:07:14 AM (2 occurrences)
Last logged: 11:07:14 AM

Error adding entities for domain sensor with platform jcihitachi_tw
Error while setting up jcihitachi_tw platform for sensor
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/sensor/__init__.py", line 581, in state
    numerical_value = float(value)  # type:ignore[arg-type]
ValueError: could not convert string to float: 'unsupported'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 455, in async_add_entities
    await asyncio.gather(*tasks)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 731, in _async_add_entity
    await entity.add_to_platform_finish()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 846, in add_to_platform_finish
    self.async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 585, in async_write_ha_state
    self._async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 649, in _async_write_ha_state
    state = self._stringify_state(available)
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 591, in _stringify_state
    if (state := self.state) is None:
  File "/usr/src/homeassistant/homeassistant/components/sensor/__init__.py", line 583, in state
    raise ValueError(
ValueError: Sensor sensor.dehumidifier_pm2_5 has device class pm25, state class None unit µg/m³ and suggested precision None thus indicating it has a numeric value; however, it has the non-numeric value: unsupported (<class 'str'>)
qqaatw commented 1 year ago

Hmm, when the error occurred, could other sensors/entities in other platforms be loaded normally, or they were blocked by the error?

It used to work until some changes brought by recent HA core versions I guess.

RiANOl commented 1 year ago

It still can set value but unable to get the update when the error occurred. For example, I can turn on/off AC or dehumidifier or change the temperature, but the entity still show the previous value.

RiANOl commented 1 year ago

It used to work until some changes brought by recent HA core versions I guess.

Exactly, it happened since HA core upgrade to 2023.5.