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.fordpass_fuel' cannot be added a second time #465

Open
jamesonuk opened this issue Jan 6, 2024 · 7 comments
Open

'sensor.fordpass_fuel' cannot be added a second time #465

jamesonuk opened this issue Jan 6, 2024 · 7 comments
Labels
bug Something isn't working

Comments

@jamesonuk
Copy link

jamesonuk commented Jan 6, 2024

on startup I am seeing errors for

homeassistant.exceptions.HomeAssistantError: Entity 'sensor.fordpass_fuel' cannot be added a second time to an entity platform

I do have two cars using the integration but the second car has sensor.forpass_fuel_2
Could also be that the fuel sensor (not _2) is for a hybrid that has petrol and electric ranges.

The sensors do appear to be setup and working but perhaps this is just a bug in the flow where the sensor is trying to get added twice?

@theOrakle
Copy link

Turn on debugging and see if it is from the new API....

I have just been ignoring for the last 2 months, but you are not alone.

2024-02-26 14:23:21.776 DEBUG (SyncWorker_20) [custom_components.fordpass.fordpass_new] Trying new vehicle API endpoint
2024-02-26 14:23:21.783 ERROR (MainThread) [homeassistant.components.sensor] Error adding entities for domain sensor with platform fordpass
Traceback (most recent call last):
  File "/opt/homeassistant/3.12.1/lib/python3.12/site-packages/homeassistant/helpers/entity_platform.py", line 533, in async_add_entities
    await asyncio.gather(*tasks)
  File "/opt/homeassistant/3.12.1/lib/python3.12/site-packages/homeassistant/helpers/entity_platform.py", line 589, in _async_add_entity
    entity.add_to_platform_start(
  File "/opt/homeassistant/3.12.1/lib/python3.12/site-packages/homeassistant/components/sensor/__init__.py", line 240, in add_to_platform_start
    super().add_to_platform_start(hass, platform, parallel_updates)
  File "/opt/homeassistant/3.12.1/lib/python3.12/site-packages/homeassistant/helpers/entity.py", line 1293, in add_to_platform_start
    raise HomeAssistantError(
homeassistant.exceptions.HomeAssistantError: Entity 'sensor.raptor_fuel' cannot be added a second time to an entity platform
2024-02-26 14:23:21.787 ERROR (MainThread) [homeassistant.components.sensor] Error while setting up fordpass platform for sensor
Traceback (most recent call last):
  File "/opt/homeassistant/3.12.1/lib/python3.12/site-packages/homeassistant/helpers/entity_platform.py", line 352, in _async_setup_platform
    await asyncio.gather(*pending)
  File "/opt/homeassistant/3.12.1/lib/python3.12/site-packages/homeassistant/helpers/entity_platform.py", line 533, in async_add_entities
    await asyncio.gather(*tasks)
  File "/opt/homeassistant/3.12.1/lib/python3.12/site-packages/homeassistant/helpers/entity_platform.py", line 589, in _async_add_entity
    entity.add_to_platform_start(
  File "/opt/homeassistant/3.12.1/lib/python3.12/site-packages/homeassistant/components/sensor/__init__.py", line 240, in add_to_platform_start
    super().add_to_platform_start(hass, platform, parallel_updates)
  File "/opt/homeassistant/3.12.1/lib/python3.12/site-packages/homeassistant/helpers/entity.py", line 1293, in add_to_platform_start
    raise HomeAssistantError(
homeassistant.exceptions.HomeAssistantError: Entity 'sensor.raptor_fuel' cannot be added a second time to an entity platform
2024-02-26 14:23:21.864 DEBUG (SyncWorker_20) [custom_components.fordpass.fordpass_new] 200
2024-02-26 14:23:21.864 DEBUG (SyncWorker_20) [custom_components.fordpass.fordpass_new] NEW API???

@jath58
Copy link

jath58 commented Feb 28, 2024

+1 same here, with one car (Ford Kuga).
Seems like some integration initialisation is stuck from the use of the previous versions of the fordpass-ha integration (pre the new ford-api).

@SquidBytes
Copy link
Collaborator

Are you able to determine if this is still an issue?

@theOrakle
Copy link

Why yes I can...

2024-05-09 18:25:33.422 ERROR (MainThread) [homeassistant.components.sensor] Error adding entity sensor.raptor_fuel for domain sensor with platform fordpass Traceback (most recent call last): File "/opt/homeassistant/3.12.1/lib/python3.12/site-packages/homeassistant/helpers/entity_platform.py", line 697, in _async_add_entity entity.add_to_platform_start( File "/opt/homeassistant/3.12.1/lib/python3.12/site-packages/homeassistant/components/sensor/__init__.py", line 233, in add_to_platform_start super().add_to_platform_start(hass, platform, parallel_updates) File "/opt/homeassistant/3.12.1/lib/python3.12/site-packages/homeassistant/helpers/entity.py", line 1327, in add_to_platform_start raise HomeAssistantError( homeassistant.exceptions.HomeAssistantError: Entity 'sensor.raptor_fuel' cannot be added a second time to an entity platform

@jamesonuk
Copy link
Author

yep still an issue for me

Logger: homeassistant.components.sensor
Source: helpers/entity_platform.py:697
integration: Sensor ([documentation](https://www.home-assistant.io/integrations/sensor), [issues](https://github.com/home-assistant/core/issues?q=is%3Aissue+is%3Aopen+label%3A%22integration%3A+sensor%22))
First occurred: 11:23:20 (1 occurrences)
Last logged: 11:23:20

Error adding entity sensor.fordpass_fuel for domain sensor with platform fordpass
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 697, in _async_add_entity
    entity.add_to_platform_start(
  File "/usr/src/homeassistant/homeassistant/components/sensor/__init__.py", line 233, in add_to_platform_start
    super().add_to_platform_start(hass, platform, parallel_updates)
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1327, in add_to_platform_start
    raise HomeAssistantError(
homeassistant.exceptions.HomeAssistantError: Entity 'sensor.fordpass_fuel' cannot be added a second time to an entity platform

@SquidBytes SquidBytes added the bug Something isn't working label May 31, 2024
@TheLizard
Copy link

TheLizard commented Jul 2, 2024

I believe this can happen on PHEV cars:

In sensor.py, last part of function async_setup_entry:
`async def async_setup_entry(hass, config_entry, async_add_entities):

    else:
        for key in api_key: <!-- loop over all api_key for fuel entry in const.py
            if key and key in sensor.coordinator.data.get("metrics", {}):
                sensors.append(sensor) <!-- DUPLICATE ENTRY
                continue  <!-- Redundant continue

in const.py there are 2 keys for api_key:
"fuel": {"icon": "mdi:gas-station", "api_key": ["fuelLevel", "xevBatteryStateOfCharge"], "measurement": "%"},
`
if in the metrics, both fuelLevel and xevBatteryStateOfCharge are present, both will try to do sensors.append(sensor), resulting in adding the same name twice.
I believe the continue line after that tries to prevent it BUT, it will apply to the for key in api_key loop, actually doing nothing (also reported by my visual studio code editor by message: 'Remove this redundant continue.'

edit: unfortunately the 'code' doesn't work entirely as expected, but managed to tweak it to be manageable

@TheLizard
Copy link

Proposal: As it is the only sensor with a dual function, would it be sensible to place the xevBatteryStateOfCharge in it's own sensor named 'elVehCharge', there already is the battery sensor, which probably is used for the 12V battery.
A downside is that for current (probably EV only), the current fuel sensor is then changed to elVehCharge. Would there be a way to detect this, or make some migration for it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants