dummylabs / thewatchman

Home Assistant custom integration to keep track of missing entities and actions in your config files
MIT License
481 stars 20 forks source link

AttributeError: 'float' object has no attribute 'replace' #75

Closed aherbjornsen closed 1 year ago

aherbjornsen commented 1 year ago

Lately I've started seeing this error every 15 minutes:

2023-01-15 18:46:36.922 ERROR (MainThread) [custom_components.watchman.coordinator] Unexpected error fetching Watchman data: 'float' object has no attribute 'replace'
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 225, in _async_refresh
    self.data = await self._async_update_data()
  File "/config/custom_components/watchman/coordinator.py", line 31, in _async_update_data
    entities_missing = check_entitites(self.hass)
  File "/config/custom_components/watchman/utils.py", line 221, in check_entitites
    state, _ = get_entity_state(hass, entry)
  File "/config/custom_components/watchman/utils.py", line 185, in get_entity_state
    state = "missing" if not entity else entity.state.replace("unavailable", "unavail")
AttributeError: 'float' object has no attribute 'replace'

Any suggestions to what the problem is? This is HASS 2023.1.4

dummylabs commented 1 year ago

Hi @aherbjornsen, it looks weird. I've just tested it against 2021.2 and all tests passed successfully. Nevertheless, I've added some additional checks for this piece of code, now it should write an error message to the HA log instead of crashing.

Could you please install last version from the main branch and check HA logs for Watchman errors? In order to do this:

  1. Go to HACS->Integrations, click Watchman, three dots menu on the right and select Redownload.
  2. The dialog appears with the version selector, you have to choose "main", then click "Download"
  3. Restart HA to apply new version of Watchman

In order to check if new version was installed, go to Settings->Devices&Services and click "1 service" link under Watchman tile. You should see version 0.6.1 under Service Info. Then, please, check HA logs and paste here the error message from Watchman for further investigations. Thanks!

aherbjornsen commented 1 year ago

Thanks for the detailed response.

I've tried to update Watchman from HACS, as per your instructions, but is unable to see a higher version than 0.6.0. I even checked for beta versions, but I seem to be stuck with 0.6.0.

dummylabs commented 1 year ago

This is correct, 0.6.1 will not be shown in the HACS versions list. You should select "main" in the list of versions as per attached screenshot:

image

This is not an "official" new version published to HACS yet, just a quick and dirty fix in the main branch to figure out the reason of this error. AFAIK all the states for all entities in Home Assistant reported as strings even if they're numbers. In your case a state was reported as float so I'm curious what entity/integration caused this.

aherbjornsen commented 1 year ago

Sorry, I missed the "main" part. Redownloaded once again and now I see 0.6.1 and the error messages seems to have gone. Thanks for your patience and fast response.

dummylabs commented 1 year ago

@aherbjornsen Great! Could you please check HA logs now and post here the relevant error message(s) from Watchman (Unable to get state for...)? I hope it helps to find out the reason of this error.

aherbjornsen commented 1 year ago

The messages I saw before the upgrade has gone. Then I saw them at regular 15 minute intervals.

After the upgrade I see two errors:

2023-01-17 11:51:25.271 ERROR (MainThread) [custom_components.watchman.utils] Unable to get state for sensor.nordpool_kwh_oslo_nok_3_095_025: 'float' object has no attribute 'replace'. Type: <class 'float'>
2023-01-17 11:52:32.999 ERROR (MainThread) [custom_components.watchman.utils] Unable to get state for sensor.nordpool_kwh_oslo_nok_3_095_025: 'float' object has no attribute 'replace'. Type: <class 'float'>

This a sensor created by the Nordpool custom integration: https://github.com/custom-components/nordpool/releases

dummylabs commented 1 year ago

Thanks, this confirms my speculation about a custom integration which, probably, does not follow HA development guidelines. I'll check it. So far (in 0.6.1) these two sensors will be present in your Watchman report with error state. In the next Watchman release these sensors will be processed as a regular sensor with no errors.