Skip to content

Commit

Permalink
Add expose keyboard lock functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
danielrivard committed Mar 28, 2023
1 parent 61956bd commit 8883d1d
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 4 deletions.
25 changes: 24 additions & 1 deletion innova_controls/airleaf.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from enum import Enum
from typing import List

from innova_controls.constants import CMD_SET_TEMP
from innova_controls.constants import CMD_LOCK_OFF, CMD_LOCK_ON, CMD_SET_TEMP
from innova_controls.fan_speed import FanSpeed
from innova_controls.innova_device import InnovaDevice
from innova_controls.mode import Mode
Expand Down Expand Up @@ -62,6 +62,17 @@ def water_temperature(self) -> float:
def supports_water_temp(self) -> bool:
return True

@property
def keyboard_locked(self) -> bool:
if "kl" in self._status:
return self._status["kl"] == 1
else:
return False

@property
def supports_keyboard_lock(self) -> bool:
return True

@property
def fan_speed(self) -> FanSpeed:
if "fn" in self._status:
Expand Down Expand Up @@ -141,6 +152,18 @@ async def set_cooling(self) -> bool:
if self.power or await self.power_on():
return await self._set_mode(self.Modes.COOLING)
return False

async def lock_keyboard(self) -> bool:
if await self._network_facade.send_command(CMD_LOCK_ON):
self._status["kl"] = 1
return True
return False

async def unlock_keyboard(self) -> bool:
if await self._network_facade.send_command(CMD_LOCK_OFF):
self._status["kl"] = 0
return True
return False

async def set_auto(self) -> bool:
pass
Expand Down
2 changes: 2 additions & 0 deletions innova_controls/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
CMD_ROTATION = "set/feature/rotation"
CMD_FAN_SPEED = "set/fan"
CMD_STATUS = "status"
CMD_LOCK_OFF = "set/lock/off"
CMD_LOCK_ON = "set/lock/on"

ROTATION_ON = 0
ROTATION_OFF = 7
Expand Down
20 changes: 20 additions & 0 deletions innova_controls/innova.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,12 @@ def scheduling_mode(self) -> bool:
return self._innova_device.scheduling_mode
return False

@property
def keyboard_locked(self) -> bool:
if self._innova_device:
return self._innova_device.keyboard_locked
return False

@property
def model(self) -> str:
if self._innova_device:
Expand Down Expand Up @@ -231,6 +237,16 @@ async def set_scheduling_off(self) -> bool:
return await self._innova_device.set_scheduling_off()
return False

async def lock_keyboard(self) -> bool:
if self._innova_device:
return await self._innova_device.lock_keyboard()
return False

async def unlock_keyboard(self) -> bool:
if self._innova_device:
return await self._innova_device.unlock_keyboard()
return False

async def set_heating(self) -> bool:
return await self._innova_device.set_heating()

Expand Down Expand Up @@ -265,3 +281,7 @@ def supports_fan(self) -> bool:
@property
def supports_preset(self) -> bool:
return self._innova_device.supports_preset

@property
def supports_keyboard_lock(self) -> bool:
return self._innova_device.supports_keyboard_lock
14 changes: 14 additions & 0 deletions innova_controls/innova_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ def night_mode(self) -> bool:
def temperature_step(self) -> float:
pass

@property
def keyboard_locked(self) -> bool:
return False

@abstractmethod
async def set_temperature(self, temperature: float) -> bool:
pass
Expand Down Expand Up @@ -137,6 +141,12 @@ async def set_fan_only(self) -> bool:
async def set_auto(self) -> bool:
pass

async def lock_keyboard(self) -> bool:
return False

async def unlock_keyboard(self) -> bool:
return False

async def _set_mode(self, mode: Mode) -> bool:
if await self._network_facade.send_command(mode.command):
self._status["ps"] = 1
Expand Down Expand Up @@ -245,3 +255,7 @@ def supports_fan(self) -> bool:
@property
def supports_preset(self) -> bool:
return True

@property
def supports_keyboard_lock(self) -> bool:
return False
17 changes: 16 additions & 1 deletion simulator/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
ambient_temp = ambient_temp * 10
power = 1
scheduling = 1
keyboard_locked = 1


def success_response(success=True):
Expand Down Expand Up @@ -117,6 +118,20 @@ def calendar_on():
return success_response()


@app.route("/api/v/1/set/lock/off", methods=["POST"])
def lock_off():
global keyboard_locked
keyboard_locked = 0
return success_response()


@app.route("/api/v/1/set/lock/on", methods=["POST"])
def lock_on():
global keyboard_locked
keyboard_locked = 1
return success_response()


@app.route("/api/v/1/status", methods=["GET"])
def status():
status = {
Expand All @@ -140,7 +155,7 @@ def status():
"heatingResistance": 0,
"hotelMode": 0,
"inputFlags": 0,
"kl": 0,
"kl": keyboard_locked,
"lastRefresh": 2,
"ncc": 0,
"nm": 0,
Expand Down
12 changes: 10 additions & 2 deletions test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ async def main():
print(f"Rotation: {innova.rotation}")
print(f"Night Mode: {innova.night_mode}")
print(f"Scheduling Mode: {innova.scheduling_mode}")
print(f"Keyboard Locked: {innova.keyboard_locked}")
modes = []
for mode in innova.supported_modes:
if mode.is_cooling:
Expand All @@ -42,9 +43,16 @@ async def main():
await innova.async_update()
print(f"Scheduling Mode: {innova.scheduling_mode}")

if innova.supports_keyboard_lock:
await innova.lock_keyboard()
print(f"Keyboard Locked: {innova.keyboard_locked}")
await innova.unlock_keyboard()
print(f"Keyboard Locked: {innova.keyboard_locked}")
await innova.async_update()
print(f"Keyboard Locked: {innova.keyboard_locked}")

# await innova.set_fan_speed(FanSpeed.AUTO)
# print(innova.fan_speed)


loop = asyncio.get_event_loop()
loop = asyncio.new_event_loop()
loop.run_until_complete(main())

0 comments on commit 8883d1d

Please sign in to comment.