Skip to content

Commit

Permalink
add getItemSetup
Browse files Browse the repository at this point in the history
  • Loading branch information
lawtancool committed Aug 4, 2020
1 parent 23f3ecc commit 5426d39
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
18 changes: 16 additions & 2 deletions pyControl4/director.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ async def sendGetRequest(self, uri):
await checkResponseForError(await resp.text())
return await resp.text()

async def sendPostRequest(self, uri, command, params):
async def sendPostRequest(self, uri, command, params, async_variable=True):
"""Sends a POST request to the specified API URI. Used to send commands to the Director.
Returns the Director's JSON response as a string.
Expand All @@ -64,7 +64,11 @@ async def sendPostRequest(self, uri, command, params):
`params` - The parameters of the command, provided as a dictionary.
"""
dataDictionary = {"async": True, "command": command, "tParams": params}
dataDictionary = {
"async": async_variable,
"command": command,
"tParams": params,
}
if self.session is None:
async with aiohttp.ClientSession(
connector=aiohttp.TCPConnector(verify_ssl=False)
Expand Down Expand Up @@ -96,6 +100,16 @@ async def getItemInfo(self, item_id):
"""
return await self.sendGetRequest("/api/v1/items/{}".format(item_id))

async def getItemSetup(self, item_id):
"""Returns a JSON list of the setup info of the specified item.
Parameters:
`item_id` - The Control4 item ID.
"""
return await self.sendPostRequest(
"/api/v1/items/{}/commands".format(item_id), "GET_SETUP", "{}", False
)

async def getItemVariables(self, item_id):
"""Returns a JSON list of the variables available for the specified item.
Expand Down
2 changes: 2 additions & 0 deletions test.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ async def returnClientSession():
alarm = C4SecurityPanel(director, 460)
print(asyncio.run(alarm.getEmergencyTypes()))

print(asyncio.run(director.getItemSetup(471)))

# sensor = C4ContactSensor(director, 471)
# print(asyncio.run(sensor.getContactState()))

Expand Down

0 comments on commit 5426d39

Please sign in to comment.