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

Move event socket to Appliances Manager #72

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
27 changes: 16 additions & 11 deletions cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,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 @@ -80,23 +77,31 @@ def attr_upd():
return

for ac_data in appliance_manager.aircons:
if ac_data["SAID"] == args.said:
await show_aircon_menu(backend_selector, auth, args.said, session)
if ac_data.said == args.said:
await show_aircon_menu(
appliance_manager, backend_selector, auth, session, ac_data
)
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)
if wd_data.said == args.said:
await show_washerdryer_menu(
appliance_manager, backend_selector, auth, session, wd_data
)
return

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

for rf_data in appliance_manager.refrigerators:
if rf_data["SAID"] == args.said:
await show_refrigerator_menu(backend_selector, auth, args.said, session)
if rf_data.said == args.said:
await show_refrigerator_menu(
appliance_manager, backend_selector, auth, session, rf_data
)
return


Expand Down
20 changes: 16 additions & 4 deletions cli_ac_menu.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
import aioconsole
import aiohttp

from whirlpool.aircon import Aircon, Mode
from whirlpool.appliancesmanager import AppliancesManager
from whirlpool.auth import Auth
from whirlpool.backendselector import BackendSelector
from whirlpool.types import ApplianceData


async def show_aircon_menu(backend_selector, auth, said, session):
async def show_aircon_menu(
manager: AppliancesManager,
backend_selector: BackendSelector,
auth: Auth,
session: aiohttp.ClientSession,
app_data: ApplianceData
) -> None:
def print_menu():
print("\n")
print(30 * "-", "MENU", 30 * "-")
Expand Down Expand Up @@ -46,9 +57,9 @@ def print_status(ac: Aircon):
def attr_upd():
print("Attributes updated")

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

loop = True
while loop:
Expand Down Expand Up @@ -95,8 +106,9 @@ 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:
print("Wrong option selection. Enter any key to try again..")

await manager.disconnect()
20 changes: 16 additions & 4 deletions cli_oven_menu.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
import aioconsole
import aiohttp

from whirlpool.appliancesmanager import AppliancesManager
from whirlpool.auth import Auth
from whirlpool.backendselector import BackendSelector
from whirlpool.oven import Cavity, CookMode, KitchenTimerState, Oven
from whirlpool.types import ApplianceData


async def show_oven_menu(backend_selector, auth, said, session):
async def show_oven_menu(
manager: AppliancesManager,
backend_selector: BackendSelector,
auth: Auth,
session: aiohttp.ClientSession,
app_data: ApplianceData
) -> None:
def print_menu():
print("\n")
print(30 * "-", "MENU", 30 * "-")
Expand Down Expand Up @@ -65,9 +76,9 @@ def print_status(ov: Oven):
def attr_upd():
print("Attributes updated")

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

loop = True
while loop:
Expand Down Expand Up @@ -130,8 +141,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..")

await manager.disconnect()
20 changes: 16 additions & 4 deletions cli_refrigerator_menu.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
import aioconsole
import aiohttp

from whirlpool.appliancesmanager import AppliancesManager
from whirlpool.auth import Auth
from whirlpool.backendselector import BackendSelector
from whirlpool.refrigerator import Refrigerator
from whirlpool.types import ApplianceData


async def show_refrigerator_menu(backend_selector, auth, said, session):
async def show_refrigerator_menu(
manager: AppliancesManager,
backend_selector: BackendSelector,
auth: Auth,
session: aiohttp.ClientSession,
app_data: ApplianceData
) -> None:
def print_menu():
print("\n")
print(30 * "-", "MENU", 30 * "-")
Expand Down Expand Up @@ -31,9 +42,9 @@ def print_status(bc: Refrigerator):
def attr_upd():
print("Attributes updated")

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

loop = True
while loop:
Expand Down Expand Up @@ -65,8 +76,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..")

await manager.disconnect()
20 changes: 16 additions & 4 deletions cli_washerdryer_menu.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
import aioconsole
import aiohttp

from whirlpool.appliancesmanager import AppliancesManager
from whirlpool.auth import Auth
from whirlpool.backendselector import BackendSelector
from whirlpool.types import ApplianceData
from whirlpool.washerdryer import WasherDryer


async def show_washerdryer_menu(backend_selector, auth, said, session):
async def show_washerdryer_menu(
manager: AppliancesManager,
backend_selector: BackendSelector,
auth: Auth,
session: aiohttp.ClientSession,
app_data: ApplianceData
) -> None:
def print_menu():
print("\n")
print(30 * "-", "MENU", 30 * "-")
Expand All @@ -27,9 +38,9 @@ def print_status(wd: WasherDryer):
def attr_upd():
print("Attributes updated")

wd = WasherDryer(backend_selector, auth, said, session)
wd = WasherDryer(backend_selector, auth, session, app_data)
wd.register_attr_callback(attr_upd)
await wd.connect()
await manager.connect()

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

await manager.disconnect()
72 changes: 59 additions & 13 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from whirlpool.auth import Auth
from whirlpool.oven import Oven
from whirlpool.refrigerator import Refrigerator
from whirlpool.types import ApplianceData
from whirlpool.washerdryer import WasherDryer

SAID = "WPR1XYZABC123"
Expand Down Expand Up @@ -44,35 +45,80 @@ def auth_fixture(backend_selector_mock, client_session_fixture):


@pytest.fixture(name="oven")
def oven_fixture(backend_selector_mock, auth_fixture, client_session_fixture):
with patch("whirlpool.appliance.Appliance._create_headers", return_value={}):
oven = Oven(backend_selector_mock, auth_fixture, SAID, client_session_fixture)
async def oven_fixture(
backend_selector_mock, auth_fixture, client_session_fixture
):
app_data = ApplianceData(
said=SAID,
name="Oven",
data_model="RANGE_DATA_MODEL",
category="Cooking",
model_number="WRO1234XX1",
serial_number="RO12345678",
)

with patch("whirlpool.appliance.Auth._create_headers", return_value={}):
oven = Oven(
backend_selector_mock, auth_fixture, client_session_fixture, app_data
)
yield oven


@pytest.fixture(name="washer_dryer")
def washer_dryer_fixture(backend_selector_mock, auth_fixture, client_session_fixture):
with patch("whirlpool.appliance.Appliance._create_headers", return_value={}):
def washer_dryer_fixture(
backend_selector_mock, auth_fixture, client_session_fixture
):
app_data = ApplianceData(
said=SAID,
name="Washer/Dryer AIO",
data_model="WASHDRY_DATA_MODEL",
category="FabricCare",
model_number="WWD1234XX1",
serial_number="WD12345678",
)

with patch("whirlpool.appliance.Auth._create_headers", return_value={}):
washer_dryer = WasherDryer(
backend_selector_mock, auth_fixture, SAID, client_session_fixture
backend_selector_mock, auth_fixture, client_session_fixture, app_data
)
yield washer_dryer


@pytest.fixture(name="aircon")
def aircon_fixture(backend_selector_mock, auth_fixture, client_session_fixture):
with patch("whirlpool.appliance.Appliance._create_headers", return_value={}):
def aircon_fixture(
backend_selector_mock, auth_fixture, client_session_fixture
):
app_data = ApplianceData(
said=SAID,
name="Air Conditioner",
data_model="AIRCON_DATA_MODEL",
category="Climate",
model_number="WAC1234XX1",
serial_number="AC12345678",
)

with patch("whirlpool.appliance.Auth._create_headers", return_value={}):
aircon = Aircon(
backend_selector_mock, auth_fixture, SAID, client_session_fixture
backend_selector_mock, auth_fixture, client_session_fixture, app_data
)
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={}):
def refrigerator_fixture(
backend_selector_mock, auth_fixture, client_session_fixture
):
app_data = ApplianceData(
said=SAID,
name="Refrigerator",
data_model="FRIG_DATA_MODEL",
category="Kitchen",
model_number="WFR1234XX1",
serial_number="FR12345678",
)

with patch("whirlpool.appliance.Auth._create_headers", return_value={}):
refrigerator = Refrigerator(
backend_selector_mock, auth_fixture, SAID, client_session_fixture
backend_selector_mock, auth_fixture, client_session_fixture, app_data
)
yield refrigerator

Expand Down
Loading
Loading