diff --git a/enums.py b/enums.py index f864d76..6ad189b 100644 --- a/enums.py +++ b/enums.py @@ -9,12 +9,11 @@ import enum class ScheduleFormat(str, enum.Enum): """ Enum to specify Schedule Format + ZERO - non programmable (time clocks cannot be non programmable) ONE - same format every day of the week TWO - 5 day / 2 day SEVEN - 7 day (every day different) - - """ ZERO = "NONPROGRAMMABLE" diff --git a/holiday.py b/holiday.py new file mode 100644 index 0000000..df8c91f --- /dev/null +++ b/holiday.py @@ -0,0 +1,48 @@ +#!/usr/bin/env python3 + +# SPDX-FileCopyrightText: 2020 Andrius Štikonas +# SPDX-License-Identifier: LGPL-3.0-or-later + +import datetime +import enum + +class Holiday: + """ + Class representing Holidays + + start, end: holiday datetime objects or None + ids + """ + + def __init__(self, reply: str): + start = reply["start"] + if start: + self._start = datetime.datetime.strptime(start.strip(), "%a %b %d %H:%M:%S %Y") + else: + self._start = None + + end = reply["end"] + if end: + self.end = datetime.datetime.strptime(end.strip(), "%a %b %d %H:%M:%S %Y") + else: + self._end = None + + self._ids = reply["ids"] + + + @property + def start(self): + """ Beginning of holiday. """ + return self._start + + + @property + def end(self): + """ End of holiday. """ + return self._end + + + @property + def ids(self): + """ Devices that have holiday set up. """ + return self._ids diff --git a/neohub.py b/neohub.py index 4422acd..fac0310 100644 --- a/neohub.py +++ b/neohub.py @@ -2,11 +2,13 @@ # SPDX-License-Identifier: LGPL-3.0-or-later import asyncio +import datetime import json import logging from enums import ScheduleFormat from system import System +from holiday import Holiday class NeoHub: @@ -153,11 +155,38 @@ class NeoHub: return result + async def holiday(self, start: datetime.datetime, end: datetime.datetime): + """ + Sets holiday mode. + + start: beginning of holiday + end: end of holiday + """ + + message = {"HOLIDAY": [start.strftime("%H%M%S%d%m%Y"), end.strftime("%H%M%S%d%m%Y")]} + + result = await self._send(message) + return result + async def get_holiday(self): """ Get list of holidays + + Returns Holiday object """ message = {"GET_HOLIDAY": 0} result = await self._send(message) + return Holiday(result) + + + async def cancel_holiday(self): + """ + Cancels holidays and returns to normal schedule + """ + + message = {"CANCEL_HOLIDAY": 0} + reply = {"result": "holiday cancelled"} + + result = await self._send(message, reply) return result diff --git a/test.py b/test.py index 91ce24a..39085ce 100755 --- a/test.py +++ b/test.py @@ -5,8 +5,9 @@ import asyncio -import neohub +import datetime import logging +import neohub from enums import ScheduleFormat @@ -15,8 +16,10 @@ async def run(): await hub.connect() system = await hub.get_system() print(vars(system)) - result = await hub.get_holiday() + result = await hub.cancel_holiday() print(result) + result = await hub.get_holiday() + print(vars(result)) logging.basicConfig(level=logging.DEBUG)