async def test_client_replace(self, sync, func, attr, ret_value, assert_value): """Test the base client functions with 200.""" if sync: resp = MockResponseSync(ret_value, 200) with patch("requests.request", return_value=resp): indego = IndegoClient(**test_config) indego._online = True indego._userid = "test_user_id" func(indego) assert getattr(indego, attr) == assert_value func(indego) assert getattr(indego, attr) == assert_value else: resp = MockResponseAsync(ret_value, 200) with patch("aiohttp.ClientSession.request", return_value=resp), patch( "pyIndego.IndegoAsyncClient.start", return_value=True ): async with IndegoAsyncClient(**test_config) as indego: indego._contextid = "askdjfbaks" indego._online = True indego._userid = "test_user_id" await func(indego) assert getattr(indego, attr) == assert_value await func(indego) assert getattr(indego, attr) == assert_value
def main(config): with IndegoClient(**config) as indego: indego.update_network() (country, operator) = country_operator(indego.network.mcc, indego.network.mnc) if country is not None: print("Country is:", country) if operator is not None: print("Operator is:", operator) else: print("Operator is unknown") else: print("Country and operator are unknown") print("Signal strength (rssi):", indego.network.rssi) print("Available Networks:") for i in range(indego.network.networkCount): (country, operator) = country_operator( int(str(indego.network.networks[i])[:3]), int(str(indego.network.networks[i])[3:5])) if (country is not None) and (operator is not None): print("\t", country, ":", operator) else: print("\tmcc =", str(indego.network.networks[i])[:3], ": mnc =", str(indego.network.networks[i])[3:5])
async def test_download(self, config, param, error): """Test the function for download map.""" conf = test_config.copy() if config: conf.update({"map_filename": config}) with patch("pyIndego.IndegoClient.get", return_value=None): indego = IndegoClient(**conf) try: indego.download_map(param) assert indego.map_filename == "test.svg" if error: assert False except error: assert True with patch("pyIndego.IndegoAsyncClient.start", return_value=True), patch( "pyIndego.IndegoAsyncClient.get", return_value=None ): async with IndegoAsyncClient(**conf) as indego: try: await indego.download_map(param) assert indego.map_filename == "test.svg" if error: assert False except error: assert True
def main(config): with IndegoClient(**config) as indego: # print(" ") # print("=[indego.download_map]===") # indego.download_map() # print("map: ", indego.map_filename) print(" ") print("=[indego.update_state]===") indego.update_state() print(indego.state) print(f"State: {indego.state_description}") print(f"State detail: {indego.state_description_detail}") print(f"xPos: {indego.state.xPos}") print(f"yPos: {indego.state.yPos}") print(f"Serial: {indego.serial}") #print(" ") #print("=[update_state longpoll]===") #indego.update_state(longpoll=True, longpoll_timeout=20) #print(indego.state) #print(indego.state_description) #print(indego.state_description_detail) #print(" ") #print("=[indego.update_alerts]====") #indego.update_alerts() #print(indego.alerts) #print("=[indego.alerts_count]====") #print(indego.alerts_count) #print("=[indego.alerts[0]]====") #print(indego.alerts[0]) #print("=[indego.alerts[1]]====") #print(indego.alerts[1]) #print("=[indego.alerts[2]]====") #print(indego.alerts[2]) #print("=[indego.alerts[3]]====") #print(indego.alerts[3]) # Wakes mower! # print(" ") # print("=[indego.update_config]====") # indego.update_config() # print(indego.config) #print(" ") #print("=[indego.update_generic_data]====") #indego.update_generic_data() #print(indego.generic_data) #print("Generic data min voltage: ", indego.generic_data.model_voltage.min) #print(indego.generic_data.alm_mode) print(" ") print("=[indego.update_last_mow]====") indego.update_last_mow() print(indego.last_mow)
def main(config): with IndegoClient(**config) as indego: indego.update_next_mow() print("Next mowing:", indego.next_mow) nowDate = datetime.now(timezone.utc) if (indego.next_mow - nowDate) < timedelta(hours=2, minutes=30): print("Less than two and a half hours before mowing.")
def test_client_response_errors(self, error): """Test the request functions with different responses.""" with patch("requests.request", side_effect=error), patch( "time.sleep", new_callable=SyncMock ): indego = IndegoClient(**test_config) indego._online = True indego._userid = "test_user_id" resp = indego._request(method=Methods.GET, path="alerts", timeout=1) assert resp is None
async def test_client_responses(self, sync, response, func, attr, ret_value): """Test the request functions with different responses.""" if sync: resp = MockResponseSync(ret_value, response) with patch("requests.request", return_value=resp): indego = IndegoClient(**test_config) indego._online = True indego._userid = "test_user_id" func(indego) assert getattr(indego, attr) == None else: resp = MockResponseAsync(ret_value, response) with patch("aiohttp.ClientSession.request", return_value=resp): async with IndegoAsyncClient(**test_config) as indego: indego._online = True indego._userid = "test_user_id" await func(indego) assert getattr(indego, attr) == None
async def test_login(self, config): """Test the function for handling alerts.""" resp_json = {"contextId": "98765", "userId": "12345"} resp_get = [{"alm_sn": "123456789"}] resp_login_s = MockResponseSync(resp_json, 200) with patch("requests.request", return_value=resp_login_s), patch( "pyIndego.IndegoClient.get", return_value=resp_get ): indego = IndegoClient(**config) indego.login() assert indego._userid == "12345" assert indego.serial == "123456789" resp_login_a = MockResponseAsync(resp_json, 200) with patch("aiohttp.ClientSession.request", return_value=resp_login_a), patch( "pyIndego.IndegoAsyncClient.start", return_value=True ), patch("pyIndego.IndegoAsyncClient.get", return_value=resp_get): async with IndegoAsyncClient(**config) as indego: await indego.login() assert indego._userid == "12345" assert indego.serial == "123456789"
def main(config): with IndegoClient(**config) as indego: indego.update_predictive_schedule() print("Times where SmartMowing is planing to mow the lawn:") for i in range(datetime.now().weekday(), datetime.now().weekday() + 7): for j in range(len(indego.predictive_schedule.schedule_days)): if (indego.predictive_schedule.schedule_days[j].day == (i % 7)): print("\t{}".format( indego.predictive_schedule.schedule_days[j].day_name)) for k in range( len(indego.predictive_schedule.schedule_days[j]. slots)): print('\t\t{:%H:%M} - {:%H:%M}'.format( indego.predictive_schedule.schedule_days[j]. slots[k].start, indego.predictive_schedule. schedule_days[j].slots[k].end)) print("Times that are excluded for mowing from SmartMowing:") for i in range(datetime.now().weekday(), datetime.now().weekday() + 7): for j in range(len(indego.predictive_schedule.exclusion_days)): if (indego.predictive_schedule.exclusion_days[j].day == (i % 7)): print("\t{}".format( indego.predictive_schedule.exclusion_days[j].day_name)) for k in range( len(indego.predictive_schedule.exclusion_days[j]. slots)): print('\t\t{:%H:%M} - {:%H:%M} {}'.format( indego.predictive_schedule.exclusion_days[j]. slots[k].start, indego.predictive_schedule. exclusion_days[j].slots[k].end, indego.predictive_schedule.exclusion_days[j]. slots[k].Attr))
async def test_alert_functions(self, alerts, loaded, index, error): """Test the function for handling alerts.""" resp = MockResponseSync(True, 200) with patch("requests.request", return_value=resp): indego = IndegoClient(**test_config) indego._online = True indego._userid = "test_user_id" indego.alerts = alerts indego._alerts_loaded = loaded try: res = indego.delete_alert(index) if error and not loaded: assert False elif not alerts and loaded: assert res is None else: assert res except error: assert True try: res = indego.put_alert_read(index) if error and not loaded: assert False elif not alerts and loaded: assert res is None else: assert res except error: assert True try: res = indego.delete_all_alerts() if alerts is None and loaded: assert res is None else: assert res except error: assert True try: res = indego.put_all_alerts_read() if alerts is None and loaded: assert res is None else: assert res except error: assert True resp = MockResponseAsync(True, 200) with patch("aiohttp.ClientSession.request", return_value=resp), patch( "pyIndego.IndegoAsyncClient.start", return_value=True ): async with IndegoAsyncClient(**test_config) as indego: indego._online = True indego._userid = "test_user_id" indego.alerts = alerts indego._alerts_loaded = loaded try: res = await indego.delete_alert(index) if error and not loaded: assert False elif not alerts and loaded: assert res is None else: assert res except error: assert True try: res = await indego.put_alert_read(index) if error and not loaded: assert False elif not alerts and loaded: assert res is None else: assert res except error: assert True try: res = await indego.delete_all_alerts() if alerts is None and loaded: assert res is None else: assert res except error: assert True try: res = await indego.put_all_alerts_read() if alerts is None and loaded: assert res is None else: assert res except error: assert True
def test_repr(self): """Test the representation string.""" indego = IndegoClient(**test_config) str(indego)
def test_update_battery(self): """Test the battery update function.""" indego = IndegoClient(**test_config) indego._update_generic_data(generic) indego._update_operating_data(operating)
async def test_commands(self, command, param, error): """Test the function for handling alerts.""" resp = MockResponseSync(True, 200) with patch("requests.request", return_value=resp): indego = IndegoClient(**test_config) indego._online = True indego._userid = "test_user_id" if command == "command": try: indego.put_command(param) if error: assert False assert True except error: assert True elif command == "mow_mode": try: indego.put_mow_mode(param) if error: assert False assert True except error: assert True elif command == "pred_cal": try: if param: indego.put_predictive_cal(param) else: indego.put_predictive_cal() if error: assert False assert True except error: assert True resp = MockResponseAsync(True, 200) with patch("aiohttp.ClientSession.request", return_value=resp), patch( "pyIndego.IndegoAsyncClient.start", return_value=True ): async with IndegoAsyncClient(**test_config) as indego: indego._online = True indego._userid = "test_user_id" if command == "command": try: await indego.put_command(param) if error: assert False assert True except error: assert True elif command == "mow_mode": try: await indego.put_mow_mode(param) if error: assert False assert True except error: assert True elif command == "pred_cal": try: if param: await indego.put_predictive_cal(param) else: await indego.put_predictive_cal() if error: assert False assert True except error: assert True
def main(config): with IndegoClient(**config) as indego: # print(" ") # print("=[indego.download_map]===") # indego.download_map() # print("map: ", indego.map_filename) # print(" ") # print("=[indego.update_all]====") # indego.update_all(force=True) # print(indego) # print(" ") print("=[indego.update_alerts]====") indego.update_alerts() print(indego.alerts) print("=[indego.alerts_count]====") print(indego.alerts_count) print("=[indego.alerts[0]]====") print(indego.alerts[0]) print("=[indego.alerts[1]]====") print(indego.alerts[1]) # print(" ") # print("=[indego.update_generic_data]====") # indego.update_generic_data() # print(indego.generic_data) # print("Generic data min voltage: ", indego.generic_data.model_voltage.min) # print(indego.generic_data.alm_mode) # print(indego.alm_name) # print(" ") # print("=[indego.update_last_completed_mow]====") # indego.update_last_completed_mow() # print(indego.last_completed_mow) # print(" ") # print("=[update_location]====") # indego.update_location() # print(indego.location) # print("=[longpoll_state]====") # indego.update_longpoll_state(40) # print(indego.longpoll_state) # indego.update_network() # print(indego.network) # indego.update_all(force=True) # print(indego) # print("=[state]====") # indego.update_state() # print(indego.state) print(" ") print("=[alerts]====") indego.update_alerts() print(indego.alerts) print("=[alerts_count]====") print(indego.alerts_count) print(" ") print("=[generic_data]====") indego.update_generic_data() print(indego.generic_data) print(" ") print("=[last_completed_mow]====") indego.update_last_completed_mow() print(indego.last_completed_mow) print(" ") print("=[location]====") indego.update_location() print(indego.location) # print("=[longpoll_state]====") # indego.update_longpoll_state(40) # print(indego.longpoll_state) print(" ") print("=[operating data]====") indego.update_operating_data() print(indego.operating_data) # indego.update_network() # print(indego.network) # print(" ") # print("=[indego.update_next_mow]===) # indego.update_next_mow() # indego.update_operating_data() # # indego.update_updates() # # indego.update_user # # indego.update_network() print("=[updates]====") indego.update_updates_available() print(indego.update_available) print(" ") print("=[user]====") indego.update_user() print(indego.user)