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

0.9.0.alpha.6 - swtich's entity gets re-created after restart #89

Open
scabana opened this issue Jan 3, 2024 · 1 comment
Open

0.9.0.alpha.6 - swtich's entity gets re-created after restart #89

scabana opened this issue Jan 3, 2024 · 1 comment

Comments

@scabana
Copy link

scabana commented Jan 3, 2024

Each time home assistant is restarted, each virtual switch gets re-created:

image

homeassistant@raspberrypi:~/.homeassistant $ cat virtual.yaml
version: 1
devices:
  Ender-3 Pro:
  - platform: switch
    name: ender_3_pro
  Lumiere Ender-3 Pro:
  - platform: switch
    name: lumiere_ender_3_pro
2024-01-03 15:01:28.793 DEBUG (MainThread) [custom_components.virtual] async setup {'group_name': 'imported', 'file_name': '/home/homeassistant/.homeassistant/virtual.yaml'}
2024-01-03 15:01:28.793 DEBUG (MainThread) [custom_components.virtual] creating new cfg
2024-01-03 15:01:28.793 DEBUG (MainThread) [custom_components.virtual.cfg] no meta data yet [Errno 2] No such file or directory: '/config/.storage/virtual.meta.json'
2024-01-03 15:01:28.796 DEBUG (MainThread) [custom_components.virtual.cfg] loaded-meta-data={}
2024-01-03 15:01:28.797 DEBUG (MainThread) [custom_components.virtual.cfg] loaded-devices={'Ender-3 Pro': [{'platform': 'switch', 'name': 'ender_3_pro'}], 'Lumiere Ender-3 Pro': [{'platform': 'switch', 'name': 'lumiere_ender_3_pro'}]}
2024-01-03 15:01:28.797 DEBUG (MainThread) [custom_components.virtual.cfg] creating ender_3_pro
2024-01-03 15:01:28.797 DEBUG (MainThread) [custom_components.virtual.cfg] added entity switch/{'name': 'ender_3_pro', 'entity_id': 'switch.ender_3_pro', 'unique_id': '57e03000-d7c2-44e0-a659-009639f3d433.virtual', 'device_id': 'Ender-3 Pro'}
2024-01-03 15:01:28.797 DEBUG (MainThread) [custom_components.virtual.cfg] creating lumiere_ender_3_pro
2024-01-03 15:01:28.798 DEBUG (MainThread) [custom_components.virtual.cfg] added entity switch/{'name': 'lumiere_ender_3_pro', 'entity_id': 'switch.lumiere_ender_3_pro', 'unique_id': '75da30cd-b17d-4de6-ba37-c5c0239c9654.virtual', 'device_id': 'Lumiere Ender-3 Pro'}
2024-01-03 15:01:28.798 DEBUG (MainThread) [custom_components.virtual.cfg] no meta data yet [Errno 2] No such file or directory: '/config/.storage/virtual.meta.json'
2024-01-03 15:01:28.798 DEBUG (MainThread) [custom_components.virtual.cfg] meta before {}
2024-01-03 15:01:28.798 DEBUG (MainThread) [custom_components.virtual.cfg] meta after {'imported': {'ender_3_pro': {'unique_id': '57e03000-d7c2-44e0-a659-009639f3d433.virtual', 'entity_id': 'switch.ender_3_pro'}, 'lumiere_ender_3_pro': {'unique_id': '75da30cd-b17d-4de6-ba37-c5c0239c9654.virtual', 'entity_id': 'switch.lumiere_ender_3_pro'}}}
2024-01-03 15:01:28.798 DEBUG (MainThread) [custom_components.virtual.cfg] couldn't save meta data [Errno 2] No such file or directory: '/config/.storage/virtual.meta.json'
2024-01-03 15:01:28.799 DEBUG (MainThread) [custom_components.virtual.cfg] meta-data={'ender_3_pro': {'unique_id': '57e03000-d7c2-44e0-a659-009639f3d433.virtual', 'entity_id': 'switch.ender_3_pro'}, 'lumiere_ender_3_pro': {'unique_id': '75da30cd-b17d-4de6-ba37-c5c0239c9654.virtual', 'entity_id': 'switch.lumiere_ender_3_pro'}}
2024-01-03 15:01:28.799 DEBUG (MainThread) [custom_components.virtual.cfg] devices=[{'device_id': 'Ender-3 Pro', 'name': 'Ender-3 Pro'}, {'device_id': 'Lumiere Ender-3 Pro', 'name': 'Lumiere Ender-3 Pro'}]
2024-01-03 15:01:28.799 DEBUG (MainThread) [custom_components.virtual.cfg] entities={'switch': [{'name': 'ender_3_pro', 'entity_id': 'switch.ender_3_pro', 'unique_id': '57e03000-d7c2-44e0-a659-009639f3d433.virtual', 'device_id': 'Ender-3 Pro'}, {'name': 'lumiere_ender_3_pro', 'entity_id': 'switch.lumiere_ender_3_pro', 'unique_id': '75da30cd-b17d-4de6-ba37-c5c0239c9654.virtual', 'device_id': 'Lumiere Ender-3 Pro'}]}
2024-01-03 15:01:28.799 DEBUG (MainThread) [custom_components.virtual.cfg] orphaned-entities={}
2024-01-03 15:01:28.799 DEBUG (MainThread) [custom_components.virtual] creating the devices
2024-01-03 15:01:28.799 DEBUG (MainThread) [custom_components.virtual] creating-device={'device_id': 'Ender-3 Pro', 'name': 'Ender-3 Pro'}
2024-01-03 15:01:28.799 DEBUG (MainThread) [custom_components.virtual] creating-device={'device_id': 'Lumiere Ender-3 Pro', 'name': 'Lumiere Ender-3 Pro'}
2024-01-03 15:01:28.800 DEBUG (MainThread) [custom_components.virtual] update hass data {'imported': {'entities': {'switch': [{'name': 'ender_3_pro', 'entity_id': 'switch.ender_3_pro', 'unique_id': '57e03000-d7c2-44e0-a659-009639f3d433.virtual', 'device_id': 'Ender-3 Pro'}, {'name': 'lumiere_ender_3_pro', 'entity_id': 'switch.lumiere_ender_3_pro', 'unique_id': '75da30cd-b17d-4de6-ba37-c5c0239c9654.virtual', 'device_id': 'Lumiere Ender-3 Pro'}]}, 'file_name': '/home/homeassistant/.homeassistant/virtual.yaml'}}
2024-01-03 15:01:32.630 INFO (MainThread) [homeassistant.components.switch] Setting up switch.virtual
2024-01-03 15:01:32.631 INFO (MainThread) [homeassistant.components.device_tracker] Setting up device_tracker.virtual
2024-01-03 15:01:32.632 DEBUG (MainThread) [custom_components.virtual.switch] setting up the entries...
2024-01-03 15:01:32.632 DEBUG (MainThread) [custom_components.virtual.entity] creating-virtual-switch={'name': 'ender_3_pro', 'entity_id': 'switch.ender_3_pro', 'unique_id': '57e03000-d7c2-44e0-a659-009639f3d433.virtual', 'device_id': 'Ender-3 Pro', 'initial_value': 'off', 'persistent': True, 'initial_availability': True}
2024-01-03 15:01:32.632 DEBUG (MainThread) [custom_components.virtual.entity] setting up device info
2024-01-03 15:01:32.632 INFO (MainThread) [custom_components.virtual.entity] VirtualEntity ender_3_pro created
2024-01-03 15:01:32.632 INFO (MainThread) [custom_components.virtual.switch] VirtualSwitch: ender_3_pro created
2024-01-03 15:01:32.632 DEBUG (MainThread) [custom_components.virtual.entity] creating-virtual-switch={'name': 'lumiere_ender_3_pro', 'entity_id': 'switch.lumiere_ender_3_pro', 'unique_id': '75da30cd-b17d-4de6-ba37-c5c0239c9654.virtual', 'device_id': 'Lumiere Ender-3 Pro', 'initial_value': 'off', 'persistent': True, 'initial_availability': True}
2024-01-03 15:01:32.632 DEBUG (MainThread) [custom_components.virtual.entity] setting up device info
2024-01-03 15:01:32.632 INFO (MainThread) [custom_components.virtual.entity] VirtualEntity lumiere_ender_3_pro created
2024-01-03 15:01:32.632 INFO (MainThread) [custom_components.virtual.switch] VirtualSwitch: lumiere_ender_3_pro created
2024-01-03 15:01:32.635 INFO (MainThread) [homeassistant.components.todo] Setting up todo.shopping_list
2024-01-03 15:01:32.636 DEBUG (MainThread) [custom_components.virtual.device_tracker] setting up the device_tracker entries...
2024-01-03 15:01:32.636 DEBUG (MainThread) [custom_components.virtual.device_tracker] installing handlers
2024-01-03 15:01:32.638 INFO (MainThread) [homeassistant.components.tts] Setting up tts.google_translate
2024-01-03 15:01:32.639 INFO (MainThread) [homeassistant.helpers.entity_registry] Registered new switch.virtual entity: switch.ender_3_pro_3
2024-01-03 15:01:32.639 INFO (MainThread) [custom_components.virtual.entity] VirtualEntity 57e03000-d7c2-44e0-a659-009639f3d433.virtual: creating initial state
2024-01-03 15:01:32.640 INFO (MainThread) [homeassistant.helpers.entity_registry] Registered new switch.virtual entity: switch.lumiere_ender_3_pro_3
2024-01-03 15:01:32.640 INFO (MainThread) [custom_components.virtual.entity] VirtualEntity 75da30cd-b17d-4de6-ba37-c5c0239c9654.virtual: creating initial state

While writing the bug, I saw this: 2024-01-03 15:01:28.798 DEBUG (MainThread) [custom_components.virtual.cfg] no meta data yet [Errno 2] No such file or directory: '/config/.storage/virtual.meta.json', took a look at the code and the path is hard-coded here. When installing Home Assistant using this setup, the .storage folder ends up in /home/homeassistant/.homeassistant/.storage not at the root. I added the necessary folder and file /config/.storage/virtual.meta.json and now the entities don't get re-created. Seems like HACS automatically saves it to the right location using this store.

@twrecked
Copy link
Owner

twrecked commented Feb 4, 2024

Sorry about this, I was on holiday and missed this one. It should be fixed now, can you try the latest build it should use the correct directory.

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