File: room.py

package info (click to toggle)
pycontrol4 1.5.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 548 kB
  • sloc: python: 914; makefile: 2
file content (152 lines) | stat: -rw-r--r-- 5,195 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
"""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)
        )