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

Error during startup: Config entry has already been setup! #94

Closed
postlund opened this issue Oct 19, 2020 · 1 comment · Fixed by #100
Closed

Error during startup: Config entry has already been setup! #94

postlund opened this issue Oct 19, 2020 · 1 comment · Fixed by #100
Labels
bug Something isn't working

Comments

@postlund
Copy link
Collaborator

Seems to be some issue when setting up entities via YAML, yielding these error messages:

2020-10-18 20:28:10 ERROR (MainThread) [homeassistant.config_entries] Error setting up entry Tuya Device (YAML) for sensor
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 228, in async_setup
    result = await component.async_setup_entry(hass, self)  # type: ignore
  File "/usr/src/homeassistant/homeassistant/components/sensor/__init__.py", line 67, in async_setup_entry
    return await hass.data[DOMAIN].async_setup_entry(entry)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 155, in async_setup_entry
    raise ValueError("Config entry has already been setup!")
ValueError: Config entry has already been setup!
2020-10-18 20:28:10 ERROR (MainThread) [homeassistant.config_entries] Error setting up entry Tuya Device (YAML) for sensor
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 228, in async_setup
    result = await component.async_setup_entry(hass, self)  # type: ignore
  File "/usr/src/homeassistant/homeassistant/components/sensor/__init__.py", line 67, in async_setup_entry
    return await hass.data[DOMAIN].async_setup_entry(entry)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 155, in async_setup_entry
    raise ValueError("Config entry has already been setup!")
ValueError: Config entry has already been setup!
2020-10-18 20:28:10 ERROR (MainThread) [homeassistant.config_entries] Error setting up entry Tuya Plug 2 (YAML) for sensor
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 228, in async_setup
    result = await component.async_setup_entry(hass, self)  # type: ignore
  File "/usr/src/homeassistant/homeassistant/components/sensor/__init__.py", line 67, in async_setup_entry
    return await hass.data[DOMAIN].async_setup_entry(entry)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 155, in async_setup_entry
    raise ValueError("Config entry has already been setup!")
ValueError: Config entry has already been setup!
2020-10-18 20:28:10 ERROR (MainThread) [homeassistant.config_entries] Error setting up entry Tuya Plug 2 (YAML) for sensor
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 228, in async_setup
    result = await component.async_setup_entry(hass, self)  # type: ignore
  File "/usr/src/homeassistant/homeassistant/components/sensor/__init__.py", line 67, in async_setup_entry
    return await hass.data[DOMAIN].async_setup_entry(entry)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 155, in async_setup_entry
    raise ValueError("Config entry has already been setup!")
ValueError: Config entry has already been setup!
2020-10-18 20:28:10 ERROR (MainThread) [homeassistant.config_entries] Error setting up entry Tuya Plug 3 (YAML) for sensor
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 228, in async_setup
    result = await component.async_setup_entry(hass, self)  # type: ignore
  File "/usr/src/homeassistant/homeassistant/components/sensor/__init__.py", line 67, in async_setup_entry
    return await hass.data[DOMAIN].async_setup_entry(entry)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 155, in async_setup_entry
    raise ValueError("Config entry has already been setup!")
ValueError: Config entry has already been setup!
2020-10-18 20:28:10 ERROR (MainThread) [homeassistant.config_entries] Error setting up entry Tuya Plug 3 (YAML) for sensor
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 228, in async_setup
    result = await component.async_setup_entry(hass, self)  # type: ignore
  File "/usr/src/homeassistant/homeassistant/components/sensor/__init__.py", line 67, in async_setup_entry
    return await hass.data[DOMAIN].async_setup_entry(entry)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 155, in async_setup_entry
    raise ValueError("Config entry has already been setup!")
ValueError: Config entry has already been setup!

Config looks like this:

localtuya:
  - host: 192.168.1.44  
    local_key: xxx
    device_id: xxx
    friendly_name: Tuya Plug 1
    protocol_version: "3.3"
    entities:
      - platform: switch
        friendly_name: Kitchen Plug 1
        id: 1
        current: 18
        current_consumption: 19
        voltage: 20
      - platform: sensor
        friendly_name: Plug 1 Current
        id: 18
        device_class: current # 18 # Optional
        scaling: 0.001
        unit_of_measurement: "A"
      - platform: sensor
        friendly_name: Plug 1 Power
        id: 19
        device_class: power
        scaling: 0.1
        unit_of_measurement: "W"
      - platform: sensor
        friendly_name: Plug 1 Voltage
        id: 20
        device_class: voltage
        scaling: 0.1
        unit_of_measurement: "V"
        # voltage: 20
  - host: 192.168.1.51
    local_key: yyy
    device_id: yyy
    friendly_name: Tuya Plug 2
    protocol_version: "3.3"
    entities:
      - platform: switch
        friendly_name: Kitchen Plug 2
        id: 1
        current: 18
        current_consumption: 19
        voltage: 20
      - platform: sensor
        friendly_name: Plug 2 Current
        id: 18
        device_class: current # 18 # Optional
        scaling: 0.001
        unit_of_measurement: "A"
      - platform: sensor
        friendly_name: Plug 2 Power
        id: 19
        device_class: power
        scaling: 0.1
        unit_of_measurement: "W"  
      - platform: sensor
        friendly_name: Plug 2 Voltage
        id: 20
        device_class: voltage
        scaling: 0.1
        unit_of_measurement: "V"
  - host: 192.168.1.52
    local_key: zzz
    device_id: zzz
    friendly_name: Tuya Plug 3
    protocol_version: "3.3"
    entities:
      - platform: switch
        friendly_name: TV Plug
        id: 1
        current: 18
        current_consumption: 19
        voltage: 20
      - platform: sensor
        friendly_name: TV Plug Current
        id: 18
        device_class: current # 18 # Optional
        scaling: 0.001
        unit_of_measurement: "A"
      - platform: sensor
        friendly_name: TV Plug Power
        id: 19
        device_class: power
        scaling: 0.1
        unit_of_measurement: "W"  
      - platform: sensor
        friendly_name: TV Plug Voltage
        id: 20
        device_class: voltage
        scaling: 0.1
        unit_of_measurement: "V"

Reported in #86 (output copied from there). Will have to look into that.

@postlund
Copy link
Collaborator Author

Ok, so now I know when and why this happens. It happens whenever two or more entities with the same type ("platform") is defined for a device. The reason for this is that we iterate over each defined entity and forward the config entry being set up to its corresponding platform. If two switch entities are defined, we will forward the same config entry to the switch platform twice, which isn't correct (and the reason we get the error). It should only be done once per platform (each platform will extract entities to set up later on). I have a fix, just need to tidy up and push.

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

Successfully merging a pull request may close this issue.

1 participant