forked from andrius/neohubapi
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)
|
result = await self._send(message, reply)
|
||||||
return result
|
return result
|
||||||
|
|
||||||
async def get_zones(self):
|
#async def get_zones(self):
|
||||||
"""
|
#"""
|
||||||
Get list of all thermostats
|
#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)
|
#zones = await self._send(message)
|
||||||
result = []
|
#result = []
|
||||||
for name, zone_id in zones.__dict__.items():
|
#for name, zone_id in zones.__dict__.items():
|
||||||
result.append(NeoStat(self, name, zone_id))
|
#result.append(NeoStat(self, name, zone_id))
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
@ -331,13 +331,21 @@ class NeoHub:
|
||||||
|
|
||||||
async def get_live_data(self):
|
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}
|
message = {"GET_LIVE_DATA": 0}
|
||||||
|
|
||||||
result = await self._send(message)
|
hub_data = await self._send(message)
|
||||||
return result
|
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):
|
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-FileCopyrightText: 2020 Andrius Štikonas <andrius@stikonas.eu>
|
||||||
# SPDX-License-Identifier: LGPL-3.0-or-later
|
# SPDX-License-Identifier: LGPL-3.0-or-later
|
||||||
|
|
||||||
|
from types import SimpleNamespace
|
||||||
|
|
||||||
class NeoStat:
|
|
||||||
|
class NeoStat(SimpleNamespace):
|
||||||
"""
|
"""
|
||||||
Class representing NeoStat theormostat
|
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._hub = hub
|
||||||
self._name = name
|
|
||||||
self._zone_id = zone_id
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
""" Zone name. """
|
""" Zone name. """
|
||||||
return self._name
|
|
||||||
|
return self._data_.ZONE_NAME
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def zone_id(self):
|
def temperature(self):
|
||||||
""" End of holiday. """
|
""" Actual zone temperature. """
|
||||||
return self._zone_id
|
|
||||||
|
return self._data_.ACTUAL_TEMP
|
||||||
|
|
||||||
async def identify(self):
|
async def identify(self):
|
||||||
"""
|
"""
|
||||||
Flashes red LED light
|
Flashes red LED light
|
||||||
"""
|
"""
|
||||||
|
|
||||||
message = {"IDENTIFY_DEV": self.zone_id}
|
message = {"IDENTIFY_DEV": self.name}
|
||||||
reply = {"result": "Device identifying"}
|
reply = {"result": "Device identifying"}
|
||||||
|
|
||||||
result = await self._hub._send(message, reply)
|
result = await self._hub._send(message, reply)
|
||||||
|
|
8
test.py
8
test.py
|
@ -16,10 +16,10 @@ async def run():
|
||||||
hub = neohub.NeoHub()
|
hub = neohub.NeoHub()
|
||||||
await hub.connect()
|
await hub.connect()
|
||||||
system = await hub.get_system()
|
system = await hub.get_system()
|
||||||
result = await hub.get_live_data()
|
hub_data, thermostats = await hub.get_live_data()
|
||||||
devices = result.devices
|
for device in thermostats:
|
||||||
for device in devices:
|
print(f"Temperature in zone {device.name}: {device.temperature}")
|
||||||
print(f"Temperature in zone {device.ZONE_NAME}: {device.ACTUAL_TEMP}")
|
#await device.identify()
|
||||||
|
|
||||||
|
|
||||||
logging.basicConfig(level=logging.DEBUG)
|
logging.basicConfig(level=logging.DEBUG)
|
||||||
|
|
Loading…
Reference in New Issue