# Bug report
After migrating to the new version of Appdeamon, I get the error a…ttached, appdeamon crashes, see log attached, see https://github.com/AppDaemon/appdaemon/issues/2286
## Description
Add a description of the bug. Detail the expected behaviour in contrast with the behaviour you're observing.
## Additional information
ControllerX installed as HACS component
CircularDependency: Visited [...] already, but cx_core.type.switch_controller depends on {'cx_const', 'cx_core.type_controller', 'cx_core.controller'}
This seems to be a structural import cycle in cx_core, which is now explicitly detected by AppDaemon’s new dependency graph logic.
Steps to reproduce:
Use AppDaemon 4.5.2
Install ControllerX 4.29 via HACS
Configure basic ControllerX apps in apps.yaml
Workarounds tried:
Added disable: true dummy apps for all cx_devices.* modules
AppDaemon still crashes due to internal cx_core cycle
Downgrade to AppDaemon 4.4.4 works fine
Expected:
ControllerX should be structured in a way that does not lead to circular import chains detectable by AppDaemon >= 4.5.
Request:
Can you consider refactoring or deferring imports in the relevant modules (like switch_controller, controller, type_controller) to break the dependency loop?
## AppDaemon app configuration
```
apps.yaml:
cx_devices___init___dummy:
module: cx_devices.__init__
class: Dummy
disable: true
cx_devices_adeo_dummy:
module: cx_devices.adeo
class: Dummy
disable: true
cx_devices_aqara_dummy:
module: cx_devices.aqara
class: Dummy
disable: true
cx_devices_aurora_dummy:
module: cx_devices.aurora
class: Dummy
disable: true
cx_devices_homematic_dummy:
module: cx_devices.homematic
class: Dummy
disable: true
cx_devices_ikea_dummy:
module: cx_devices.ikea
class: Dummy
disable: true
cx_devices_legrand_dummy:
module: cx_devices.legrand
class: Dummy
disable: true
cx_devices_linkind_dummy:
module: cx_devices.linkind
class: Dummy
disable: true
cx_devices_livarno_dummy:
module: cx_devices.livarno
class: Dummy
disable: true
cx_devices_lutron_dummy:
module: cx_devices.lutron
class: Dummy
disable: true
cx_devices_muller_licht_dummy:
module: cx_devices.muller_licht
class: Dummy
disable: true
cx_devices_osram_dummy:
module: cx_devices.osram
class: Dummy
disable: true
cx_devices_philips_dummy:
module: cx_devices.philips
class: Dummy
disable: true
cx_devices_prolight_dummy:
module: cx_devices.prolight
class: Dummy
disable: true
cx_devices_rgb_genie_dummy:
module: cx_devices.rgb_genie
class: Dummy
disable: true
cx_devices_robb_dummy:
module: cx_devices.robb
class: Dummy
disable: true
cx_devices_sengled_dummy:
module: cx_devices.sengled
class: Dummy
disable: true
cx_devices_shelly_dummy:
module: cx_devices.shelly
class: Dummy
disable: true
cx_devices_smartkontakten_dummy:
module: cx_devices.smartkontakten
class: Dummy
disable: true
cx_devices_smartthings_dummy:
module: cx_devices.smartthings
class: Dummy
disable: true
cx_devices_sonoff_dummy:
module: cx_devices.sonoff
class: Dummy
disable: true
cx_devices_tasmota_dummy:
module: cx_devices.tasmota
class: Dummy
disable: true
cx_devices_terncy_dummy:
module: cx_devices.terncy
class: Dummy
disable: true
cx_devices_trust_dummy:
module: cx_devices.trust
class: Dummy
disable: true
cx_devices_tuya_dummy:
module: cx_devices.tuya
class: Dummy
disable: true
nachttisch_links:
module: controllerx
class: E1743Controller
integration: mqtt
controller: zigbee2mqtt/DIM-Nachttisch-links/action
light: light.hue_color_lamp_1
nachttisch_rechts:
module: controllerx
class: E1743Controller
integration: mqtt
controller: zigbee2mqtt/DIM-Nachttisch-rechts/action
light: light.schlafzimmer_nachttisch_rechts
wohnzimmer_dim:
module: controllerx
class: E1743Controller
integration: mqtt
controller: zigbee2mqtt/DIM-Wohnzimmer/action
light: light.wohnzimmer_decke
flur_dim:
module: controllerx
class: E1743Controller
integration: mqtt
controller: zigbee2mqtt/DIM-Flur3/action
light: light.hue_flur_gruppe
merge_mapping:
"on":
- scene: scene.flur_tagszene
kueche_dim:
module: controllerx
class: E1743Controller
integration: mqtt
controller: zigbee2mqtt/DIM-Kueche/action
light: light.unterschranke_kuche
flur_dim2:
module: controllerx
class: E2002LightController
integration: mqtt
controller: zigbee2mqtt/DIM-Flur2/action
light: light.hue_flur_gruppe
merge_mapping:
"on":
- scene: scene.flur_tagszene
esszimmer_dim:
module: controllerx
class: E1743CoverController
integration: mqtt
controller: zigbee2mqtt/DIM-Esszimmer/action
cover: cover.esszimmer
wohnzimmer_dim_vorhang:
module: controllerx
class: E1743CoverController
integration: mqtt
controller: zigbee2mqtt/DIM-Wohnzimmer-Vorhang/action
cover: cover.wohnzimmer_fenster
```
## Logs
```
2025-05-28 08:21:31.989236 INFO AppDaemon: ------------------------------------------------------------
2025-05-28 08:21:31.989577 INFO AppDaemon: AppDaemon Version 4.5.2 starting
2025-05-28 08:21:31.989670 INFO AppDaemon: Additional version info: dev
2025-05-28 08:21:31.989732 INFO AppDaemon: ------------------------------------------------------------
2025-05-28 08:21:31.989815 INFO AppDaemon: Python version is 3.12.10
2025-05-28 08:21:31.990037 INFO AppDaemon: Configuration read from: /conf/appdaemon.yaml
2025-05-28 08:21:31.990204 INFO AppDaemon: Added log: AppDaemon
2025-05-28 08:21:31.990283 INFO AppDaemon: Added log: Error
2025-05-28 08:21:31.990367 INFO AppDaemon: Added log: Access
2025-05-28 08:21:31.990446 INFO AppDaemon: Added log: Diag
2025-05-28 08:21:31.991086 INFO AppDaemon: Using /conf/apps as app_dir
2025-05-28 08:21:31.991996 INFO AppDaemon: Loading Plugin HASS using class HassPlugin from module appdaemon.plugins.hass.hassplugin
2025-05-28 08:21:31.992225 INFO HASS: HASS Plugin initialization complete
2025-05-28 08:21:31.992421 INFO AppDaemon: Loading Plugin MQTT using class MqttPlugin from module appdaemon.plugins.mqtt.mqttplugin
2025-05-28 08:21:31.992579 INFO MQTT: MQTT Plugin Initializing
2025-05-28 08:21:31.992682 INFO MQTT: Using 'appdaemon_mqtt_client/status' as birth topic with payload 'online'
2025-05-28 08:21:31.992772 INFO MQTT: Using 'appdaemon_mqtt_client/status' as will topic with payload 'offline'
2025-05-28 08:21:31.996831 INFO AppDaemon: Initializing HTTP
2025-05-28 08:21:31.996995 INFO AppDaemon: Using 'ws' for event stream
2025-05-28 08:21:31.997249 INFO AppDaemon: HTTP Listening on port 5050
2025-05-28 08:21:31.999338 INFO AppDaemon: Starting API
2025-05-28 08:21:32.000499 INFO AppDaemon: Starting Admin Interface
2025-05-28 08:21:32.000654 INFO AppDaemon: Starting Dashboards
2025-05-28 08:21:32.009564 INFO HASS: Connected to Home Assistant 2025.5.3 with aiohttp websocket
2025-05-28 08:21:32.010281 INFO HASS: Authenticated to Home Assistant 2025.5.3
2025-05-28 08:21:32.011257 INFO HASS: Waiting for Home Assistant to start
2025-05-28 08:21:32.011583 INFO MQTT: Connected to MQTT broker at URL 192.168.1.191:1883 with paho-mqtt
2025-05-28 08:21:32.017891 INFO MQTT: MQTT Plugin initialization complete
2025-05-28 08:21:32.050830 INFO AppDaemon: Starting Apps with 8 workers and 8 pins
2025-05-28 08:21:32.054465 INFO AppDaemon: Running on port 5050
2025-05-28 08:21:32.054626 INFO AppDaemon: Waiting for plugins to be ready
2025-05-28 08:21:32.056067 INFO AppDaemon: All plugins ready
2025-05-28 08:21:32.057453 INFO AppDaemon: Scheduler running in realtime
2025-05-28 08:21:32.064480 WARNING HASS: Disconnected from Home Assistant, retrying in 5 seconds
2025-05-28 08:21:32.269105 INFO MQTT: Unable to decode MQTT message from topic home/OMG_lilygo_rtl_433_ESP_FSK/RTL_433toMQTT/Fineoffset-WH51/0dbd49, ignoring message
2025-05-28 08:21:32.269341 ERROR MQTT: Unable to decode MQTT message from topic home/OMG_lilygo_rtl_433_ESP_FSK/RTL_433toMQTT/Fineoffset-WH51/0dbd49, with error: 'utf-8' codec can't decode byte 0xd6 in position 247: invalid continuation byte
2025-05-28 08:21:32.511604 INFO AppDaemon: New app config: nachttisch_links
2025-05-28 08:21:32.511772 INFO AppDaemon: New app config: nachttisch_rechts
2025-05-28 08:21:32.511897 INFO AppDaemon: New app config: wohnzimmer_dim
2025-05-28 08:21:32.511989 INFO AppDaemon: New app config: flur_dim
2025-05-28 08:21:32.512088 INFO AppDaemon: New app config: kueche_dim
2025-05-28 08:21:32.512187 INFO AppDaemon: New app config: flur_dim2
2025-05-28 08:21:32.512271 INFO AppDaemon: New app config: esszimmer_dim
2025-05-28 08:21:32.512392 INFO AppDaemon: New app config: wohnzimmer_dim_vorhang
2025-05-28 08:21:32.668853 WARNING AppDaemon: ------------------------------------------------------------
2025-05-28 08:21:32.669062 WARNING AppDaemon: Unexpected error during run()
2025-05-28 08:21:32.669183 WARNING AppDaemon: ------------------------------------------------------------
Traceback (most recent call last):
File "/usr/local/lib/python3.12/site-packages/appdaemon/__main__.py", line 157, in run
loop.run_until_complete(asyncio.gather(*pending))
File "/usr/local/lib/python3.12/asyncio/base_events.py", line 691, in run_until_complete
return future.result()
^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/appdaemon/utility_loop.py", line 144, in loop
await self.AD.app_management.check_app_updates(mode=UpdateMode.INIT)
File "/usr/local/lib/python3.12/site-packages/appdaemon/app_management.py", line 809, in check_app_updates
await self._import_modules(update_actions)
File "/usr/local/lib/python3.12/site-packages/appdaemon/app_management.py", line 1055, in _import_modules
load_order = self.dependency_manager.python_sort(modules)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/appdaemon/dependency_manager.py", line 210, in python_sort
order = [n for n in topo_sort(self.python_deps.dep_graph) if n in modules]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/appdaemon/dependency.py", line 261, in topo_sort
raise CircularDependency(f"Visited {visited} already, but {node} depends on {deps}")
appdaemon.dependency.CircularDependency: Visited ['cx_devices.sengled', 'cx_core', 'cx_core.type.z2m_light_controller', 'cx_const', 'collections.abc', 'typing', 'cx_core.controller', 'ast', 'appdaemon.adapi', 'time', 'cx_version', 'appdaemon.plugins.hass.hassapi', 'cx_core.action_type.base', 'abc', 'cx_core.integration', 'cx_helper', 'pkgutil', 'importlib', 'os', 'functools', 'appdaemon.plugins.mqtt.mqttapi', 'asyncio', 'cx_core.action_type', 'cx_core.action_type.delay_action_type', 'cx_core.action_type.call_service_action_type', 'cx_core.action_type.scene_action_type', 'cx_core.action_type.predefined_action_type', 'inspect', 're', 'collections', 'appdaemon.utils', 'cx_core.integration.z2m', 'json', 'cx_core.type_controller', 'cx_core.feature_support', 'cx_core.stepper', 'dataclasses', 'cx_core.type.cover_controller', 'cx_core.feature_support.cover', 'cx_core.type.media_player_controller', 'cx_core.stepper.index_loop_stepper', 'cx_core.stepper.stop_stepper', 'cx_core.feature_support.media_player', 'cx_core.release_hold_controller', 'cx_core.type.switch_controller', 'cx_core.type.light_controller', 'cx_core.stepper.bounce_stepper', 'cx_core.feature_support.light', 'cx_core.stepper.loop_stepper', 'cx_core.integration.deconz', 'cx_core.integration.zha', 'cx_core.color_helper'] already, but cx_devices.sengled depends on {'cx_core', 'cx_const'}
2025-05-28 08:21:32.671808 INFO AppDaemon: Previous message repeated 1 times
2025-05-28 08:21:32.671945 INFO AppDaemon: AppDaemon Exited
```
## Additional Context
Add any other context or screenshots about the bug here.