File tree Expand file tree Collapse file tree 2 files changed +29
-0
lines changed
Expand file tree Collapse file tree 2 files changed +29
-0
lines changed Original file line number Diff line number Diff line change 44from switchbot .client import SwitchBotClient
55from switchbot .devices import Device
66from switchbot .remotes import Remote
7+ from switchbot .scene import Scene
78
89__version__ = "2.3.0"
910
@@ -41,3 +42,13 @@ def remote(self, id: str) -> Remote:
4142 if remote .id == id :
4243 return remote
4344 raise ValueError (f"Unknown remote { id } " )
45+
46+ def scenes (self ) -> List [Scene ]:
47+ response = self .client .get ("scenes" )
48+ return [Scene (client = self .client , id = scene ["scene_id" ], ** scene ) for scene in response ["body" ]]
49+
50+ def scene (self , id : str ) -> Scene :
51+ for scene in self .scenes ():
52+ if scene .id == id :
53+ return scene
54+ raise ValueError (f"Unknown scene { id } " )
Original file line number Diff line number Diff line change 1+ from __future__ import annotations
2+
3+ from switchbot .client import SwitchBotClient
4+
5+
6+ class Scene :
7+ def __init__ (self , client : SwitchBotClient , id : str , ** extra ):
8+ self .client = client
9+ self .id : str = id
10+ self .name : str = extra .get ("scene_name" )
11+
12+ def execute (self ):
13+ self .client .post (f"scenes/{ self .id } /execute" )
14+
15+ def __repr__ (self ):
16+ name = "Scene" if self .name is None else self .name
17+ name = name .replace (" " , "" )
18+ return f"{ name } (id={ self .id } )"
You can’t perform that action at this time.
0 commit comments