From ac52dee4e7dc805b04d20e4affbc21bf4176a016 Mon Sep 17 00:00:00 2001 From: Xavier Moreno Date: Sun, 24 Apr 2022 18:32:16 +0200 Subject: [PATCH] fix(homematic): registered controller set was not initialized on constructor related to #421 --- apps/controllerx/cx_core/integration/homematic.py | 15 +++++++++++---- .../cx_core/integration/homematic_test.py | 6 +++--- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/apps/controllerx/cx_core/integration/homematic.py b/apps/controllerx/cx_core/integration/homematic.py index 0cb6eb59..10077936 100644 --- a/apps/controllerx/cx_core/integration/homematic.py +++ b/apps/controllerx/cx_core/integration/homematic.py @@ -1,19 +1,26 @@ -from typing import Any, Dict, Optional, Set +from typing import TYPE_CHECKING, Any, Dict, Optional, Set from appdaemon.plugins.hass.hassapi import Hass from cx_const import DefaultActionsMapping from cx_core.integration import EventData, Integration +if TYPE_CHECKING: + from cx_core.controller import Controller + class HomematicIntegration(Integration): name = "homematic" - _registererd_controller_ids: Set[str] = set() + _registered_controller_ids: Set[str] + + def __init__(self, controller: "Controller", kwargs: Dict[str, Any]): + self._registered_controller_ids = set() + super().__init__(controller, kwargs) def get_default_actions_mapping(self) -> Optional[DefaultActionsMapping]: return self.controller.get_homematic_actions_mapping() async def listen_changes(self, controller_id: str) -> None: - self._registererd_controller_ids.add(controller_id) + self._registered_controller_ids.add(controller_id) await Hass.listen_event( self.controller, self.event_callback, "homematic.keypress" ) @@ -21,7 +28,7 @@ async def listen_changes(self, controller_id: str) -> None: async def event_callback( self, event_name: str, data: EventData, kwargs: Dict[str, Any] ) -> None: - if data["name"] not in self._registererd_controller_ids: + if data["name"] not in self._registered_controller_ids: return param = data["param"] channel = data["channel"] diff --git a/tests/unit_tests/cx_core/integration/homematic_test.py b/tests/unit_tests/cx_core/integration/homematic_test.py index 9c58111c..367cab7b 100644 --- a/tests/unit_tests/cx_core/integration/homematic_test.py +++ b/tests/unit_tests/cx_core/integration/homematic_test.py @@ -38,7 +38,7 @@ async def test_callback( ) -> None: handle_action_patch = mocker.patch.object(fake_controller, "handle_action") integration = HomematicIntegration(fake_controller, {}) - integration._registererd_controller_ids = registered_controllers + integration._registered_controller_ids = registered_controllers await integration.event_callback("test", data, {}) @@ -56,11 +56,11 @@ async def test_listen_changes( controller_id = "controller_id" listen_event_mock = mocker.patch.object(Hass, "listen_event") integration = HomematicIntegration(fake_controller, {}) - assert integration._registererd_controller_ids == set() + assert integration._registered_controller_ids == set() await integration.listen_changes(controller_id) listen_event_mock.assert_called_once_with( fake_controller, integration.event_callback, "homematic.keypress" ) - assert integration._registererd_controller_ids == {controller_id} + assert integration._registered_controller_ids == {controller_id}