forked from andrius/neohubapi
Add class to represent holidays.
This commit is contained in:
parent
cf195e83ed
commit
d44117d913
3
enums.py
3
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"
|
||||
|
|
|
@ -0,0 +1,48 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
# SPDX-FileCopyrightText: 2020 Andrius Štikonas <andrius@stikonas.eu>
|
||||
# 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
|
29
neohub.py
29
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
|
||||
|
|
7
test.py
7
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)
|
||||
|
|
Loading…
Reference in New Issue