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

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

Closed
aherbjornsen opened this issue Jan 15, 2023 · 7 comments
Closed

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

aherbjornsen opened this issue Jan 15, 2023 · 7 comments

Comments

@aherbjornsen
Copy link

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 added a commit that referenced this issue Jan 16, 2023
@dummylabs
Copy link
Owner

dummylabs commented Jan 16, 2023

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
Copy link
Author

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
Copy link
Owner

dummylabs commented Jan 17, 2023

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
Copy link
Author

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
Copy link
Owner

dummylabs commented Jan 17, 2023

@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
Copy link
Author

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
Copy link
Owner

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.

dummylabs added a commit that referenced this issue Jan 17, 2023
This issue was closed.
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

No branches or pull requests

2 participants