JurajNyiri / HomeAssistant-Tapo-Control

Control for Tapo cameras as a Home Assistant component
Apache License 2.0
957 stars 80 forks source link

ValueError: Config entry has already been setup #447

Closed codyc1515 closed 8 months ago

codyc1515 commented 8 months ago

Description

When re-configuring the device, the config entry does not get re-loaded correctly.

Reproduction Steps

  1. Browse to Devices & Services -> Tapo: Cameras Control -> Camera Name
  2. Press Reload from the options selection

~~2. Press Configure button

  1. Select Action = Configure device
  2. Change something (maybe input Cloud Password, if it was empty before), then Submit~~

Expected behavior

No errors in logs.

If applicable, add error logs.

Logger: homeassistant.config_entries
Source: config_entries.py:402
First occurred: 10:27:50 (1 occurrences)
Last logged: 10:27:50

Error setting up entry Dining Room Camera for sensor
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 402, in async_setup
    result = await component.async_setup_entry(hass, self)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/sensor/__init__.py", line 130, in async_setup_entry
    return await component.async_setup_entry(entry)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 187, in async_setup_entry
    raise ValueError("Config entry has already been setup!")
ValueError: Config entry has already been setup!
Logger: homeassistant.config_entries
Source: config_entries.py:557
First occurred: 10:06:17 (2 occurrences)
Last logged: 10:27:46

Error unloading entry Dining Room Camera for binary_sensor
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 557, in async_unload
    result = await component.async_unload_entry(hass, self)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/binary_sensor/__init__.py", line 175, in async_unload_entry
    return await component.async_unload_entry(entry)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 202, in async_unload_entry
    raise ValueError("Config entry was never loaded!")
ValueError: Config entry was never loaded!

Device Firmware

1.3.6 Build 230424 Rel.77225n(4555)

Integration Version

5.4.2

Using stream component

Yes

Does camera work via official integrations?

Yes

Camera has all attributes filled out in developer tools

Yes

HASS Environment

OS

Search for similar issues

Yes

Additional information

access_token: xxx
model_name: C200
brand: TP-Link
motion_detection: on
frontend_stream_type: hls
device_type: SMART.IPCAMERA
device_model: C200
device_name: C200 1.0
device_info: C200 1.0 IPC
hw_version: 1.0
sw_version: 1.3.6 Build 230424 Rel.77225n(4555)
device_alias: Dining Room Camera
avatar: camera c212
longitude: 0
latitude: 0
has_set_location_info: 0
features: 3
barcode: 
mac: 28-EE-52-93-E9-D3
dev_id: 80215ACBBFF1B116E989BD4366B7BBF31E273DDA
oem_id: 8902D2F34FCE407721DE92F5759839C2
hw_desc: 48574445534300000000000000000001
alarm: off
user: homeassistant
presets: 
{}

record_plan: 
sunday: '["0000-2400:2"]'
monday: '["0000-2400:2"]'
tuesday: '["0000-2400:2"]'
wednesday: '["0000-2400:2"]'
thursday: '["0000-2400:2"]'
friday: '["0000-2400:2"]'
saturday: '["0000-2400:2"]'

entity_picture: /api/camera_proxy/camera.dining_room?token=xxx
icon: mdi:webcam
friendly_name: Dining Room Camera
supported_features: 3
JurajNyiri commented 8 months ago

I could not replicate this, please provide exact and clear replication steps (starting from no devices ideally), the ones you provided are not replicating the issue.

codyc1515 commented 8 months ago

The steps are there under Reproduction Steps. I'll repeat them here again:

  1. Browse to Devices & Services -> Tapo: Cameras Control -> Camera Name
  2. Press Configure button
  3. Select Action = Configure device
  4. Change something (maybe input Cloud Password, if it was empty before), then Submit
JurajNyiri commented 8 months ago

Ok then, I will repeat my message again:

I could not replicate this, please provide exact and clear replication steps (starting from no devices ideally), the ones you provided are not replicating the issue.

Refrain from opening more issues unless you take the time to verify your very strong (and incorrect) assumptions or read my messages, you opened 5 issues in last hours, out of which 3 were invalid and wasted my time reading.

codyc1515 commented 8 months ago

Sorry but just because you could not replicate the issue does not make it invalid. You could try hit on Reload option instead. It's happening every time.

Appears to be caused by this - https://github.com/JurajNyiri/HomeAssistant-Tapo-Control/blob/1427931a0ce5c584bd25d2a570ffa569a21e668e/custom_components/tapo_control/config_flow.py#L1027C33-L1027C33

2023-11-08 11:25:38.735 DEBUG (MainThread) [custom_components.tapo_control] [172.16.32.227] Opened Tapo options.
2023-11-08 11:25:40.675 DEBUG (MainThread) [custom_components.tapo_control] [172.16.32.227] Opened Tapo options.
2023-11-08 11:25:40.675 DEBUG (MainThread) [custom_components.tapo_control] [172.16.32.227] Verifying updated data.
2023-11-08 11:25:40.675 DEBUG (MainThread) [custom_components.tapo_control] [172.16.32.227] Skipping test of cloud password for control as it was not updated.
2023-11-08 11:25:40.676 DEBUG (MainThread) [custom_components.tapo_control] [172.16.32.227] Skipping test of RTSP stream as Camera Account is the same.
2023-11-08 11:25:40.676 DEBUG (MainThread) [custom_components.tapo_control] [172.16.32.227] Skipping test of control using Camera Account since cloud password is provided.
2023-11-08 11:25:40.676 DEBUG (MainThread) [custom_components.tapo_control] [172.16.32.227] Skipping removal of devices since IP address did not change.
2023-11-08 11:25:40.676 DEBUG (MainThread) [custom_components.tapo_control] [172.16.32.227] Updating entry.
2023-11-08 11:25:40.677 DEBUG (MainThread) [custom_components.tapo_control] [172.16.32.227] Skipping reload of entry.
2023-11-08 11:25:40.810 DEBUG (MainThread) [custom_components.tapo_control] [initOnvifEvents] Creating onvif connection...
2023-11-08 11:25:40.887 DEBUG (MainThread) [custom_components.tapo_control] [initOnvifEvents] Creating onvif connection...
2023-11-08 11:25:40.908 DEBUG (MainThread) [custom_components.tapo_control] [initOnvifEvents] Connection estabilished.
2023-11-08 11:25:40.909 DEBUG (MainThread) [custom_components.tapo_control] [initOnvifEvents] Getting device information...
2023-11-08 11:25:40.954 DEBUG (MainThread) [custom_components.tapo_control] [initOnvifEvents] Connection estabilished.
2023-11-08 11:25:40.955 DEBUG (MainThread) [custom_components.tapo_control] [initOnvifEvents] Getting device information...
2023-11-08 11:25:41.097 DEBUG (MainThread) [custom_components.tapo_control] [initOnvifEvents] Got device information.
2023-11-08 11:25:41.098 DEBUG (MainThread) [custom_components.tapo_control] setupOnvif - entry
2023-11-08 11:25:41.098 DEBUG (MainThread) [custom_components.tapo_control] Setting up onvif...
2023-11-08 11:25:41.098 DEBUG (MainThread) [custom_components.tapo_control] setupEvents - entry
2023-11-08 11:25:41.099 DEBUG (MainThread) [custom_components.tapo_control] Detected base_url schema: http
2023-11-08 11:25:41.100 DEBUG (MainThread) [custom_components.tapo_control] Detected base_url schema: http
2023-11-08 11:25:41.101 DEBUG (MainThread) [custom_components.tapo_control] Using HTTPS: False
2023-11-08 11:25:41.101 DEBUG (MainThread) [custom_components.tapo_control] Webhook enabled: True
2023-11-08 11:25:41.101 DEBUG (MainThread) [custom_components.tapo_control] Using Webhooks: True
2023-11-08 11:25:41.101 DEBUG (MainThread) [custom_components.tapo_control] Setting up events...
2023-11-08 11:25:41.101 DEBUG (MainThread) [custom_components.tapo_control] WSPullPointSupport: True
2023-11-08 11:25:41.205 DEBUG (MainThread) [custom_components.tapo_control] [initOnvifEvents] Got device information.
2023-11-08 11:25:41.205 DEBUG (MainThread) [custom_components.tapo_control] setupOnvif - entry
2023-11-08 11:25:41.205 DEBUG (MainThread) [custom_components.tapo_control] Setting up onvif...
2023-11-08 11:25:41.205 DEBUG (MainThread) [custom_components.tapo_control] setupEvents - entry
2023-11-08 11:25:41.206 DEBUG (MainThread) [custom_components.tapo_control] Detected base_url schema: http
2023-11-08 11:25:41.207 DEBUG (MainThread) [custom_components.tapo_control] Detected base_url schema: http
2023-11-08 11:25:41.207 DEBUG (MainThread) [custom_components.tapo_control] Using HTTPS: False
2023-11-08 11:25:41.207 DEBUG (MainThread) [custom_components.tapo_control] Webhook enabled: True
2023-11-08 11:25:41.208 DEBUG (MainThread) [custom_components.tapo_control] Using Webhooks: True
2023-11-08 11:25:41.208 DEBUG (MainThread) [custom_components.tapo_control] Setting up events...
2023-11-08 11:25:41.208 DEBUG (MainThread) [custom_components.tapo_control] WSPullPointSupport: True
2023-11-08 11:25:41.592 DEBUG (MainThread) [custom_components.tapo_control] Events started.
2023-11-08 11:25:41.592 DEBUG (MainThread) [custom_components.tapo_control] Creating binary sensor entity.
2023-11-08 11:25:41.593 DEBUG (MainThread) [custom_components.tapo_control] Binary sensor creation for motion has been forwarded to component.
2023-11-08 11:26:05.320 DEBUG (MainThread) [custom_components.tapo_control] [172.16.32.227] Opened Tapo options.
2023-11-08 11:26:07.574 DEBUG (MainThread) [custom_components.tapo_control] [172.16.32.227] Opened Tapo options.
2023-11-08 11:26:07.575 DEBUG (MainThread) [custom_components.tapo_control] [172.16.32.227] Verifying updated data.
2023-11-08 11:26:07.575 DEBUG (MainThread) [custom_components.tapo_control] [172.16.32.227] Skipping test of cloud password for control as it was not updated.
2023-11-08 11:26:07.575 DEBUG (MainThread) [custom_components.tapo_control] [172.16.32.227] Skipping test of RTSP stream as Camera Account is the same.
2023-11-08 11:26:07.576 DEBUG (MainThread) [custom_components.tapo_control] [172.16.32.227] Skipping test of control using Camera Account since cloud password is provided.
2023-11-08 11:26:07.576 DEBUG (MainThread) [custom_components.tapo_control] [172.16.32.227] Skipping removal of devices since IP address did not change.
2023-11-08 11:26:07.576 DEBUG (MainThread) [custom_components.tapo_control] [172.16.32.227] Updating entry.
2023-11-08 11:26:07.576 DEBUG (MainThread) [custom_components.tapo_control] [172.16.32.227] Skipping reload of entry.
2023-11-08 11:26:11.535 DEBUG (MainThread) [custom_components.tapo_control] Events started.
2023-11-08 11:26:11.733 ERROR (MainThread) [homeassistant.config_entries] Error unloading entry 172.16.32.227 for binary_sensor
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 557, in async_unload
    result = await component.async_unload_entry(hass, self)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/binary_sensor/__init__.py", line 175, in async_unload_entry
    return await component.async_unload_entry(entry)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 202, in async_unload_entry
    raise ValueError("Config entry was never loaded!")
ValueError: Config entry was never loaded!
JurajNyiri commented 8 months ago

Good job providing replication steps that are valid, next time lets skip the attitude and lets take the time to read what is asked of us. Reloading integration leads to this error 100% of time, compared to the initial replication steps in OP.

Looking into this, it would be good to include it in https://github.com/JurajNyiri/HomeAssistant-Tapo-Control/pull/449 since reauth does reload integration as well.

codyc1515 commented 8 months ago

Thank you. Just trying to help here with making the integration better. None of these are serious blocking issues, so i apologize if it came across as spamming with these. I don't always have the time to report them right away, so when I log them there can be a few at once. Hope you can understand and I appreciate the work you've done here 😄

JurajNyiri commented 8 months ago

I do appreciate the help. I apologize if I came across as frustrated. There has been recently a lot of users reporting false positives due to new firmware and unfortunately most of the users do not care to read or do research before opening new issues/comments with no detail at all. Just another day of open source developer :-)

JurajNyiri commented 8 months ago

Fixed in next release, thank you!

marco-calautti commented 3 months ago

Sorry, but I still get the same issue with the latest version of the integration. My camera is a C200. Every time I restart HAS, the integration throws the ValueError exception and HAS becomes unreachable.