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

Consul beer fridges integration #63

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
14 changes: 13 additions & 1 deletion cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

from cli_ac_menu import show_aircon_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 whirlpool.appliancesmanager import AppliancesManager
from whirlpool.auth import Auth
Expand All @@ -22,7 +23,10 @@
parser.add_argument("-e", "--email", help="Email address")
parser.add_argument("-p", "--password", help="Password")
parser.add_argument(
"-b", "--brand", help="Brand (whirlpool/maytag/kitchenaid)", default="whirlpool"
"-b",
"--brand",
help="Brand (whirlpool/maytag/kitchenaid/consul)",
default="whirlpool",
)
parser.add_argument("-r", "--region", help="Region (EU/US)", default="EU")
parser.add_argument("-l", "--list", help="List appliances", action="store_true")
Expand All @@ -40,6 +44,8 @@ def attr_upd():
selected_brand = Brand.Maytag
elif args.brand == "kitchenaid":
selected_brand = Brand.KitchenAid
elif args.brand == "consul":
selected_brand = Brand.Consul
else:
logger.error("Invalid brand argument")
return
Expand All @@ -66,6 +72,7 @@ def attr_upd():
print(appliance_manager.aircons)
print(appliance_manager.washer_dryers)
print(appliance_manager.ovens)
print(appliance_manager.refrigerators)
return

if not args.said:
leandrocaldas marked this conversation as resolved.
Show resolved Hide resolved
Expand All @@ -87,5 +94,10 @@ def attr_upd():
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


asyncio.run(start())
72 changes: 72 additions & 0 deletions cli_refrigerator_menu.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import aioconsole

from whirlpool.refrigerator import Refrigerator


async def show_refrigerator_menu(backend_selector, auth, said, session):
def print_menu():
print("\n")
print(30 * "-", "MENU", 30 * "-")
print("+. Temp up")
print("-. Temp down")
print("-4. Set -4°C")
print("-2. Set -2°C")
print("0. Set 0°C")
print("3. Set 3°C")
print("5. Set 5°C")
print("t. Turbo toggle")
print("l. Display lock toggle")
print("u. Update status from server")
print("p. Print status")
print("r. Print raw status")
print("c. Custom command")
print("q. Exit")
print(67 * "-")

def print_status(bc: Refrigerator):
print("current_temp: " + str(rf.get_offset_temp()) + "°C")
print("turbo_mode: " + str(rf.get_turbo_mode()))
print("display_locked: " + str(rf.get_display_lock()))

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:
print_menu()
choice = await aioconsole.ainput("Enter your choice: ")

if choice == "+":
temp = rf.get_temp() - 1
await rf.set_temp(temp)
elif choice == "-":
temp = rf.get_temp() + 1
leandrocaldas marked this conversation as resolved.
Show resolved Hide resolved
await rf.set_temp(temp)
elif choice in ["-4", "-2", "0", "3", "5"]:
temp = int(choice)
await rf.set_offset_temp(temp)
elif choice == "t":
await rf.set_turbo_mode(not rf.get_turbo_mode())
elif choice == "l":
await rf.set_display_lock(not rf.get_display_lock())
elif choice == "p":
print_status(rf)
elif choice == "u":
await rf.fetch_data()
print_status(rf)
elif choice == "r":
print(rf._data_dict)
elif choice == "c":
cmd = await aioconsole.ainput("Command: ")
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..")
10 changes: 10 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from whirlpool.appliancesmanager import AppliancesManager
from whirlpool.auth import Auth
from whirlpool.oven import Oven
from whirlpool.refrigerator import Refrigerator
from whirlpool.washerdryer import WasherDryer

SAID = "WPR1XYZABC123"
Expand Down Expand Up @@ -67,6 +68,15 @@ def aircon_fixture(backend_selector_mock, auth_fixture, client_session_fixture):
yield aircon


@pytest.fixture(name="refrigerator")
def refrigerator_fixture(backend_selector_mock, auth_fixture, client_session_fixture):
with patch("whirlpool.appliance.Appliance._create_headers", return_value={}):
refrigerator = Refrigerator(
backend_selector_mock, auth_fixture, SAID, client_session_fixture
)
yield refrigerator


@pytest.fixture(name="appliances_manager")
def appliances_manager_fixture(
backend_selector_mock, auth_fixture, client_session_fixture
Expand Down
Loading
Loading