forked from andrius/neohubapi
Add ScheduleFormat enum.
This commit is contained in:
parent
f51fb1ce32
commit
727caaa333
|
@ -0,0 +1,23 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
# SPDX-FileCopyrightText: 2020 Andrius Štikonas <andrius@stikonas.eu>
|
||||
# SPDX-License-Identifier: LGPL-3.0-or-later
|
||||
|
||||
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"
|
||||
ONE = "24HOURSFIXED"
|
||||
TWO = "5DAY/2DAY"
|
||||
SEVEN = "7DAY"
|
11
neohub.py
11
neohub.py
|
@ -5,8 +5,10 @@ import asyncio
|
|||
import json
|
||||
import logging
|
||||
|
||||
from enums import ScheduleFormat
|
||||
from system import System
|
||||
|
||||
|
||||
class NeoHub:
|
||||
def __init__(self):
|
||||
self._logger = logging.getLogger('neohub')
|
||||
|
@ -122,14 +124,11 @@ class NeoHub:
|
|||
return result
|
||||
|
||||
|
||||
async def set_format(self, format):
|
||||
async def set_format(self, format: ScheduleFormat):
|
||||
"""
|
||||
Sets timer format
|
||||
Sets schedule format
|
||||
|
||||
"NONPROGRAMMABLE" - non programmable (time clocks cannot be non programmable)
|
||||
"24HOURSFIXED" - same format every day of the week
|
||||
"5DAY/2DAY" - 5 day / 2 day
|
||||
"7DAY" - 7 day (every day different)
|
||||
Format is specified using ScheduleFormat enum:
|
||||
"""
|
||||
|
||||
message = {"SET_FORMAT": format}
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
# SPDX-FileCopyrightText: 2020 Andrius Štikonas <andrius@stikonas.eu>
|
||||
# SPDX-License-Identifier: LGPL-3.0-or-later
|
||||
|
||||
from enums import ScheduleFormat
|
||||
|
||||
|
||||
def schedule_format(int_format):
|
||||
if int_format == 0:
|
||||
return ScheduleFormat.ZERO
|
||||
elif int_format == 1:
|
||||
return ScheduleFormat.ONE
|
||||
elif int_format == 2:
|
||||
return ScheduleFormat.TWO
|
||||
elif int_format == 4:
|
||||
return ScheduleFormat.SEVEN
|
||||
else:
|
||||
raise ValueError('Unrecognized ScheduleFormat')
|
||||
|
||||
|
||||
class System:
|
||||
def __init__(self, system_info):
|
||||
self.dst_auto = system_info['DST_AUTO']
|
||||
self.dst_on = system_info['DST_ON']
|
||||
self.timer_format = schedule_format(system_info['FORMAT'])
|
||||
# If system timer format is set to non programmable, then any time clock remain
|
||||
# in the previous setting which is stored in ALT_TIMER_FORMAT.
|
||||
self.alt_timer_format = schedule_format(system_info['ALT_TIMER_FORMAT'])
|
||||
self.ntp = system_info['NTP_ON'] == "Running"
|
||||
self.hub_type = system_info['HUB_TYPE']
|
||||
self.hub_version = system_info['HUB_VERSION']
|
||||
self.temperature_unit = system_info["CORF"]
|
||||
self.timezone = system_info['TIME_ZONE']
|
||||
self.time = system_info['UTC']
|
3
test.py
3
test.py
|
@ -8,13 +8,14 @@ import asyncio
|
|||
import neohub
|
||||
import logging
|
||||
|
||||
from enums import ScheduleFormat
|
||||
|
||||
async def run():
|
||||
hub = neohub.NeoHub()
|
||||
await hub.connect()
|
||||
system = await hub.get_system()
|
||||
print(vars(system))
|
||||
result = await hub.set_format("NONPROGRAMMABLE")
|
||||
result = await hub.set_format(ScheduleFormat.ZERO)
|
||||
print(result)
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue