Initial support for timeclocks.

This commit is contained in:
Andrius Štikonas 2021-01-02 22:42:56 +00:00
parent 65b9667d99
commit 7893ed66fd
3 changed files with 58 additions and 9 deletions

View File

@ -1,6 +1,6 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
# SPDX-FileCopyrightText: 2020 Andrius Štikonas <andrius@stikonas.eu> # SPDX-FileCopyrightText: 2020-2021 Andrius Štikonas <andrius@stikonas.eu>
# SPDX-License-Identifier: MIT # SPDX-License-Identifier: MIT
@ -15,13 +15,23 @@ from neohubapi.enums import ScheduleFormat
async def run(): async def run():
hub = neohub.NeoHub() hub = neohub.NeoHub()
system = await hub.get_system() system = await hub.get_system()
hub_data, thermostats = await hub.get_live_data() hub_data, devices = await hub.get_live_data()
for device in thermostats: print("Thermostats:")
for device in devices['thermostats']:
print(f"Target temperature of {device.name}: {device.target_temperature}") print(f"Target temperature of {device.name}: {device.target_temperature}")
await device.identify() await device.identify()
print("Timeclocks:")
for device in devices['timeclocks']:
print(f"Timeclock {device.name}: {device.target_temperature}")
print(await hub.set_timer_hold(False, 1, [device]))
print(await hub.target_temperature_step) print(await hub.target_temperature_step)
#logging.basicConfig(level=logging.DEBUG) def main():
asyncio.run(run()) logging.basicConfig(level=logging.DEBUG)
asyncio.run(run())
if (__name__ == '__main__'):
main()

View File

@ -1,4 +1,4 @@
# SPDX-FileCopyrightText: 2020 Andrius Štikonas <andrius@stikonas.eu> # SPDX-FileCopyrightText: 2020-2021 Andrius Štikonas <andrius@stikonas.eu>
# SPDX-License-Identifier: LGPL-3.0-or-later # SPDX-License-Identifier: LGPL-3.0-or-later
import asyncio import asyncio
@ -334,12 +334,22 @@ class NeoHub:
devices = hub_data.devices devices = hub_data.devices
delattr(hub_data, "devices") delattr(hub_data, "devices")
thermostat_list = list(filter(lambda device: device.THERMOSTAT, devices)) thermostat_list = list(filter(lambda device: hasattr(device, 'THERMOSTAT'), devices))
timeclock_list = list(filter(lambda device: hasattr(device, 'TIMECLOCK'), devices))
thermostats = [] thermostats = []
timeclocks = []
for thermostat in thermostat_list: for thermostat in thermostat_list:
thermostats.append(NeoStat(self, thermostat)) thermostats.append(NeoStat(self, thermostat))
return hub_data, thermostats for timeclock in timeclock_list:
timeclocks.append(NeoStat(self, timeclock))
devices = {}
devices['thermostats'] = thermostats
devices['timeclocks'] = timeclocks
return hub_data, devices
async def permit_join(self, name, timeout_s=120): async def permit_join(self, name, timeout_s=120):
""" """
@ -447,3 +457,32 @@ class NeoHub:
result = await self._send(message) result = await self._send(message)
return result.__dict__ return result.__dict__
async def set_timer(self, state: bool, devices: [NeoStat]):
"""
Turns the output of timeclock on or off
This function works only with NeoPlugs and does not work on
NeoStats that are in timeclock mode.
"""
names = [x.name for x in devices]
message = {"TIMER_ON" if state else "TIMER_OFF": names}
reply = {"result": "timers on" if state else "timers off"}
result = await self._send(message, reply)
return result
async def set_timer_hold(self, state: bool, minutes: int, devices: [NeoStat]):
"""
Turns the output of timeclock on or off
"""
names = [x.name for x in devices]
message = {"TIMER_HOLD_ON" if state else "TIMER_HOLD_OFF": [minutes, names]}
reply = {"result": "timer hold on" if state else "timer hold off"}
result = await self._send(message, reply)
return result

View File

@ -1,4 +1,4 @@
# SPDX-FileCopyrightText: 2020 Andrius Štikonas <andrius@stikonas.eu> # SPDX-FileCopyrightText: 2020-2021 Andrius Štikonas <andrius@stikonas.eu>
# SPDX-License-Identifier: LGPL-3.0-or-later # SPDX-License-Identifier: LGPL-3.0-or-later
from datetime import datetime, timedelta from datetime import datetime, timedelta