Exemplo n.º 1
0
async def test_attributes(caplog, aio_httpclient):
    caplog.set_level(logging.DEBUG)
    auth = MagicMock()

    aio_httpclient.get.return_value = MockResponse(json.dumps(DATA1), 200)

    aircon = Aircon(BackendSelectorMock(), auth, SAID, None)
    await aircon.connect()
    assert aircon.get_online() is False
    assert aircon.get_power_on() is False
    assert aircon.get_display_on() is False
    assert aircon.get_current_temp() == 23
    assert aircon.get_current_humidity() == 56
    assert aircon.get_temp() == 30
    assert aircon.get_humidity() == 40
    assert aircon.get_mode() == Mode.Heat
    assert aircon.get_sixthsense_mode() is False
    assert aircon.get_fanspeed() == FanSpeed.Off
    assert aircon.get_h_louver_swing() is True
    assert aircon.get_turbo_mode() is False
    assert aircon.get_eco_mode() is False
    assert aircon.get_quiet_mode() is False
    await aircon.disconnect()

    aio_httpclient.get.return_value = MockResponse(json.dumps(DATA2), 200)
    await aircon.connect()
    assert aircon.get_online() is True
    assert aircon.get_power_on() is True
    assert aircon.get_display_on() is True
    assert aircon.get_current_temp() == 30
    assert aircon.get_current_humidity() == 31
    assert aircon.get_temp() == 29
    assert aircon.get_humidity() == 45
    assert aircon.get_mode() == Mode.Fan
    assert aircon.get_sixthsense_mode() is True
    assert aircon.get_fanspeed() == FanSpeed.Auto
    assert aircon.get_h_louver_swing() is False
    assert aircon.get_turbo_mode() is True
    assert aircon.get_eco_mode() is True
    assert aircon.get_quiet_mode() is True
    await aircon.disconnect()
Exemplo n.º 2
0
 def print_status(ac: Aircon):
     print("online: " + str(ac.get_online()))
     print("power_on: " + str(ac.get_power_on()))
     print("temp: " + str(ac.get_temp()))
     print("humidity: " + str(ac.get_humidity()))
     print("current_temp: " + str(ac.get_current_temp()))
     print("current_humidity: " + str(ac.get_current_humidity()))
     print("mode: " + str(ac.get_mode()))
     print("sixthsense_mode: " + str(ac.get_sixthsense_mode()))
     print("fanspeed: " + str(ac.get_fanspeed()))
     print("h_louver_swing: " + str(ac.get_h_louver_swing()))
     print("turbo_mode: " + str(ac.get_turbo_mode()))
     print("eco_mode: " + str(ac.get_eco_mode()))
     print("quiet_mode: " + str(ac.get_quiet_mode()))
     print("display_on: " + str(ac.get_display_on()))
Exemplo n.º 3
0
async def show_aircon_menu(backend_selector, auth, said):
    def print_menu():
        print("\n")
        print(30 * "-", "MENU", 30 * "-")
        print("1. Turn on")
        print("0. Turn off")
        print("+. Temp up")
        print("-. Temp down")
        print("C. Mode: Cool")
        print("H. Mode: Heat")
        print("F. Mode: Fan")
        print("S. Mode: Sixth Sense")
        print("2. Swing toggle")
        print("3. Turbo toggle")
        print("4. Eco toggle")
        print("5. Quiet toggle")
        print("6. Display toggle")
        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(ac: Aircon):
        print("online: " + str(ac.get_online()))
        print("power_on: " + str(ac.get_power_on()))
        print("temp: " + str(ac.get_temp()))
        print("humidity: " + str(ac.get_humidity()))
        print("current_temp: " + str(ac.get_current_temp()))
        print("current_humidity: " + str(ac.get_current_humidity()))
        print("mode: " + str(ac.get_mode()))
        print("sixthsense_mode: " + str(ac.get_sixthsense_mode()))
        print("fanspeed: " + str(ac.get_fanspeed()))
        print("h_louver_swing: " + str(ac.get_h_louver_swing()))
        print("turbo_mode: " + str(ac.get_turbo_mode()))
        print("eco_mode: " + str(ac.get_eco_mode()))
        print("quiet_mode: " + str(ac.get_quiet_mode()))
        print("display_on: " + str(ac.get_display_on()))

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

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

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

        if choice == "1":
            await ac.set_power_on(True)
        elif choice == "0":
            await ac.set_power_on(False)
        elif choice == "+":
            temp = ac.get_temp() + 1
            await ac.set_temp(temp)
        elif choice == "-":
            temp = ac.get_temp() - 1
            await ac.set_temp(temp)
        elif choice == "C":
            await ac.set_mode(Mode.Cool)
        elif choice == "H":
            await ac.set_mode(Mode.Heat)
        elif choice == "F":
            await ac.set_mode(Mode.Fan)
        elif choice == "S":
            await ac.set_mode(Mode.SixthSense)
        elif choice == "2":
            await ac.set_h_louver_swing(not ac.get_h_louver_swing())
        elif choice == "3":
            await ac.set_turbo_mode(not ac.get_turbo_mode())
        elif choice == "4":
            await ac.set_eco_mode(not ac.get_eco_mode())
        elif choice == "5":
            await ac.set_quiet_mode(not ac.get_quiet_mode())
        elif choice == "6":
            await ac.set_display_on(not ac.get_display_on())
        elif choice == "p":
            print_status(ac)
        elif choice == "u":
            await ac.fetch_data()
            print_status(ac)
        elif choice == "v":
            print(ac._data_dict)
        elif choice == "c":
            cmd = aioconsole.ainput("Command: ")
            val = aioconsole.ainput("Value: ")
            await ac.send_attributes({cmd: val})
        elif choice == "q":
            await ac.disconnect()
            auth.cancel_auto_renewal()
            print("Bye")
            loop = False
        else:
            print("Wrong option selection. Enter any key to try again..")