| 1 |
""" |
| 2 |
Air Purifier and Humidifier Device API Responses |
| 3 |
|
| 4 |
FANS variable is a list of device types |
| 5 |
|
| 6 |
DETAILS_RESPONSES variable is a dictionary of responses from the API |
| 7 |
for get_details() methods. The keys are the device types and the |
| 8 |
values are the responses. The responses are tuples of (response, status) |
| 9 |
|
| 10 |
METHOD_RESPONSES variable is a defaultdict of responses from the API. This is |
| 11 |
the FunctionResponse variable from the utils module in the tests dir. |
| 12 |
The default response is a tuple with the value ({"code": 0, "msg": "success"}, 200). |
| 13 |
|
| 14 |
The values of METHOD_RESPONSES can be a function that takes a single argument or |
| 15 |
a static value. The value is checked if callable at runtime and if so, it is called |
| 16 |
with the provided argument. If not callable, the value is returned as is. |
| 17 |
|
| 18 |
METHOD_RESPONSES = { |
| 19 |
'DEV_TYPE': defaultdict( |
| 20 |
lambda: ({"code": 0, "msg": "success"}, 200)) |
| 21 |
) |
| 22 |
} |
| 23 |
|
| 24 |
# For a function to handle the response |
| 25 |
def status_response(request_body=None): |
| 26 |
# do work with request_body |
| 27 |
return request_body, 200 |
| 28 |
|
| 29 |
METHOD_RESPONSES['DEV_TYPE']['set_status'] = status_response |
| 30 |
|
| 31 |
# To change the default value for a device type |
| 32 |
|
| 33 |
METHOD_RESPONSES['DEVTYPE'].default_factory = lambda: ({"code": 0, "msg": "success"}, 200) |
| 34 |
""" |
| 35 |
|
| 36 |
from copy import deepcopy |
| 37 |
from pyvesync.device_map import fan_modules |
| 38 |
from pyvesync.const import DeviceStatus |
| 39 |
from defaults import ( |
| 40 |
build_bypass_v2_response, |
| 41 |
FunctionResponsesV2, |
| 42 |
) |
| 43 |
from pyvesync.const import FanModes |
| 44 |
|
| 45 |
FANS = [m.setup_entry for m in fan_modules] |
| 46 |
FANS_NUM = len(FANS) |
| 47 |
|
| 48 |
|
| 49 |
class FanDefaults: |
| 50 |
fan_status = DeviceStatus.ON |
| 51 |
screen_status = DeviceStatus.ON |
| 52 |
oscillation_status = DeviceStatus.ON |
| 53 |
oscillation_horizontal = DeviceStatus.ON |
| 54 |
oscillation_vertical = DeviceStatus.ON |
| 55 |
mute_status = DeviceStatus.ON |
| 56 |
child_lock = DeviceStatus.OFF |
| 57 |
fan_mode = FanModes.NORMAL |
| 58 |
yaw = 45 |
| 59 |
pitch = 90 |
| 60 |
top = 120 |
| 61 |
bottom = 0 |
| 62 |
left = 0 |
| 63 |
right = 90 |
| 64 |
fan_level = 1 |
| 65 |
fan_speed_level = 1 |
| 66 |
temperature_fan = 75.0 |
| 67 |
|
| 68 |
|
| 69 |
FAN_DETAILS: dict[str, dict] = { |
| 70 |
"LTF-F422S": { |
| 71 |
"powerSwitch": int(FanDefaults.fan_status), |
| 72 |
"workMode": FanModes.NORMAL.value, |
| 73 |
"manualSpeedLevel": FanDefaults.fan_level, |
| 74 |
"fanSpeedLevel": FanDefaults.fan_speed_level, |
| 75 |
"screenState": int(FanDefaults.screen_status), |
| 76 |
"screenSwitch": int(FanDefaults.screen_status), |
| 77 |
"oscillationSwitch": int(FanDefaults.oscillation_status), |
| 78 |
"oscillationState": int(FanDefaults.oscillation_status), |
| 79 |
"muteSwitch": int(FanDefaults.mute_status), |
| 80 |
"muteState": int(FanDefaults.mute_status), |
| 81 |
"timerRemain": 0, |
| 82 |
"temperature": FanDefaults.temperature_fan, |
| 83 |
"sleepPreference": { |
| 84 |
"sleepPreferenceType": "default", |
| 85 |
"oscillationSwitch": int(FanDefaults.oscillation_status), |
| 86 |
"initFanSpeedLevel": 0, |
| 87 |
"fallAsleepRemain": 0, |
| 88 |
"autoChangeFanLevelSwitch": int(FanDefaults.fan_status), |
| 89 |
}, |
| 90 |
"scheduleCount": 0, |
| 91 |
"displayingType": 0, |
| 92 |
"errorCode": 0, |
| 93 |
}, |
| 94 |
"LPF-R423S": { |
| 95 |
"powerSwitch": int(FanDefaults.fan_status), |
| 96 |
"workMode": FanDefaults.fan_mode.value, |
| 97 |
"fanSpeedLevel": FanDefaults.fan_speed_level, |
| 98 |
"scheduleCount": 0, |
| 99 |
"timerRemain": 0, |
| 100 |
"sleepPreference": { |
| 101 |
"sleepPreferenceType": "default", |
| 102 |
"oscillationState": int(FanDefaults.oscillation_status), |
| 103 |
"initFanSpeedLevel": 0, |
| 104 |
"fallAsleepRemain": 0, |
| 105 |
}, |
| 106 |
"temperature": FanDefaults.temperature_fan * 10, |
| 107 |
"muteState": int(FanDefaults.mute_status), |
| 108 |
"muteSwitch": int(FanDefaults.mute_status), |
| 109 |
"screenState": int(FanDefaults.screen_status), |
| 110 |
"screenSwitch": int(FanDefaults.screen_status), |
| 111 |
"errorCode": 0, |
| 112 |
"horizontalOscillationState": int(FanDefaults.oscillation_horizontal), |
| 113 |
"verticalOscillationState": int(FanDefaults.oscillation_vertical), |
| 114 |
"childLock": FanDefaults.child_lock, |
| 115 |
"oscillationCoordinate": {"yaw": FanDefaults.yaw, "pitch": FanDefaults.pitch}, |
| 116 |
"oscillationRange": { |
| 117 |
"left": FanDefaults.left, |
| 118 |
"right": FanDefaults.right, |
| 119 |
"top": FanDefaults.top, |
| 120 |
"bottom": FanDefaults.bottom, |
| 121 |
}, |
| 122 |
"highTemperatureReminderState": 1, |
| 123 |
"highTemperature": 806, |
| 124 |
"smartCleaningReminderState": 1, |
| 125 |
"oscillationCalibrationState": 0, |
| 126 |
"oscillationCalibrationProgress": 0, |
| 127 |
"levelMemory": [ |
| 128 |
{"workMode": "normal", "level": 2, "enable": 1}, |
| 129 |
{"workMode": "turbo", "level": 12, "enable": 0}, |
| 130 |
{"workMode": "eco", "level": 3, "enable": 1}, |
| 131 |
{"workMode": "advancedSleep", "level": 3, "enable": 1}, |
| 132 |
], |
| 133 |
"horizontalOscillationDemo": 0, |
| 134 |
"verticalOscillationDemo": 0, |
| 135 |
"isSupportSetOnceOscillation": 1, |
| 136 |
"isTimerSupportPowerOn": 1, |
| 137 |
"isSupportSetRelativeCoordinate": 1, |
| 138 |
}, |
| 139 |
} |
| 140 |
"""Contains the result dictionary of the device response details for fans. |
| 141 |
|
| 142 |
Dictionary with key being the `setup_entry` attribute for each fan device |
| 143 |
found in the `pyvesync.device_map.fan_modules` object. The value is the |
| 144 |
return dictionary for a successful `fan.update()` API request. |
| 145 |
""" |
| 146 |
|
| 147 |
DETAILS_RESPONSES = { |
| 148 |
"LTF-F422S": build_bypass_v2_response(inner_result=FAN_DETAILS["LTF-F422S"]), |
| 149 |
"LPF-R423S": build_bypass_v2_response(inner_result=FAN_DETAILS["LPF-R423S"]), |
| 150 |
} |
| 151 |
|
| 152 |
|
| 153 |
METHOD_RESPONSES = { |
| 154 |
"LTF-F422S": deepcopy(FunctionResponsesV2), |
| 155 |
"LPF-R423S": deepcopy(FunctionResponsesV2) |
| 156 |
} |
| 157 |
"""Default responses for device methods. |
| 158 |
|
| 159 |
This dictionary maps the setup_entry to the default response for that device. |
| 160 |
|
| 161 |
Examples: |
| 162 |
- For legacy API responses `defaults.FunctionResponses` |
| 163 |
- For Bypass V1 `defaults.FunctionResponsesV1` |
| 164 |
- For Bypass V2 `defaults.FunctionResponsesV2` |
| 165 |
""" |
| 166 |
|
| 167 |
|