Skip to content

Commit

Permalink
Add room support for accessories attached to thermostat (#58)
Browse files Browse the repository at this point in the history
* add support for priority and rooms

* Update deploy.yml

* Update deploy.yml

* bit of clean up

* get ready for PR
  • Loading branch information
dalinicus authored Jul 30, 2023
1 parent 8324d8c commit ba521e4
Show file tree
Hide file tree
Showing 5 changed files with 217 additions and 1 deletion.
27 changes: 27 additions & 0 deletions aiolyric/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from .objects.base import LyricBase
from .objects.device import LyricDevice
from .objects.location import LyricLocation
from .objects.priority import LyricPriority, LyricRoom


class Lyric(LyricBase):
Expand All @@ -24,6 +25,7 @@ def __init__(
self._devices_dict: dict = {}
self._locations: List[LyricLocation] = []
self._locations_dict: dict = {}
self._rooms_dict: dict = {}

@property
def client_id(self) -> str:
Expand All @@ -45,6 +47,10 @@ def locations(self) -> List[LyricLocation]:
def locations_dict(self) -> dict:
return self._locations_dict

@property
def rooms_dict(self) -> dict[str, LyricRoom]:
return self._rooms_dict

async def get_devices(
self,
location_id: int,
Expand Down Expand Up @@ -74,6 +80,27 @@ async def get_locations(self) -> None:
for location in self._locations:
self._locations_dict[location.locationID] = location

async def get_thermostat_rooms(
self,
location_id: int,
device_id: str
) -> None:
"""Get Priority, which contains accessory information."""
response: ClientResponse = await self._client.get(
f"{BASE_URL}/devices/thermostats/{device_id}/priority?apikey={self.client_id}&locationId={location_id}"
)
json = await response.json()
self.logger.debug(json)

priority = LyricPriority(json)

macId = priority.deviceId # device id in the priority payload refers to the mac address of the device
self._rooms_dict[macId]: dict = {}

# add each room to the room dictionary. Rooms contain motion, temp, and humidity averages for all accessories in a room
for room in priority.currentPriority.rooms:
self._rooms_dict[macId][room.id] = room

async def update_thermostat(
self,
location: LyricLocation,
Expand Down
97 changes: 97 additions & 0 deletions aiolyric/objects/priority.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
"""
Class object for LyricPriority
Documentation: https://github.com/timmo001/aiolyric
Generated by generator/generator.py - 2023-07-27 18:30:29.139453
"""
from .base import LyricBase


class LyricAccessories(LyricBase):

@property
def id(self):
return self.attributes.get("id", None)

@property
def type(self):
return self.attributes.get("type", "")

@property
def excludeTemp(self):
return self.attributes.get("excludeTemp", False)

@property
def excludeMotion(self):
return self.attributes.get("excludeMotion", False)

@property
def temperature(self):
return self.attributes.get("temperature", None)

@property
def status(self):
return self.attributes.get("status", "")

@property
def detectMotion(self):
return self.attributes.get("detectMotion", False)


class LyricRoom(LyricBase):

@property
def id(self):
return self.attributes.get("id", None)

@property
def roomName(self):
return self.attributes.get("roomName", "")

@property
def roomAvgTemp(self):
return self.attributes.get("roomAvgTemp", None)

@property
def roomAvgHumidity(self):
return self.attributes.get("roomAvgHumidity", None)

@property
def overallMotion(self):
return self.attributes.get("overallMotion", False)

@property
def accessories(self):
return [LyricAccessories(x) for x in self.attributes.get("accessories", [])]


class CurrentPriority(LyricBase):

@property
def priorityType(self):
return self.attributes.get("priorityType", "")

@property
def selectedRooms(self):
return self.attributes.get("selectedRooms", [])

@property
def rooms(self):
return [LyricRoom(x) for x in self.attributes.get("rooms", [])]


class LyricPriority(LyricBase):

@property
def deviceId(self):
return self.attributes.get("deviceId", "")

@property
def status(self):
return self.attributes.get("status", "")

@property
def currentPriority(self):
return CurrentPriority(self.attributes.get("currentPriority", {}))


2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from setuptools import find_packages, setup

version = "1.0.10"
version = "1.1.0"

setup(
name="aiolyric",
Expand Down
18 changes: 18 additions & 0 deletions tests/objects/test_priority.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
"""
Generated by generator/generator.py - 2023-07-27 18:30:29.139453
"""
from aiolyric.objects.priority import LyricPriority
from tests.responses.priority_fixture import priority_fixture_response

def test_priority(priority_fixture_response):
obj = LyricPriority(priority_fixture_response)
assert obj.deviceId == priority_fixture_response['deviceId']
assert obj.status == priority_fixture_response['status']
assert obj.currentPriority.priorityType == priority_fixture_response['currentPriority']['priorityType']
assert obj.currentPriority.selectedRooms[0] == priority_fixture_response['currentPriority']['selectedRooms'][0]
assert obj.currentPriority.rooms[0].id == priority_fixture_response['currentPriority']['rooms'][0]['id']
assert obj.currentPriority.rooms[0].roomName == priority_fixture_response['currentPriority']['rooms'][0]['roomName']
assert obj.currentPriority.rooms[0].roomAvgTemp == priority_fixture_response['currentPriority']['rooms'][0]['roomAvgTemp']
assert obj.currentPriority.rooms[0].roomAvgHumidity == priority_fixture_response['currentPriority']['rooms'][0]['roomAvgHumidity']
assert obj.currentPriority.rooms[0].overallMotion == priority_fixture_response['currentPriority']['rooms'][0]['overallMotion']
assert obj.currentPriority.rooms[0].accessories == priority_fixture_response['currentPriority']['rooms'][0]['accessories']
74 changes: 74 additions & 0 deletions tests/responses/priority_fixture.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
"""
Generated by generator/generator.py - 2023-07-27 18:30:29.139453
"""
import pytest


@pytest.fixture()
def priority_fixture_response():
return {
'deviceId': '00A01AB1ABCD',
'status': 'NoHold',
'currentPriority': {
'priorityType': 'PickARoom',
'selectedRooms': [
0
],
'rooms': [
{
'id': 0,
'roomName': 'Hallway',
'roomAvgTemp': 76,
'roomAvgHumidity': 54,
'overallMotion': False,
'accessories': [
{
'id': 0,
'type': 'Thermostat',
'excludeTemp': False,
'excludeMotion': False,
'temperature': 75.828,
'status': 'Ok',
'detectMotion': False
}
]
},
{
'id': 1,
'roomName': 'Office',
'roomAvgTemp': 76,
'roomAvgHumidity': 52,
'overallMotion': True,
'accessories': [
{
'id': 1,
'type': 'IndoorAirSensor',
'excludeTemp': False,
'excludeMotion': False,
'temperature': 76,
'status': 'Ok',
'detectMotion': True
}
]
},
{
'id': 2,
'roomName': 'Master Bedroom',
'roomAvgTemp': 76,
'roomAvgHumidity': 52,
'overallMotion': False,
'accessories': [
{
'id': 2,
'type': 'IndoorAirSensor',
'excludeTemp': False,
'excludeMotion': False,
'temperature': 76,
'status': 'Ok',
'detectMotion': True
}
]
}
]
}
}

0 comments on commit ba521e4

Please sign in to comment.