-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Room Media API Calls #21
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
f224e95
Add Room Media API Calls
kdkavanagh 0cc37b9
Seperate Volume and Mute functions
nalin29 04ae51a
Documentation for getUIConfiguration
nalin29 7cc2cd3
delete invalid API calls
nalin29 6bf96c9
include getVideo/AudioDevices with comment
nalin29 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
class C4Entity: | ||
def __init__(self, C4Director, item_id): | ||
"""Creates a Control4 object. | ||
|
||
Parameters: | ||
`C4Director` - A `pyControl4.director.C4Director` object that corresponds to the Control4 Director that the device is connected to. | ||
|
||
`item_id` - The Control4 item ID. | ||
""" | ||
self.director = C4Director | ||
self.item_id = int(item_id) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,154 @@ | ||
"""Controls Control4 Room devices. | ||
""" | ||
|
||
|
||
from pyControl4 import C4Entity | ||
|
||
|
||
class C4Room(C4Entity): | ||
""" | ||
A media-oriented view of a Control4 Room, supporting items of type="room" | ||
""" | ||
|
||
async def isRoomHidden(self) -> bool: | ||
"""Returns True if the room is hidden from the end-user""" | ||
value = await self.director.getItemVariableValue(self.item_id, "ROOM_HIDDEN") | ||
return int(value) != 0 | ||
|
||
async def isOn(self) -> bool: | ||
"""Returns True/False if the room is "ON" from the director's perspective""" | ||
value = await self.director.getItemVariableValue(self.item_id, "POWER_STATE") | ||
return int(value) != 0 | ||
|
||
async def setRoomOff(self): | ||
"""Turn the room "OFF" """ | ||
await self.director.sendPostRequest( | ||
"/api/v1/items/{}/commands".format(self.item_id), | ||
"ROOM_OFF", | ||
{}, | ||
) | ||
|
||
async def _setSource(self, source_id: int, audio_only: bool): | ||
""" | ||
Sets the room source, turning on the room if necessary. | ||
If audio_only, only the current audio device is changed | ||
""" | ||
await self.director.sendPostRequest( | ||
f"/api/v1/items/{self.item_id}/commands", | ||
"SELECT_AUDIO_DEVICE" if audio_only else "SELECT_VIDEO_DEVICE", | ||
{"deviceid": source_id}, | ||
) | ||
|
||
async def setAudioSource(self, source_id: int): | ||
"""Sets the current audio source for the room""" | ||
await self._setSource(source_id, audio_only=True) | ||
|
||
async def setVideoAndAudioSource(self, source_id: int): | ||
"""Sets the current audio and video source for the room""" | ||
await self._setSource(source_id, audio_only=False) | ||
|
||
async def getVolume(self) -> int: | ||
"""Returns the current volume for the room from 0-100""" | ||
value = await self.director.getItemVariableValue(self.item_id, "CURRENT_VOLUME") | ||
return int(value) | ||
|
||
async def isMuted(self) -> bool: | ||
"""Returns True if the room is muted""" | ||
value = await self.director.getItemVariableValue(self.item_id, "IS_MUTED") | ||
return int(value) != 0 | ||
|
||
async def setMuteOn(self): | ||
"""Mute the room""" | ||
await self.director.sendPostRequest( | ||
"/api/v1/items/{}/commands".format(self.item_id), | ||
"MUTE_ON", | ||
{}, | ||
) | ||
|
||
async def setMuteOff(self): | ||
"""Unmute the room""" | ||
await self.director.sendPostRequest( | ||
"/api/v1/items/{}/commands".format(self.item_id), | ||
"MUTE_OFF", | ||
{}, | ||
) | ||
|
||
async def toggleMute(self): | ||
"""Toggle the current mute state for the room""" | ||
await self.director.sendPostRequest( | ||
"/api/v1/items/{}/commands".format(self.item_id), | ||
"MUTE_TOGGLE", | ||
{}, | ||
) | ||
|
||
async def setVolume(self, volume: int): | ||
"""Set the room volume, 0-100""" | ||
await self.director.sendPostRequest( | ||
"/api/v1/items/{}/commands".format(self.item_id), | ||
"SET_VOLUME_LEVEL", | ||
{"LEVEL": volume}, | ||
) | ||
|
||
async def setIncrementVolume(self): | ||
"""Decrease volume by 1""" | ||
await self.director.sendPostRequest( | ||
"/api/v1/items/{}/commands".format(self.item_id), | ||
"PULSE_VOL_UP", | ||
{}, | ||
) | ||
|
||
async def setDecrementVolume(self): | ||
"""Decrease volume by 1""" | ||
await self.director.sendPostRequest( | ||
"/api/v1/items/{}/commands".format(self.item_id), | ||
"PULSE_VOL_DOWN", | ||
{}, | ||
) | ||
|
||
async def setPlay(self): | ||
await self.director.sendPostRequest( | ||
"/api/v1/items/{}/commands".format(self.item_id), | ||
"PLAY", | ||
{}, | ||
) | ||
|
||
async def setPause(self): | ||
await self.director.sendPostRequest( | ||
"/api/v1/items/{}/commands".format(self.item_id), | ||
"PAUSE", | ||
{}, | ||
) | ||
|
||
async def setStop(self): | ||
"""Stops the currently playing media but does not turn off the room""" | ||
await self.director.sendPostRequest( | ||
"/api/v1/items/{}/commands".format(self.item_id), | ||
"STOP", | ||
{}, | ||
) | ||
|
||
async def getAudioDevices(self): | ||
""" | ||
Note: As tested in OS 3.2.3 this doesn't work, but may work in previous versions | ||
|
||
Get the audio devices located in the room. | ||
Note that this is literally the devices in the room, | ||
not necessarily all devices _playable_ in the room. | ||
See C4Director.getUiConfiguration for a more accurate list | ||
""" | ||
await self.director.sendGetRequest( | ||
"/api/v1/locations/rooms/{}/audio_devices".format(self.item_id) | ||
) | ||
|
||
async def getVideoDevices(self): | ||
""" | ||
Note: As tested in OS 3.2.3 this doesn't work, but may work in previous versions | ||
|
||
Get the video devices located in the room. | ||
Note that this is literally the devices in the room, | ||
not necessarily all devices _playable_ in the room. | ||
See C4Director.getUiConfiguration for a more accurate list | ||
""" | ||
await self.director.sendGetRequest( | ||
"/api/v1/locations/rooms/{}/video_devices".format(self.item_id) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you document/provide an example of what kind of data format is returned by this call?
See here for an example:
pyControl4/pyControl4/account.py
Line 157 in 065485f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The API call on OS 3.2.3, just returns None for me on both getAudioDevices/getVideoDevices. I do not make use of the functions in the HA integration instead we use the UI. Perhaps we delete these API Calls since they are not used?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It returns None? Like literal Python
None
or some sort of valid JSON response that just says no devices?I'm inclined to leave it in with a comment that says it returns none on OS 3.2.3 if it's actually a valid JSON response from Control4. Perhaps other configurations/older OS versions make use of this call.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah its just None the python literal. That is why I labeled as an invalid API call and deleted but I can put it back with comment that it wasn't valid in OS 3.2.3
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, I committed a change that brings back the functions and adds a warning note.