def test_update_locations(self):
     smart_system = SmartSystem(email="*****@*****.**", password="******")
     print("Taille test : " + str(len(smart_system.locations)))
     api_mock = GardenaApiMock()
     m_sessions = api_mock.register_sessions()
     m_locations = api_mock.register_locations()
     api_mock.mount(smart_system)
     smart_system.authenticate()
     smart_system.update_locations()
     assert len(smart_system.locations) == 1
     assert (smart_system.locations["1c8b301f-22c8-423d-1b4d-ec25315d1377"].
             id == location_return["id"])
     assert (smart_system.locations["1c8b301f-22c8-423d-1b4d-ec25315d1377"].
             name == location_return["name"])
     assert m_sessions.call_count == 1
     assert m_locations.call_count == 1
 def test_get_all_powers(self):
     smart_system = SmartSystem(email="*****@*****.**", password="******")
     api_mock = GardenaApiMock()
     api_mock.register_sessions()
     api_mock.register_two_locations()
     m_devices = api_mock.register_devices()
     m_devices_2 = api_mock.register_second_location_devices()
     api_mock.mount(smart_system)
     smart_system.authenticate()
     smart_system.update_locations()
     smart_system.update_all_devices()
     assert len(smart_system.get_all_powers()) == 2
     assert (smart_system.locations["1c8b301f-22c8-423d-1b4d-ec25315d1377"].
             id == location_return["id"])
     assert (smart_system.locations["1c8b301f-22c8-423d-1b4d-ec25315d1377"].
             powers["c6e981e9-8ec6-438f-b400-c720d7f313c8"].name == "Power")
     assert (smart_system.locations["1c8b301f-22c8-423d-1b4d-ec25315d1378"].
             id == location_return_two["id"])
     assert (
         smart_system.locations["1c8b301f-22c8-423d-1b4d-ec25315d1378"].
         powers["c6e981e9-8ec6-438f-b400-c720d7f313c9"].name == "Power 2")
     assert m_devices.call_count == 1
     assert m_devices_2.call_count == 1
 def test_get_all_mowers(self):
     smart_system = SmartSystem(email="*****@*****.**", password="******")
     api_mock = GardenaApiMock()
     api_mock.register_sessions()
     api_mock.register_two_locations()
     m_devices = api_mock.register_devices()
     m_devices_2 = api_mock.register_second_location_devices()
     api_mock.mount(smart_system)
     smart_system.authenticate()
     smart_system.update_locations()
     smart_system.update_all_devices()
     assert len(smart_system.get_all_mowers()) == 2
     assert (smart_system.locations["1c8b301f-22c8-423d-1b4d-ec25315d1377"].
             id == location_return["id"])
     assert (smart_system.locations["1c8b301f-22c8-423d-1b4d-ec25315d1377"].
             mowers["e3c1b615-7351-25fc-a551-1908254a2b3e"].name == "Rosi")
     assert (smart_system.locations["1c8b301f-22c8-423d-1b4d-ec25315d1378"].
             id == location_return_two["id"])
     assert (
         smart_system.locations["1c8b301f-22c8-423d-1b4d-ec25315d1378"].
         mowers["e3c1b615-7351-25fc-a551-1908254a2b3f"].name == "Rosi 2")
     assert m_devices.call_count == 1
     assert m_devices_2.call_count == 1
 def test_get_all_water_controls(self):
     smart_system = SmartSystem(email="*****@*****.**", password="******")
     api_mock = GardenaApiMock()
     api_mock.register_sessions()
     api_mock.register_two_locations()
     m_devices = api_mock.register_devices()
     m_devices_2 = api_mock.register_second_location_devices()
     api_mock.mount(smart_system)
     smart_system.authenticate()
     smart_system.update_locations()
     smart_system.update_all_devices()
     assert len(smart_system.get_all_water_controls()) == 2
     assert (smart_system.locations["1c8b301f-22c8-423d-1b4d-ec25315d1377"].
             id == location_return["id"])
     assert (smart_system.locations["1c8b301f-22c8-423d-1b4d-ec25315d1377"].
             water_controls["d6259669-3241-488c-a88e-bcf3a07a58bf"].name ==
             "Water Control")
     assert (smart_system.locations["1c8b301f-22c8-423d-1b4d-ec25315d1378"].
             id == location_return_two["id"])
     assert (smart_system.locations["1c8b301f-22c8-423d-1b4d-ec25315d1378"].
             water_controls["d6259669-3241-488c-a88e-bcf3a07a58c0"].name ==
             "Water Control 2")
     assert m_devices.call_count == 1
     assert m_devices_2.call_count == 1
 def test_get_all_sensors(self):
     smart_system = SmartSystem(email="*****@*****.**", password="******")
     api_mock = GardenaApiMock()
     api_mock.register_sessions()
     api_mock.register_two_locations()
     m_devices = api_mock.register_devices()
     m_devices_2 = api_mock.register_second_location_devices()
     api_mock.mount(smart_system)
     smart_system.authenticate()
     smart_system.update_locations()
     smart_system.update_all_devices()
     assert len(smart_system.get_all_sensors()) == 2
     assert (smart_system.locations["1c8b301f-22c8-423d-1b4d-ec25315d1377"].
             id == location_return["id"])
     assert (
         smart_system.locations["1c8b301f-22c8-423d-1b4d-ec25315d1377"].
         sensors["a130596e-6627-4030-aea5-b6d2f24d0e03"].name == "Sensor")
     assert (smart_system.locations["1c8b301f-22c8-423d-1b4d-ec25315d1378"].
             id == location_return_two["id"])
     assert (
         smart_system.locations["1c8b301f-22c8-423d-1b4d-ec25315d1378"].
         sensors["a130596e-6627-4030-aea5-b6d2f24d0e04"].name == "Sensor 2")
     assert m_devices.call_count == 1
     assert m_devices_2.call_count == 1
 def test_get_all_gateways(self):
     smart_system = SmartSystem(email="*****@*****.**", password="******")
     api_mock = GardenaApiMock()
     api_mock.register_sessions()
     api_mock.register_two_locations()
     m_devices = api_mock.register_devices()
     m_devices_2 = api_mock.register_second_location_devices()
     api_mock.mount(smart_system)
     smart_system.authenticate()
     smart_system.update_locations()
     smart_system.update_all_devices()
     assert len(smart_system.get_all_gateways()) == 2
     assert (smart_system.locations["1c8b301f-22c8-423d-1b4d-ec25315d1377"].
             id == location_return["id"])
     assert (smart_system.locations["1c8b301f-22c8-423d-1b4d-ec25315d1377"].
             gateways["75cfc1f8-a20c-51d6-c5ea-1b5ecdde80c1"].name ==
             "Gardena Zentrale")
     assert (smart_system.locations["1c8b301f-22c8-423d-1b4d-ec25315d1378"].
             id == location_return_two["id"])
     assert (smart_system.locations["1c8b301f-22c8-423d-1b4d-ec25315d1378"].
             gateways["75cfc1f8-a20c-51d6-c5ea-1b5ecdde80c2"].name ==
             "Gardena Zentrale 2")
     assert m_devices.call_count == 1
     assert m_devices_2.call_count == 1
def try_connection(email, password, client_id):
    _LOGGER.debug("Trying to connect to Gardena during setup")
    smart_system = SmartSystem(email=email, password=password, client_id=client_id)
    smart_system.authenticate()
    smart_system.update_locations()
    _LOGGER.debug("Successfully connected to Gardena during setup")
Beispiel #8
0
    mqttclient.on_disconnect = on_mqtt_disconnect
    mqttclient.on_message = on_mqtt_message
    mqttclient.will_set(f"{mqttprefix}/connected", "0", 0, True)
    mqttthread = Thread(target=mqttclient.loop_forever)

    mqttclientconnected = False

    logging.info('===== Prepare SmartSystem Client =====')
    logging.info(' - create')
    smart_system = SmartSystem(email=gardenauser,
                               password=gardenapassword,
                               client_id=gardenaapikey)
    logging.info(' - authenticate')
    smart_system.authenticate()
    logging.info(' - update location list')
    smart_system.update_locations()
    for location in smart_system.locations.values():
        logging.info(f' - update device list for location : {location.name}')
        smart_system.update_devices(location)

    # add callbacks
    smart_system.add_ws_status_callback(on_ws_status_changed)
    for device in location.devices.values():
        device.add_callback(on_device_update)

    smartsystemclientconnected = False

    logging.info('===== Connection To MQTT Broker =====')
    mqttclient.connect(mqtthost, mqttport)
    mqttthread.start()
 def test_update_locations_failed(self):
     smart_system = SmartSystem(email="*****@*****.**", password="******")
     init_failed_mock(smart_system)
     smart_system.authenticate()
     with pytest.raises(HTTPError):
         smart_system.update_locations()