Skip to content

Commit

Permalink
Add unwatch_all to Observable
Browse files Browse the repository at this point in the history
Clear old facade from the system
  • Loading branch information
gazoodle committed Apr 5, 2022
1 parent 35e31c3 commit 480c60c
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/geckolib/async_spa.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,7 @@ async def disconnect(self) -> None:
self._protocol.disconnect()
self._protocol = None
self._transport = None
self.unwatch_all()

@property
def isopen(self) -> bool:
Expand Down
1 change: 1 addition & 0 deletions src/geckolib/async_spa_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ async def async_reset(self) -> None:
"""Reset the spa manager"""
self._spa_descriptors = None
if self._facade is not None:
await self._facade.disconnect()
self._facade = None
if self._spa is not None:
await self._spa.disconnect()
Expand Down
6 changes: 6 additions & 0 deletions src/geckolib/automation/async_facade.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ def __init__(self, spa: GeckoAsyncSpa, taskman: AsyncTasks, **kwargs: str) -> No
self._taskman.add_task(self._facade_update(), "Facade update", "FACADE")
self._ready = False

async def disconnect(self) -> None:
_LOGGER.debug("Disconnect facade")
self._taskman.cancel_key_tasks("FACADE")
for device in self.all_automation_devices:
device.unwatch_all()

def _on_config_device_change(self, *args) -> None:
active_mode = False
for device in self.all_config_change_devices:
Expand Down
1 change: 1 addition & 0 deletions src/geckolib/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ class _GeckoIdleConfig(_GeckoConfig):

def set_config_mode(active: bool) -> None:
"""Set config mode to active (true) or idle (false)."""
_LOGGER.debug("set_config_mode: %s", active)
new_config = _GeckoActiveConfig() if active else _GeckoIdleConfig()
for member in CONFIG_MEMBERS:
setattr(GeckoConfig, member, getattr(new_config, member))
Expand Down
5 changes: 5 additions & 0 deletions src/geckolib/driver/observable.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ def unwatch(self, observer: Callable[[Any, Any, Any], None]) -> None:
"""Remove an observer to this observable class"""
self._observers.remove(observer)

def unwatch_all(self):
"""Remove all observers on this observable class"""
_LOGGER.debug("Remove all observers from %s", self)
self._observers.clear()

def _on_change(
self, sender: Any = None, old_value: Any = None, new_value: Any = None
) -> None:
Expand Down

0 comments on commit 480c60c

Please sign in to comment.