Skip to content
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

Provide data model #76

Closed
wants to merge 24 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
e38b086
Move event socket to Appliances Manager
Jan 8, 2025
3b65925
Update tests to support recent changes
Jan 8, 2025
1b16b52
Let the Appliance actually manage it's own data
Jan 9, 2025
af20b58
Seperate WasherDryer into Washer and Dryer
Jan 9, 2025
137c361
Add tests for dryer and washer
Jan 9, 2025
16b9907
Move more of the event processing to Appliance
Jan 9, 2025
a1a87b3
Merge branch 'move_event_socket_to_app_manager' into washer_dryer_split
Jan 9, 2025
abfdaf1
Move device creation to a "registry"
Jan 9, 2025
9a48d16
Missed changing send_attributes() definition
Jan 9, 2025
8a18f1b
Merge branch 'move_event_socket_to_app_manager' into washer_dryer_split
Jan 9, 2025
87141ea
Merge branch 'move_event_socket_to_app_manager' into device_registry
Jan 9, 2025
520d996
Forgot to change calls to send_attributes as well
Jan 9, 2025
f87fd3c
Merge branch 'move_event_socket_to_app_manager' into washer_dryer_split
Jan 9, 2025
0a5ae8c
Merge branch 'move_event_socket_to_app_manager' into device_registry
Jan 9, 2025
7847b0a
Merge branch 'master' into device_registry
lllucius Jan 9, 2025
1a6bfeb
Merge branch 'master' into washer_dryer_split
lllucius Jan 9, 2025
bc27e2c
Merge branch 'master' into move_event_socket_to_app_manager
lllucius Jan 9, 2025
079e639
Fix Ruff findings
Jan 10, 2025
fc4fbcd
Merge branch 'move_event_socket_to_app_manager' into washer_dryer_split
Jan 10, 2025
007ecca
Fix Ruff findings
Jan 10, 2025
96b1e67
Merge branch 'washer_dryer_split' into device_registry
Jan 10, 2025
92cc813
Fix Ruff findings
Jan 10, 2025
7923183
Provide basic data model handling
Jan 10, 2025
7fac2c2
Fix Ruff findings
Jan 10, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 25 additions & 25 deletions cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
import aiohttp

from cli_ac_menu import show_aircon_menu
from cli_dryer_menu import show_dryer_menu
from cli_oven_menu import show_oven_menu
from cli_refrigerator_menu import show_refrigerator_menu
from cli_washerdryer_menu import show_washerdryer_menu
from cli_washer_menu import show_washer_menu
from whirlpool.appliancesmanager import AppliancesManager
from whirlpool.auth import Auth
from whirlpool.backendselector import BackendSelector, Brand, Region
from whirlpool.backendselector import BackendSelector
from whirlpool.types import ApplianceKind, Brand, Region

logging.basicConfig(format="%(asctime)s [%(name)s %(levelname)s]: %(message)s")
logger = logging.getLogger("whirlpool")
Expand All @@ -35,9 +37,6 @@


async def start():
def attr_upd():
logger.info("Attributes updated")

if args.brand == "whirlpool":
selected_brand = Brand.Whirlpool
elif args.brand == "maytag":
Expand Down Expand Up @@ -70,34 +69,35 @@ def attr_upd():

if args.list:
print(appliance_manager.aircons)
print(appliance_manager.washer_dryers)
print(appliance_manager.dryer)
print(appliance_manager.ovens)
print(appliance_manager.refrigerators)
print(appliance_manager.washers)
return

if not args.said:
logger.error("No appliance specified")
return

for ac_data in appliance_manager.aircons:
if ac_data["SAID"] == args.said:
await show_aircon_menu(backend_selector, auth, args.said, session)
return

for wd_data in appliance_manager.washer_dryers:
if wd_data["SAID"] == args.said:
await show_washerdryer_menu(backend_selector, auth, args.said, session)
return

for mo_data in appliance_manager.ovens:
if mo_data["SAID"] == args.said:
await show_oven_menu(backend_selector, auth, args.said, session)
return

for rf_data in appliance_manager.refrigerators:
if rf_data["SAID"] == args.said:
await show_refrigerator_menu(backend_selector, auth, args.said, session)
return
app = appliance_manager.get_appliance(args.said)
if not app:
logger.error(f"{args.said} wasn't found")
return

await appliance_manager.connect()

match app.Kind:
case ApplianceKind.AirCon:
await show_aircon_menu(app)
case ApplianceKind.Dryer:
await show_dryer_menu(app)
case ApplianceKind.Oven:
await show_oven_menu(app)
case ApplianceKind.Refrigerator:
await show_refrigerator_menu(app)
case ApplianceKind.Washer:
await show_washer_menu(app)

await appliance_manager.disconnect()

asyncio.run(start())
5 changes: 1 addition & 4 deletions cli_ac_menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from whirlpool.aircon import Aircon, Mode


async def show_aircon_menu(backend_selector, auth, said, session):
async def show_aircon_menu(ac: Aircon) -> None:
def print_menu():
print("\n")
print(30 * "-", "MENU", 30 * "-")
Expand Down Expand Up @@ -46,9 +46,7 @@ def print_status(ac: Aircon):
def attr_upd():
print("Attributes updated")

ac = Aircon(backend_selector, auth, said, session)
ac.register_attr_callback(attr_upd)
await ac.connect()

loop = True
while loop:
Expand Down Expand Up @@ -95,7 +93,6 @@ def attr_upd():
val = await aioconsole.ainput("Value: ")
await ac.send_attributes({cmd: val})
elif choice == "q":
await ac.disconnect()
print("Bye")
loop = False
else:
Expand Down
76 changes: 76 additions & 0 deletions cli_dryer_menu.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import aioconsole

from whirlpool.dryer import Dryer


async def show_dryer_menu(dr: Dryer) -> None:
def print_menu() -> None:
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) -> None:
print(f"online: {dr.get_online()}")
print(f"state: {dr.get_machine_state_value()}")
print(f"door open: {dr.get_op_status_dooropen()}")
print(f"est time remaining: {dr.get_time_status_est_time_remaining()}")
print(f"extra power changeable: {dr.get_change_status_extrapowerchangeable()}")
print(f"steam changeable: {dr.get_change_status_steamchangeable()}")
print(f"cycle select: {dr.get_change_status_cycleselect()}")
print(f"dryness: {dr.get_change_status_dryness()}")
print(f"manual dry time: {dr.get_change_status_manualdrytime()}")
print(f"static guard: {dr.get_change_status_staticguard()}")
print(f"temperature: {dr.get_change_status_temperature()}")
print(f"wrinkle shield: {dr.get_change_status_wrinkleshield()}")
print(f"airflow status: {dr.get_cycle_status_airflow_status()}")
print(f"cool down: {dr.get_cycle_status_cool_down()}")
print(f"damp: {dr.get_cycle_status_damp()}")
print(f"drying: {dr.get_cycle_status_drying()}")
print(f"limited cycle: {dr.get_cycle_status_limited_cycle()}")
print(f"sensing: {dr.get_cycle_status_sensing()}")
print(f"static reduce: {dr.get_cycle_status_static_reduce()}")
print(f"steaming: {dr.get_cycle_status_steaming()}")
print(f"wet: {dr.get_cycle_status_wet()}")
print(f"cycle count: {dr.get_odometer_status_cycle_count()}")
print(f"running hours: {dr.get_odometer_status_running_hours()}")
print(f"total hours: {dr.get_odometer_status_total_hours()}")
print(f"isp check: {dr.get_wifi_status_isp_check()}")
print(f"rssi antenna diversity: {dr.get_wifi_status_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()}")

def attr_upd() -> None:
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(dr._data_dict)
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..")

dr.unregister_attr_callback(attr_upd)
7 changes: 3 additions & 4 deletions cli_oven_menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from whirlpool.oven import Cavity, CookMode, KitchenTimerState, Oven


async def show_oven_menu(backend_selector, auth, said, session):
async def show_oven_menu(ov: Oven) -> None:
def print_menu():
print("\n")
print(30 * "-", "MENU", 30 * "-")
Expand Down Expand Up @@ -65,9 +65,7 @@ def print_status(ov: Oven):
def attr_upd():
print("Attributes updated")

ov = Oven(backend_selector, auth, said, session)
ov.register_attr_callback(attr_upd)
await ov.connect()

loop = True
while loop:
Expand Down Expand Up @@ -130,8 +128,9 @@ def attr_upd():
val = await aioconsole.ainput("Value: ")
await ov.send_attributes({cmd: val})
elif choice == "q":
await ov.disconnect()
print("Bye")
loop = False
else:
print("Wrong option selection. Enter any key to try again..")

ov.unregister_attr_callback(attr_upd)
7 changes: 3 additions & 4 deletions cli_refrigerator_menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from whirlpool.refrigerator import Refrigerator


async def show_refrigerator_menu(backend_selector, auth, said, session):
async def show_refrigerator_menu(rf: Refrigerator) -> None:
def print_menu():
print("\n")
print(30 * "-", "MENU", 30 * "-")
Expand Down Expand Up @@ -31,9 +31,7 @@ def print_status(bc: Refrigerator):
def attr_upd():
print("Attributes updated")

rf = Refrigerator(backend_selector, auth, said, session)
rf.register_attr_callback(attr_upd)
await rf.connect()

loop = True
while loop:
Expand Down Expand Up @@ -65,8 +63,9 @@ def attr_upd():
val = await aioconsole.ainput("Value: ")
await rf.send_attributes({cmd: val})
elif choice == "q":
await rf.disconnect()
print("Bye")
loop = False
else:
print("Wrong option selection. Enter any key to try again..")

rf.unregister_attr_callback(attr_upd)
54 changes: 54 additions & 0 deletions cli_washer_menu.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import aioconsole

from whirlpool.washer import Washer


async def show_washer_menu(wr: Washer) -> 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(wr: Washer):
print("online: " + str(wr.get_online()))
print("state: " + str(wr.get_machine_state()))
print("sensing: " + str(wr.get_cycle_status_sensing()))
print("filling: " + str(wr.get_cycle_status_filling()))
print("soaking: " + str(wr.get_cycle_status_soaking()))
print("washing: " + str(wr.get_cycle_status_washing()))
print("rinsing: " + str(wr.get_cycle_status_rinsing()))
print("spinning: " + str(wr.get_cycle_status_spinning()))

def attr_upd():
print("Attributes updated")

wr.register_attr_callback(attr_upd)

loop = True
while loop:
print_menu()
choice = await aioconsole.ainput("Enter your choice: ")

if choice == "p":
print_status(wr)
elif choice == "u":
await wr.fetch_data()
print_status(wr)
elif choice == "v":
print(wr._data_dict)
elif choice == "c":
cmd = await aioconsole.ainput("Command: ")
val = await aioconsole.ainput("Value: ")
await wr.send_attributes({cmd: val})
elif choice == "q":
print("Bye")
loop = False
else:
print("Wrong option selection. Enter any key to try again..")

wr.unregister_attr_callback(attr_upd)
55 changes: 0 additions & 55 deletions cli_washerdryer_menu.py

This file was deleted.

Loading
Loading