-
Notifications
You must be signed in to change notification settings - Fork 15
Split washer and dryer class #96
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 10 commits
e59e153
a68c952
5b6b7cd
71390d6
f3f5038
432d137
0dc1749
d5b450e
21e9834
6d153ff
bfd3479
22facc9
19a9544
4b338d1
899da5e
c929d22
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import json | ||
|
||
import aioconsole | ||
|
||
from whirlpool.dryer import Dryer | ||
|
||
|
||
async def show_dryer_menu(dr: Dryer) -> None: | ||
def print_menu(): | ||
print("\n") | ||
print(30 * "-", "MENU", 30 * "-") | ||
print("u. Update status from server") | ||
print("p. Print status") | ||
print("v. Print raw status") | ||
print("c. Custom command") | ||
print("q. Exit") | ||
print(67 * "-") | ||
|
||
def print_status(dr: Dryer): | ||
print(f"online: {dr.get_online()}") | ||
print(f"state: {dr.get_machine_state()}") | ||
print(f"door open: {dr.get_door_open()}") | ||
print(f"est time remaining: {dr.get_est_time_remaining()}") | ||
print(f"extra power changeable: {dr.get_status_extra_power_changeable()}") | ||
print(f"steam changeable: {dr.get_status_extra_steam_changeable()}") | ||
print(f"cycle select: {dr.get_status_cycle_select()}") | ||
print(f"dryness: {dr.get_status_dryness()}") | ||
print(f"manual dry time: {dr.get_status_manual_dry_time()}") | ||
print(f"static guard: {dr.get_status_static_guard()}") | ||
print(f"temperature: {dr.get_status_temperature()}") | ||
print(f"wrinkle shield: {dr.get_status_wrinkle_shield()}") | ||
print(f"airflow status: {dr.get_airflow_status()}") | ||
print(f"cool down: {dr.get_cool_down()}") | ||
print(f"damp: {dr.get_damp()}") | ||
print(f"drying: {dr.get_drying()}") | ||
print(f"limited cycle: {dr.get_limited_cycle()}") | ||
print(f"sensing: {dr.get_sensing()}") | ||
print(f"static reduce: {dr.get_static_reduce()}") | ||
print(f"steaming: {dr.get_steaming()}") | ||
print(f"wet: {dr.get_wet()}") | ||
print(f"cycle count: {dr.get_cycle_count()}") | ||
print(f"running hours: {dr.get_running_hours()}") | ||
print(f"total hours: {dr.get_total_hours()}") | ||
print(f"isp check: {dr.get_isp_check()}") | ||
print(f"rssi antenna diversity: {dr.get_rssi_antenna_diversity()}") | ||
|
||
print(f"set dryness: {dr.get_dryness()}") | ||
print(f"set manual dry time: {dr.get_manual_dry_time()}") | ||
print(f"set cycle select: {dr.get_cycle_select()}") | ||
print(f"set temperature: {dr.get_temperature()}") | ||
print(f"set wrinkle shield: {dr.get_wrinkle_shield()}") | ||
|
||
def attr_upd(): | ||
print("Attributes updated") | ||
|
||
dr.register_attr_callback(attr_upd) | ||
|
||
loop = True | ||
while loop: | ||
print_menu() | ||
choice = await aioconsole.ainput("Enter your choice: ") | ||
|
||
if choice == "p": | ||
print_status(dr) | ||
elif choice == "u": | ||
await dr.fetch_data() | ||
print_status(dr) | ||
elif choice == "v": | ||
print(json.dumps(dr._data_dict, indent=4)) | ||
elif choice == "c": | ||
cmd = await aioconsole.ainput("Command: ") | ||
val = await aioconsole.ainput("Value: ") | ||
await dr.send_attributes({cmd: val}) | ||
elif choice == "q": | ||
print("Bye") | ||
loop = False | ||
else: | ||
print("Wrong option selection. Enter any key to try again..") |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
from collections.abc import Callable | ||
from typing import Any | ||
|
||
import pytest | ||
from aioresponses import aioresponses | ||
from yarl import URL | ||
|
||
from whirlpool.appliancesmanager import AppliancesManager | ||
from whirlpool.auth import Auth | ||
from whirlpool.backendselector import BackendSelector | ||
from whirlpool.dryer import ( | ||
CycleSelect, | ||
Dryness, | ||
MachineState, | ||
Temperature, | ||
WrinkleShield, | ||
) | ||
|
||
|
||
async def test_attributes(appliances_manager: AppliancesManager): | ||
dryer = appliances_manager.dryers[0] | ||
assert dryer.get_machine_state() == MachineState.Standby | ||
assert dryer.get_door_open() is False | ||
assert dryer.get_est_time_remaining() == 1800 | ||
assert dryer.get_drum_light_on() == 0 | ||
lllucius marked this conversation as resolved.
Show resolved
Hide resolved
|
||
assert dryer.get_status_extra_steam_changeable() == 1 | ||
assert dryer.get_status_cycle_select() == 0 | ||
assert dryer.get_status_dryness() == 1 | ||
assert dryer.get_status_manual_dry_time() == 1 | ||
assert dryer.get_status_temperature() == 1 | ||
assert dryer.get_status_wrinkle_shield() == 1 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. lets remove the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not really sure about these. It "seems" that they are telling the caller whether that specific attribute can be changed or not. Maybe they should be more like:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ah! they inform the app if it should allow the user to change those settings trough the app? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. these where not updated. btw, if I got it right, these tell if the user can change the respective settings on the app? |
||
assert dryer.get_dryness() == Dryness.High | ||
assert dryer.get_manual_dry_time() == 1800 | ||
assert dryer.get_cycle_select() == CycleSelect.Timed_Dry | ||
assert dryer.get_airflow_status() == 0 | ||
assert dryer.get_cool_down() == 0 | ||
assert dryer.get_damp() == 0 | ||
assert dryer.get_drying() == 0 | ||
assert dryer.get_limited_cycle() == 0 | ||
assert dryer.get_sensing() == 0 | ||
assert dryer.get_static_reduce() == 0 | ||
assert dryer.get_steaming() == 0 | ||
assert dryer.get_wet() == 0 | ||
assert dryer.get_cycle_count() == 195 | ||
assert dryer.get_running_hours() == 148 | ||
assert dryer.get_total_hours() == 6302 | ||
assert dryer.get_rssi_antenna_diversity() == -51 | ||
assert dryer.get_damp_notification_tone_volume() == 0 | ||
assert dryer.get_alert_tone_volume() == 0 | ||
assert dryer.get_temperature() == Temperature.Cool | ||
assert dryer.get_wrinkle_shield() == WrinkleShield.Off | ||
|
||
|
||
@pytest.mark.parametrize( | ||
["method", "argument", "expected_json"], | ||
[ | ||
], | ||
lllucius marked this conversation as resolved.
Show resolved
Hide resolved
|
||
) | ||
async def test_setters( | ||
appliances_manager: AppliancesManager, | ||
auth: Auth, | ||
backend_selector: BackendSelector, | ||
aioresponses_mock: aioresponses, | ||
method: Callable, | ||
argument: Any, | ||
expected_json: dict, | ||
): | ||
dryer = appliances_manager.dryers[0] | ||
|
||
expected_payload = { | ||
"json": { | ||
"body": expected_json, | ||
"header": {"said": dryer.said, "command": "setAttributes"}, | ||
} | ||
} | ||
|
||
post_request_call_kwargs = { | ||
"url": backend_selector.appliance_command_url, | ||
"method": "POST", | ||
"data": None, | ||
"json": expected_payload["json"], | ||
"allow_redirects": True, | ||
"headers": auth.create_headers(), | ||
} | ||
|
||
url = backend_selector.appliance_command_url | ||
|
||
# add call, call method | ||
aioresponses_mock.post(url, payload=expected_payload) | ||
await method(dryer, argument) | ||
|
||
# assert args and length | ||
aioresponses_mock.assert_called_with(**post_request_call_kwargs) | ||
assert len(aioresponses_mock.requests[("POST", URL(url))]) == 1 |
lllucius marked this conversation as resolved.
Show resolved
Hide resolved
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
from collections.abc import Callable | ||
from typing import Any | ||
|
||
import pytest | ||
from aioresponses import aioresponses | ||
from yarl import URL | ||
|
||
from whirlpool.appliancesmanager import AppliancesManager | ||
from whirlpool.auth import Auth | ||
from whirlpool.backendselector import BackendSelector | ||
from whirlpool.washer import MachineState | ||
|
||
|
||
async def test_attributes(appliances_manager: AppliancesManager): | ||
washer = appliances_manager.washers[0] | ||
|
||
assert washer.get_machine_state() == MachineState.Standby | ||
assert washer.get_sensing() is False | ||
assert washer.get_filling() is False | ||
assert washer.get_soaking() is False | ||
assert washer.get_washing() is False | ||
assert washer.get_rinsing() is False | ||
assert washer.get_spinning() is False | ||
assert washer.get_dispense_1_level() == 4 | ||
assert washer.get_door_open() is True | ||
assert washer.get_time_remaining() == 4080 | ||
|
||
|
||
@pytest.mark.parametrize( | ||
["method", "argument", "expected_json"], | ||
[ | ||
], | ||
) | ||
async def test_setters( | ||
appliances_manager: AppliancesManager, | ||
auth: Auth, | ||
backend_selector: BackendSelector, | ||
aioresponses_mock: aioresponses, | ||
method: Callable, | ||
argument: Any, | ||
expected_json: dict, | ||
): | ||
washer = appliances_manager.washers[0] | ||
expected_payload = { | ||
"json": { | ||
"body": expected_json, | ||
"header": {"said": washer.said, "command": "setAttributes"}, | ||
} | ||
} | ||
|
||
post_request_call_kwargs = { | ||
"url": backend_selector.appliance_command_url, | ||
"method": "POST", | ||
"data": None, | ||
"json": expected_payload["json"], | ||
"allow_redirects": True, | ||
"headers": auth.create_headers(), | ||
} | ||
|
||
url = backend_selector.appliance_command_url | ||
|
||
# add call, call method | ||
aioresponses_mock.post(url, payload=expected_payload) | ||
await method(washer, argument) | ||
|
||
# assert args and length | ||
aioresponses_mock.assert_called_with(**post_request_call_kwargs) | ||
assert len(aioresponses_mock.requests[("POST", URL(url))]) == 1 | ||
lllucius marked this conversation as resolved.
Show resolved
Hide resolved
|
Uh oh!
There was an error while loading. Please reload this page.