diff --git a/pyControl4/director.py b/pyControl4/director.py index fce307d..b4f64c4 100644 --- a/pyControl4/director.py +++ b/pyControl4/director.py @@ -228,6 +228,22 @@ async def get_item_commands(self, item_id: int) -> list[dict[str, Any]]: result: list[dict[str, Any]] = json.loads(data) return result + async def get_browse_items(self, path: str) -> list[dict[str, Any]]: + """Returns browseable media items for the specified Control4 browse path. + + Parameters: + `path` - The browse API path from a command's value source. + """ + data = await self.send_get_request(path) + payload: Any = json.loads(data) + if isinstance(payload, list): + return [item for item in payload if isinstance(item, dict)] + if isinstance(payload, dict): + visible = payload.get("visible") + if isinstance(visible, list): + return [item for item in visible if isinstance(item, dict)] + return [] + async def get_item_network(self, item_id: int) -> list[dict[str, Any]]: """Returns the network information for the specified item. diff --git a/pyControl4/room.py b/pyControl4/room.py index e5af9c1..68ebaf4 100644 --- a/pyControl4/room.py +++ b/pyControl4/room.py @@ -140,6 +140,36 @@ async def set_stop(self) -> None: {}, ) + async def get_commands(self) -> list[dict[str, Any]]: + """Returns the commands available for this room.""" + return await self.director.get_item_commands(self.item_id) + + async def get_browse_items(self, path: str) -> list[dict[str, Any]]: + """Returns browseable media items for the specified room browse path. + + Parameters: + `path` - The Control4 API path from a command parameter's value source. + """ + return await self.director.get_browse_items(path) + + async def play_browse_item( + self, + command: str, + params: dict[str, Any], + ) -> str: + """Sends a browse selection command to this room. + + Parameters: + `command` - The Control4 command to send. + + `params` - The command parameters, typically including the selected media ID. + """ + return await self.director.send_post_request( + f"/api/v1/items/{self.item_id}/commands", + command, + params, + ) + async def get_audio_devices(self) -> dict[str, Any]: """ Note: As tested in OS 3.2.3 this doesn't work, but may work in previous versions