Skip to content

Commit

Permalink
Added scene trigger/complete/undo timestamp support. Added support fo…
Browse files Browse the repository at this point in the history
…r scenes/<scene_id>/undo operation.
  • Loading branch information
fpb committed Oct 26, 2023
1 parent 9269da2 commit f582441
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
11 changes: 10 additions & 1 deletion src/dirigera/devices/scene.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,24 @@ class Scene:
scene_id: str
name: str
icon: str
last_completed: str
last_triggered: str
last_undo: str

def trigger(self) -> None:
self.dirigera_client.post(route=f"/scenes/{self.scene_id}/trigger")

def undo(self) -> None:
self.dirigera_client.post(route=f"/scenes/{self.scene_id}/undo")


def dict_to_scene(data: Dict[str, Any], dirigera_client: AbstractSmartHomeHub) -> Scene:
return Scene(
dirigera_client=dirigera_client,
scene_id=data["id"],
name=data["info"]["name"],
icon=data["info"]["icon"]
icon=data["info"]["icon"],
last_completed=data["lastCompleted"],
last_triggered=data["lastTriggered"],
last_undo=data["lastUndo"]
)
14 changes: 11 additions & 3 deletions tests/test_scenes.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
TEST_ID = "00000000-0000-0000-0000-000000000000"
TEST_NAME = "NAME"
TEST_ICON = "ICON"

TEST_LAST_COMPLETED = "2023-10-26T10:39:39.176Z"
TEST_LAST_TRIGGERED = "2023-10-26T10:39:39.176Z"
TEST_LAST_UNDO = "2023-10-26T10:42:14.847Z"

@pytest.fixture(name="fake_client")
def fixture_fake_client():
Expand All @@ -18,7 +20,10 @@ def fixture_scene(fake_client: FakeDirigeraHub):
dirigera_client=fake_client,
scene_id=TEST_ID,
name=TEST_NAME,
icon=TEST_ICON
icon=TEST_ICON,
last_completed=TEST_LAST_COMPLETED,
last_triggered=TEST_LAST_TRIGGERED,
last_undo=TEST_LAST_UNDO
)


Expand All @@ -34,7 +39,10 @@ def test_dict_to_scene(fake_client):
"info": {
"name": TEST_NAME,
"icon": TEST_ICON
}
},
"lastCompleted": TEST_LAST_COMPLETED,
"lastTriggered": TEST_LAST_TRIGGERED,
"lastUndo": TEST_LAST_UNDO
}

scene = dict_to_scene(data, fake_client)
Expand Down

0 comments on commit f582441

Please sign in to comment.