Skip to content

Commit

Permalink
Tests (#75)
Browse files Browse the repository at this point in the history
* Update

* Refactor test_priority to include assertions for accessories properties

* Cleanup

* Changes

* Additions

* Test client

* Add

* Fan

* Finalise
  • Loading branch information
timmo001 authored Apr 1, 2024
1 parent 00ed2ee commit 8e6d9d0
Show file tree
Hide file tree
Showing 14 changed files with 565 additions and 326 deletions.
25 changes: 12 additions & 13 deletions aiolyric/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,11 @@ 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:
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}"
Expand All @@ -111,12 +115,12 @@ async def update_thermostat(
self,
location: LyricLocation,
device: LyricDevice,
mode=None,
heat_setpoint=None,
cool_setpoint=None,
auto_changeover_active=None,
thermostat_setpoint_status=None,
next_period_time=None,
mode: str | None = None,
heat_setpoint: int | float | None = None,
cool_setpoint: int | float | None = None,
auto_changeover_active: bool | None = None,
thermostat_setpoint_status: str | None = None,
next_period_time: str | None = None,
) -> ClientResponse:
"""Update Theremostat."""
self.logger.debug("Update Thermostat")
Expand Down Expand Up @@ -178,12 +182,7 @@ async def update_fan(
"""Update Fan."""
self.logger.debug("Update Fan")

data = {}

if mode is not None:
data["mode"] = mode
else:
data["mode"] = device.settings.fanMode.fan
data = {"mode": mode}

self.logger.debug(data)

Expand Down
2 changes: 0 additions & 2 deletions aiolyric/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ async def request(
"""Make a request."""
if (headers := kwargs.get("headers")) is None:
headers = {}
else:
headers = dict(headers)

access_token = await self.async_get_access_token()
headers["Authorization"] = f"Bearer {access_token}"
Expand Down
50 changes: 13 additions & 37 deletions aiolyric/objects/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,20 +81,6 @@ def air(self):
class SettingsSpecialmode(LyricBaseObject):
"""Special mode."""

@property
def _(self):
"""Return None."""
return None


class SettingsFan(LyricBaseObject):
"""Fan settings."""

@property
def fan(self):
"""Return the fan settings."""
return self.attributes.get("fan", {})


class Settings(LyricBaseObject):
"""Settings."""
Expand All @@ -119,30 +105,10 @@ def devicePairingEnabled(self):
"""Return if device pairing is enabled."""
return self.attributes.get("devicePairingEnabled", True)

@property
def fanModes(self):
"""Return fan modes."""
return SettingsFan(self.attributes.get("allowedModes", []))

@property
def fanChangeableValues(self):
"""Return fan changeable values."""
return SettingsFan(self.attributes.get("changeableValues", {}))

@property
def fanMode(self):
"""Return the fan mode."""
return SettingsFan(self.attributes.get("mode", None))


class Devicesettings(LyricBaseObject):
"""Device settings."""

@property
def _(self):
"""Return None."""
return None


class Service(LyricBaseObject):
"""Service."""
Expand All @@ -156,15 +122,20 @@ def mode(self):
class Changeablevalues(LyricBaseObject):
"""Changeable values."""

@property
def mode(self):
"""Return the mode."""
return self.attributes.get("mode", None)

@property
def autoChangeoverActive(self):
"""Return if auto changeover is active."""
return self.attributes.get("autoChangeoverActive", None)

@property
def mode(self):
"""Return the mode."""
return self.attributes.get("mode", None)
def emergencyHeatActive(self):
"""Return the thermostat setpoint status."""
return self.attributes.get("emergencyHeatActive", None)

@property
def heatSetpoint(self):
Expand Down Expand Up @@ -398,3 +369,8 @@ def operationStatus(self):
def deviceModel(self):
"""Return the device model."""
return self.attributes.get("deviceModel", None)

@property
def fanMode(self):
"""Return the fan mode."""
return self.attributes.get("fanMode", None)
245 changes: 245 additions & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,248 @@
from typing import Final

RESPONSE_JSON_BASIC: Final[dict] = {"test": "test"}

RESPONSE_JSON_DEVICE: Final[dict] = {
"locationID": 123456,
"indoorHumidity": 51,
"displayedOutdoorHumidity": 51,
"vacationHold": {"enabled": False},
"currentSchedulePeriod": {"day": "Monday", "period": "P2"},
"scheduleCapabilities": {
"availableScheduleTypes": ["None", "Geofenced", "TimedEmea"],
"schedulableFan": False,
},
"scheduleType": {"scheduleType": "Timed", "scheduleSubType": "EMEA"},
"scheduleStatus": "Resume",
"allowedTimeIncrements": 10,
"settings": {
"hardwareSettings": {"brightness": 5, "maxBrightness": 5},
"temperatureMode": {"air": True},
"specialMode": {},
"devicePairingEnabled": True,
},
"deviceClass": "Thermostat",
"deviceType": "Thermostat",
"deviceID": "LCC-00A01AB1ABCD",
"name": "Thermostat",
"isAlive": True,
"isUpgrading": False,
"isProvisioned": True,
"macID": "00A01AB1ABCD",
"deviceSettings": {},
"service": {"mode": "Up"},
"deviceRegistrationDate": "2019-01-01T19:32:20.4766667",
"dataSyncStatus": "Initiated",
"units": "Celsius",
"indoorTemperature": 23.5,
"outdoorTemperature": 16,
"allowedModes": ["Heat", "Off"],
"deadband": 0,
"hasDualSetpointStatus": False,
"minHeatSetpoint": 5,
"maxHeatSetpoint": 35,
"minCoolSetpoint": -18,
"maxCoolSetpoint": -18,
"changeableValues": {
"mode": "Heat",
"autoChangeoverActive": False,
"emergencyHeatActive": False,
"heatSetpoint": 15,
"coolSetpoint": 28,
"thermostatSetpointStatus": "NoHold",
"nextPeriodTime": "19:00:00",
"endHeatSetpoint": 62,
"endCoolSetpoint": 85,
"heatCoolMode": "Heat",
},
"operationStatus": {
"mode": "EquipmentOff",
"fanRequest": False,
"circulationFanRequest": False,
},
"deviceModel": "T5-T6",
"fanMode": "Auto",
}

RESPONSE_JSON_LOCATION: Final[dict] = {
"locationID": 123456,
"name": "Home",
"country": "GB",
"zipcode": "AB12 3AB",
"devices": [
{
"displayedOutdoorHumidity": 51,
"vacationHold": {"enabled": False},
"currentSchedulePeriod": {"day": "Monday", "period": "P2"},
"scheduleCapabilities": {
"availableScheduleTypes": ["None", "Geofenced", "TimedEmea"],
"schedulableFan": False,
},
"scheduleType": {"scheduleType": "Timed", "scheduleSubType": "EMEA"},
"scheduleStatus": "Resume",
"allowedTimeIncrements": 10,
"settings": {
"hardwareSettings": {"brightness": 5, "maxBrightness": 5},
"temperatureMode": {"air": True},
"specialMode": {},
"devicePairingEnabled": True,
},
"deviceClass": "Thermostat",
"deviceType": "Thermostat",
"deviceID": "LCC-00D02DD9CADE",
"userDefinedDeviceName": "Thermostat",
"name": "Thermostat",
"isAlive": True,
"isUpgrading": False,
"isProvisioned": True,
"macID": "00D02DD9CADE",
"deviceSettings": {},
"service": {"mode": "Up"},
"deviceRegistrationDate": "2019-04-04T19:32:20.4766667",
"dataSyncStatus": "Initiated",
"units": "Celsius",
"indoorTemperature": 23,
"outdoorTemperature": 16,
"allowedModes": ["Heat", "Off"],
"deadband": 0,
"hasDualSetpointStatus": False,
"minHeatSetpoint": 5,
"maxHeatSetpoint": 35,
"minCoolSetpoint": -18,
"maxCoolSetpoint": -18,
"changeableValues": {
"mode": "Heat",
"heatSetpoint": 15,
"coolSetpoint": 28,
"thermostatSetpointStatus": "NoHold",
"nextPeriodTime": "19:00:00",
"heatCoolMode": "Heat",
"endHeatSetpoint": None,
"endCoolSetpoint": None,
},
"operationStatus": {
"mode": "EquipmentOff",
"fanRequest": False,
"circulationFanRequest": False,
},
"deviceModel": "T5-T6",
}
],
"users": [
{
"userID": 123456,
"username": "[email protected]",
"firstname": "Tim",
"lastname": "Drake",
"created": 1554403500,
"deleted": -62135596800,
"activated": True,
"connectedHomeAccountExists": True,
"locationRoleMapping": [
{
"locationID": 1214161,
"role": "Adult",
"locationName": "Home",
"status": 1,
}
],
"isOptOut": "False",
"isCurrentUser": True,
}
],
"timeZone": "GMT Standard Time",
"ianaTimeZone": "Europe/London",
"daylightSavingTimeEnabled": True,
"geoFenceEnabled": False,
"predictiveAIREnabled": False,
"comfortLevel": 0,
"geoFenceNotificationEnabled": False,
"geoFenceNotificationTypeId": 13,
"configuration": {
"faceRecognition": {
"enabled": False,
"maxPersons": 10,
"maxEtas": 2,
"maxEtaPersons": 1,
"schedules": [
{
"time": [{"start": "00:00:00", "end": "23:59:59"}],
"days": [
"Sunday",
"Monday",
"Tuesday",
"Wednesday",
"Thursday",
"Friday",
"Saturday",
],
}
],
}
},
}

RESPONSE_JSON_PRIORITY: Final[dict] = {
"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,
}
],
},
],
},
}
Loading

0 comments on commit 8e6d9d0

Please sign in to comment.