Skip to content

Commit c8a5a4d

Browse files
authored
Merge pull request #67 from tuya/query-rooms-by-device
feat(home): add query_room_by_device to query a device's room
2 parents bf59601 + 5603978 commit c8a5a4d

4 files changed

Lines changed: 26 additions & 2 deletions

File tree

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ With diversified devices and industries, Tuya IoT Development Platform opens bas
3232
- send_commands
3333
- HomeRepository
3434
- query_homes
35+
- query_room_by_device
3536
- SceneRepository
3637
- query_scenes
3738
- trigger_scene
@@ -58,6 +59,7 @@ With diversified devices and industries, Tuya IoT Development Platform opens bas
5859
| 0.2.8 | Add report_type to device status #51 |
5960
| 0.2.9 | Fix incorrect type hint in DeviceFunction #44 <br/>Add pre-commit workflow #46 <br/>Apply ruff format #47 |
6061
| 0.2.10 | Make enum mapping lookups case-insensitive #55 <br/>Add ruff-check to pre-commit #56 <br/>Add ApiRequestException for failed API responses #58 <br/>Fix 0.2.9 changelog formatting #59 |
62+
| 0.2.11 | Add query_room_by_device to query the room a device belongs to |
6163

6264
## Installation
6365

tuya_sharing/home.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@ def __init__(self, id: str, name: str):
99
self.name = name
1010

1111

12+
class SmartLifeRoom:
13+
def __init__(self, id: str, name: str, display_order: int = 0):
14+
self.id = id
15+
self.name = name
16+
self.display_order = display_order
17+
18+
1219
class HomeRepository:
1320
def __init__(self, customer_api: CustomerApi):
1421
self.api = customer_api
@@ -24,3 +31,15 @@ def query_homes(self) -> list[SmartLifeHome]:
2431
return _homes
2532

2633
return []
34+
35+
def query_room_by_device(self, device_id: str) -> SmartLifeRoom | None:
36+
response = self.api.get(f"/v1.0/cloud/life/ha/{device_id}/room")
37+
38+
if response.get("success", False):
39+
room = response.get("result")
40+
if room:
41+
return SmartLifeRoom(
42+
str(room["id"]), room["name"], room.get("displayOrder", 0)
43+
)
44+
45+
return None

tuya_sharing/manager.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
from .customerapi import CustomerApi, CustomerTokenInfo, SharingTokenListener
66
from .device import DeviceRepository, CustomerDevice
7-
from .home import HomeRepository, SmartLifeHome
7+
from .home import HomeRepository, SmartLifeHome, SmartLifeRoom
88
from .scenes import SceneRepository
99
from .user import UserRepository
1010
from .strategy import strategy
@@ -98,6 +98,9 @@ def refresh_mq(self):
9898
def send_commands(self, device_id: str, commands: list[dict[str, Any]]):
9999
return self.device_repository.send_commands(device_id, commands)
100100

101+
def query_room_by_device(self, device_id: str) -> Optional[SmartLifeRoom]:
102+
return self.home_repository.query_room_by_device(device_id)
103+
101104
def get_device_stream_allocate(
102105
self, device_id: str, stream_type: Literal["flv", "hls", "rtmp", "rtsp"]
103106
) -> Optional[str]:

tuya_sharing/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
"""smartlife device sharing sdk version."""
22

3-
VERSION = "0.2.10"
3+
VERSION = "0.2.11"

0 commit comments

Comments
 (0)