diff --git a/neohub.py b/neohub.py index 1daea91..a99c0e3 100644 --- a/neohub.py +++ b/neohub.py @@ -344,3 +344,38 @@ class NeoHub: result = await self._send(message) return result + + async def lock(self, pin: int, devices: [NeoStat]): + """ + PIN locks thermostats + + PIN is a four digit number + """ + + if pin < 0 or pin > 9999: + return False + + pins = [] + for x in range(4): + pins.append(pin % 10) + pin = pin // 10 + pins.reverse() + + names = [x.name for x in devices] + message = {"LOCK": [pins, names]} + reply = {"result": "locked"} + + result = await self._send(message, reply) + return result + + async def unlock(self, devices: [NeoStat]): + """ + Unlocks PIN locked thermostats + """ + + names = [x.name for x in devices] + message = {"UNLOCK": names} + reply = {"result": "unlocked"} + + result = await self._send(message, reply) + return result diff --git a/neostat.py b/neostat.py index 7fc0c6f..6b1d2b6 100644 --- a/neostat.py +++ b/neostat.py @@ -63,3 +63,11 @@ class NeoStat: result = await self._hub._send(message, reply) return result + + async def lock(self, pin: int): + result = await self._hub.lock(pin, [self]) + return result + + async def unlock(self): + result = await self._hub.unlock([self]) + return result