Draft Live data API proposal.
This commit is contained in:
parent
24127f9df5
commit
87c9516172
34
neohub.py
34
neohub.py
|
@ -183,19 +183,19 @@ class NeoHub:
|
|||
result = await self._send(message, reply)
|
||||
return result
|
||||
|
||||
async def get_zones(self):
|
||||
"""
|
||||
Get list of all thermostats
|
||||
#async def get_zones(self):
|
||||
#"""
|
||||
#Get list of all thermostats
|
||||
|
||||
Returns a list of NeoStat objects
|
||||
"""
|
||||
#Returns a list of NeoStat objects
|
||||
#"""
|
||||
|
||||
message = {"GET_ZONES": 0}
|
||||
#message = {"GET_ZONES": 0}
|
||||
|
||||
zones = await self._send(message)
|
||||
result = []
|
||||
for name, zone_id in zones.__dict__.items():
|
||||
result.append(NeoStat(self, name, zone_id))
|
||||
#zones = await self._send(message)
|
||||
#result = []
|
||||
#for name, zone_id in zones.__dict__.items():
|
||||
#result.append(NeoStat(self, name, zone_id))
|
||||
|
||||
return result
|
||||
|
||||
|
@ -331,13 +331,21 @@ class NeoHub:
|
|||
|
||||
async def get_live_data(self):
|
||||
"""
|
||||
Returns live data from all devices
|
||||
Returns live data from hub and all devices
|
||||
"""
|
||||
|
||||
message = {"GET_LIVE_DATA": 0}
|
||||
|
||||
result = await self._send(message)
|
||||
return result
|
||||
hub_data = await self._send(message)
|
||||
devices = hub_data.devices
|
||||
delattr(hub_data, "devices")
|
||||
|
||||
thermostat_list = list(filter(lambda device: device.THERMOSTAT, devices))
|
||||
thermostats = []
|
||||
for thermostat in thermostat_list:
|
||||
thermostats.append(NeoStat(self, thermostat))
|
||||
|
||||
return hub_data, thermostats
|
||||
|
||||
async def permit_join(self, name, timeout_s=120):
|
||||
"""
|
||||
|
|
21
neostat.py
21
neostat.py
|
@ -3,33 +3,36 @@
|
|||
# SPDX-FileCopyrightText: 2020 Andrius Štikonas <andrius@stikonas.eu>
|
||||
# SPDX-License-Identifier: LGPL-3.0-or-later
|
||||
|
||||
from types import SimpleNamespace
|
||||
|
||||
class NeoStat:
|
||||
|
||||
class NeoStat(SimpleNamespace):
|
||||
"""
|
||||
Class representing NeoStat theormostat
|
||||
"""
|
||||
|
||||
def __init__(self, hub, name: str, zone_id: int):
|
||||
def __init__(self, hub, thermostat):
|
||||
self._data_ = thermostat
|
||||
self._hub = hub
|
||||
self._name = name
|
||||
self._zone_id = zone_id
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
""" Zone name. """
|
||||
return self._name
|
||||
|
||||
return self._data_.ZONE_NAME
|
||||
|
||||
@property
|
||||
def zone_id(self):
|
||||
""" End of holiday. """
|
||||
return self._zone_id
|
||||
def temperature(self):
|
||||
""" Actual zone temperature. """
|
||||
|
||||
return self._data_.ACTUAL_TEMP
|
||||
|
||||
async def identify(self):
|
||||
"""
|
||||
Flashes red LED light
|
||||
"""
|
||||
|
||||
message = {"IDENTIFY_DEV": self.zone_id}
|
||||
message = {"IDENTIFY_DEV": self.name}
|
||||
reply = {"result": "Device identifying"}
|
||||
|
||||
result = await self._hub._send(message, reply)
|
||||
|
|
8
test.py
8
test.py
|
@ -16,10 +16,10 @@ async def run():
|
|||
hub = neohub.NeoHub()
|
||||
await hub.connect()
|
||||
system = await hub.get_system()
|
||||
result = await hub.get_live_data()
|
||||
devices = result.devices
|
||||
for device in devices:
|
||||
print(f"Temperature in zone {device.ZONE_NAME}: {device.ACTUAL_TEMP}")
|
||||
hub_data, thermostats = await hub.get_live_data()
|
||||
for device in thermostats:
|
||||
print(f"Temperature in zone {device.name}: {device.temperature}")
|
||||
#await device.identify()
|
||||
|
||||
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
|
|
Loading…
Reference in New Issue