Skip to content
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 fan support #25

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
105 changes: 105 additions & 0 deletions pyControl4/climate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
"""Controls Control4 Light devices.
"""


from pyControl4 import C4Entity


class C4Climate(C4Entity):
async def getHVACState(self):
"""Returns the power state of thee fan as a boolean (True=on, False=off)."""
value = await self.director.getItemVariableValue(self.item_id, "HVAC_STATE")
return value

async def getHVACModes(self):
"""Returns the power state of thee fan as a boolean (True=on, False=off)."""
value = await self.director.getItemVariableValue(
self.item_id, "HVAC_MODES_LIST"
)
return value

async def getHVACMode(self):
"""Returns the power state of thee fan as a boolean (True=on, False=off)."""
value = await self.director.getItemVariableValue(self.item_id, "HVAC_MODE")
return value

async def getFANModes(self):
"""Returns the power state of thee fan as a boolean (True=on, False=off)."""
value = await self.director.getItemVariableValue(self.item_id, "FAN_MODES_LIST")
return value

async def getFANMode(self):
"""Returns the power state of thee fan as a boolean (True=on, False=off)."""
value = await self.director.getItemVariableValue(self.item_id, "FAN_MODE")
return value

async def getFANState(self):
"""Returns the power state of thee fan as a boolean (True=on, False=off)."""
value = await self.director.getItemVariableValue(self.item_id, "FAN_STATE")
return value

async def getCoolSetpointF(self):
"""Returns the power state of thee fan as a boolean (True=on, False=off)."""
value = await self.director.getItemVariableValue(
self.item_id, "COOL_SETPOINT_F"
)
return value

async def getHeatSetpointF(self):
"""Returns the power state of thee fan as a boolean (True=on, False=off)."""
value = await self.director.getItemVariableValue(
self.item_id, "HEAT_SETPOINT_F"
)
return value

async def getHumidity(self):
"""Returns the power state of thee fan as a boolean (True=on, False=off)."""
value = await self.director.getItemVariableValue(self.item_id, "HUMIDITY")
return value

async def getCurrentTemperature(self):
"""Returns the power state of thee fan as a boolean (True=on, False=off)."""
value = await self.director.getItemVariableValue(self.item_id, "TEMPERATURE_F")
return value

async def setTemperature(self, temp):
await self.director.sendPostRequest(
"/api/v1/items/{}/commands".format(self.item_id),
"SET_SETPOINT_COOL",
{"FAHRENHEIT": temp},
)

async def setCoolSetpoint(self, temp):
await self.director.sendPostRequest(
"/api/v1/items/{}/commands".format(self.item_id),
"SET_SETPOINT_COOL",
{"FAHRENHEIT": temp},
)

async def setHeatSetpoint(self, temp):
await self.director.sendPostRequest(
"/api/v1/items/{}/commands".format(self.item_id),
"SET_SETPOINT_HEAT",
{"FAHRENHEIT": temp},
)

async def setHvacMode(self, mode):
await self.director.sendPostRequest(
"/api/v1/items/{}/commands".format(self.item_id),
"SET_MODE_HVAC",
{"MODE": mode},
)

async def setFanMode(self, mode):
await self.director.sendPostRequest(
"/api/v1/items/{}/commands".format(self.item_id),
"SET_MODE_FAN",
{"MODE": mode},
)

async def setPreset(self, preset):
await self.director.sendPostRequest(
"/api/v1/items/{}/commands".format(self.item_id),
"SET_PRESET",
{"NAME": preset},
)
2 changes: 1 addition & 1 deletion pyControl4/director.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ async def getItemSetup(self, item_id):
`item_id` - The Control4 item ID.
"""
return await self.sendPostRequest(
"/api/v1/items/{}/commands".format(item_id), "GET_SETUP", "{}", False
"/api/v1/items/{}/commands".format(item_id), "GET_SETUP", {}, False
)

async def getItemVariables(self, item_id):
Expand Down
46 changes: 46 additions & 0 deletions pyControl4/fan.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
"""Controls Control4 Light devices.
"""


from pyControl4 import C4Entity


class C4Fan(C4Entity):
async def getSpeed(self):
"""Returns the speed of a fan controller 0-4 are valid values.
Will cause an error if called on a non-dimmer switch. Use `getState()` instead.
0 - off, 1 - low, 2 - medium, 3 - medium high, 4 - high
"""
value = await self.director.getItemVariableValue(self.item_id, "CURRENT_SPEED")
return int(value)

async def getState(self):
"""Returns the power state of thee fan as a boolean (True=on, False=off)."""
value = await self.director.getItemVariableValue(self.item_id, "IS_ON")
return bool(value)

async def setSpeed(self, speed):
"""Sets the fan speed, or turns off the fan..
speed 0 for off, 1 for low, 2 for medium, 3 for medium high, 4 for high

Parameters:
`speed` - (int) 0-4
"""
await self.director.sendPostRequest(
"/api/v1/items/{}/commands".format(self.item_id),
"SET_SPEED",
{"SPEED": speed},
)

async def setPreset(self, preset):
"""Sets the preset fan speed, the speed the fan goes to if you just hit on
speed 0 for off, 1 for low, 2 for medium, 3 for medium high, 4 for high

Parameters:
`preset` - (int) 0-4
"""
await self.director.sendPostRequest(
"/api/v1/items/{}/commands".format(self.item_id),
"DESIGNATE_PRESET",
{"PRESET": preset},
)
Loading