Skip to content

Commit

Permalink
Add inclusion state changed controller event (#1114)
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinHjelmare authored Nov 11, 2024
1 parent f79f4f1 commit b4fc851
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
5 changes: 5 additions & 0 deletions test/model/test_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -2254,6 +2254,11 @@ async def test_additional_events(controller: Controller) -> None:
{"source": "controller", "event": "inclusion started", "strategy": 0},
)
controller.receive_event(event)
event = Event(
"inclusion state changed",
{"source": "controller", "event": "inclusion state changed", "state": 1},
)
controller.receive_event(event)
event = Event(
"inclusion stopped", {"source": "controller", "event": "inclusion stopped"}
)
Expand Down
3 changes: 3 additions & 0 deletions zwave_js_server/model/controller/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -901,6 +901,9 @@ def handle_exclusion_failed(self, event: Event) -> None:
def handle_inclusion_started(self, event: Event) -> None:
"""Process an inclusion started event."""

def handle_inclusion_state_changed(self, event: Event) -> None:
"""Process an inclusion state changed event."""

def handle_exclusion_started(self, event: Event) -> None:
"""Process an exclusion started event."""

Expand Down
19 changes: 18 additions & 1 deletion zwave_js_server/model/controller/event_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from typing import Literal, TypedDict

from ...const import InclusionStrategy, RemoveNodeReason
from ...const import InclusionState, InclusionStrategy, RemoveNodeReason
from ...event import BaseEventModel
from ..node.data_model import FoundNodeDataType, NodeDataType
from .firmware import (
Expand Down Expand Up @@ -154,6 +154,22 @@ def from_dict(cls, data: dict) -> InclusionStartedEventModel:
)


class InclusionStateChangedEventModel(BaseControllerEventModel):
"""Model for `inclusion state changed` event data."""

event: Literal["inclusion state changed"]
state: InclusionState

@classmethod
def from_dict(cls, data: dict) -> InclusionStateChangedEventModel:
"""Initialize from dict."""
return cls(
source=data["source"],
event=data["event"],
state=data["state"],
)


class InclusionStoppedEventModel(BaseControllerEventModel):
"""Model for `inclusion stopped` event data."""

Expand Down Expand Up @@ -336,6 +352,7 @@ def from_dict(cls, data: dict) -> StatusChangedEventModel:
"inclusion aborted": InclusionAbortedEventModel,
"inclusion failed": InclusionFailedEventModel,
"inclusion started": InclusionStartedEventModel,
"inclusion state changed": InclusionStateChangedEventModel,
"inclusion stopped": InclusionStoppedEventModel,
"node added": NodeAddedEventModel,
"node found": NodeFoundEventModel,
Expand Down

0 comments on commit b4fc851

Please sign in to comment.