custom-components / sensor.owlintuition

A set of sensors to integrate the OWL Intuition devices network
MIT License
11 stars 9 forks source link

Error on Startup - invalid literal for int() with base 10: 'N/A' #33

Closed chorley14 closed 1 year ago

chorley14 commented 1 year ago

I am getting the below error on startup and then stops working.

Logger: homeassistant.components.sensor
Source: components/sensor/__init__.py:595
Integration: Sensor (documentation, issues)
First occurred: 5:55:21 PM (2 occurrences)
Last logged: 5:55:21 PM

Error adding entities for domain sensor with platform owlintuition
Error while setting up owlintuition platform for sensor
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/sensor/__init__.py", line 591, in state
    numerical_value = int(value)
                      ^^^^^^^^^^
ValueError: invalid literal for int() with base 10: 'N/A'

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 510, in async_add_entities
    await asyncio.gather(*tasks)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 750, in _async_add_entity
    await entity.add_to_platform_finish()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1004, in add_to_platform_finish
    self.async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 746, in async_write_ha_state
    self._async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 808, in _async_write_ha_state
    state = self._stringify_state(available)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 752, in _stringify_state
    if (state := self.state) is None:
                 ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/sensor/__init__.py", line 595, in state
    raise ValueError(
ValueError: Sensor sensor.owl_intuition_cost_today has device class 'monetary', state class 'total_increasing' unit 'None' and suggested precision 'None' thus indicating it has a numeric value; however, it has the non-numeric value: 'N/A' (<class 'str'>)

anyone else seen this issue?

shortbloke commented 1 year ago

Is this happening when HA restarts? or at a specific time of day?

glpatcern commented 1 year ago

This seems yet another strengthened check of HA core, surely all legitimate but effectively breaking existing integrations. Can you tell please which HA version are you running?

I suspect https://github.com/custom-components/sensor.owlintuition/blob/master/custom_components/owlintuition/sensor.py#L399 to be the culprit (and it may explain why I or @shortbloke don't see it). Maybe you could give it a try by replacing 'N/A' with 0 ?

chorley14 commented 1 year ago

Is this happening when HA restarts? or at a specific time of day?

Yeah, when HA starts-up.

chorley14 commented 1 year ago

This seems yet another strengthened check of HA core, surely all legitimate but effectively breaking existing integrations. Can you tell please which HA version are you running?

I suspect https://github.com/custom-components/sensor.owlintuition/blob/master/custom_components/owlintuition/sensor.py#L399 to be the culprit (and it may explain why I or @shortbloke don't see it). Maybe you could give it a try by replacing 'N/A' with 0 ?

I am running 2023.8.4, i have not updated to 2023.9.3 yet.

I have just changed N/A to 0 as suggested and this has fixed this issue.

Thanks for your help :)

glpatcern commented 1 year ago

Great, I've just pushed the fix