Exemple #1
0
 def setup_method(self, method):
     self.sm = SmartSystem(email="login",
                           password="******",
                           client_id="client_id")
     loc = Location(self.sm, location_fixture)
     self.sm.locations[loc.id] = loc
     device = Mower(self.sm, mower_fixture)
     loc.add_device(device)
Exemple #2
0
 def test_get_devices_failed(self):
     smart_system = SmartSystem(email="*****@*****.**", password="******")
     init_failed_mock(smart_system)
     smart_system.authenticate()
     location = Location(smart_system=smart_system)
     location.update_information(location_return)
     with pytest.raises(HTTPError):
         location.update_devices()
Exemple #3
0
 def test_update_devices(self):
     location = Location(smart_system=self.smart_system_test_info)
     location.update_information(location_return)
     location.update_devices()
     assert self.m_devices.call_count == 1
     assert len(location.gateways) == 1
     assert len(location.mowers) == 1
     assert len(location.sensors) == 1
     assert len(location.water_controls) == 1
     assert len(location.powers) == 1
 def update_locations(self):
     response_data = self.__call_smart_system_get(
         f"{self.SMART_HOST}/v1/locations")
     if len(response_data["data"]) < 1:
         self.logger.error("No location found....")
     else:
         self.locations = {}
         for location in response_data["data"]:
             new_location = Location(self, location)
             new_location.update_location_data(location)
             self.locations[new_location.id] = new_location
Exemple #5
0
 def test_device_informations(self):
     location = Location(smart_system=self.smart_system_test_info)
     location.update_information(location_return)
     location.update_devices()
     assert self.m_devices.call_count == 1
     assert len(location.gateways) == 1
     assert len(location.mowers) == 1
     assert "75cfc1f8-a20c-51d6-c5ea-1b5ecdde80c1" in location.gateways.keys()
     assert "e3c1b615-7351-25fc-a551-1908254a2b3e" in location.mowers.keys()
     assert "a130596e-6627-4030-aea5-b6d2f24d0e03" in location.sensors.keys()
     assert "d6259669-3241-488c-a88e-bcf3a07a58bf" in location.water_controls.keys()
     assert "c6e981e9-8ec6-438f-b400-c720d7f313c8" in location.powers.keys()
Exemple #6
0
 def update_locations(self):
     """Update locations (gardens, ..) """
     url = "https://smart.gardena.com/sg-1/locations/"
     params = (("user_id", self.user_id),)
     response = self.request_session.get(
         url, headers=self.create_header(), params=params
     )
     response.raise_for_status()
     response_data = json.loads(response.content.decode("utf-8"))
     for location in response_data["locations"]:
         if location["id"] not in self.locations:
             self.locations[location["id"]] = Location(smart_system=self)
         self.locations[location["id"]].update_information(location)
Exemple #7
0
 def test_location_information(self):
     location = Location(smart_system=self.smart_system_test_info)
     location.update_information(location_return)
     assert location.id == location_return["id"]
     assert location.name == location_return["name"]
     assert location.latitude == location_return["geo_position"]["latitude"]
     assert location.longitude == location_return["geo_position"]["longitude"]
     assert location.address == location_return["geo_position"]["address"]
     assert location.city == location_return["geo_position"]["city"]
     assert location.sunrise == location_return["geo_position"]["sunrise"]
     assert location.sunset == location_return["geo_position"]["sunset"]
     assert location.time_zone == location_return["geo_position"]["time_zone"]
     assert (
         location.time_zone_offset
         == location_return["geo_position"]["time_zone_offset"]
     )
Exemple #8
0
 def test_update_devices_unknown_category(self):
     location = Location(smart_system=self.smart_system_test_info)
     location.update_information(location_return)
     location.update_devices()
     assert self.m_devices.call_count == 1
     assert len(location.gateways) == 1
     assert len(location.mowers) == 1
     assert len(location.sensors) == 1
     assert len(location.water_controls) == 1
     assert len(location.powers) == 1
     location.add_or_update_device(
         device={
             "id": "75cfc1f8-a20c-51d6-c5ea-1b5eccce80c1",
             "name": "Unknown device",
             "description": "Unknown device",
             "category": "unknown_category",
         }
     )
     assert len(location.gateways) == 1
     assert len(location.mowers) == 1
     assert len(location.sensors) == 1
     assert len(location.water_controls) == 1
     assert len(location.powers) == 1
Exemple #9
0
 def test_init_exception_without_smart_system(self):
     with pytest.raises(ValueError):
         Location()
Exemple #10
0
 def test_init(self):
     location = Location(smart_system=self.smart_system_test_info)
     assert location.smart_system == self.smart_system_test_info
def get_location_fixture(
        smart_system=SmartSystemFixture.get_smart_system_fixture()):
    return Location(smart_system=smart_system)
Exemple #12
0
 def test_location(self):
     loc = Location(self.sm, location_fixture)
     assert loc.id == "753aecac-4c46-470e-aa96-d92436f11e77"
     assert loc.name == "My Garden"