diff --git a/examples/config.json b/examples/config.json index 8da2c7d..6838078 100644 --- a/examples/config.json +++ b/examples/config.json @@ -1,5 +1,4 @@ { - "username": "xxx@xxx.xx", - "password": "xxx", - "serial": "xxxxxxxxx" + "token": "", + "serial": "123456789" } \ No newline at end of file diff --git a/examples/print_network.py b/examples/print_network.py index 3c45774..b48c39b 100755 --- a/examples/print_network.py +++ b/examples/print_network.py @@ -2,9 +2,15 @@ # -*- coding: utf-8 -*- import json +import logging from pyIndego import IndegoClient +logging.basicConfig(filename="pyIndego.log", level=logging.DEBUG) +_LOGGER = logging.getLogger(__name__) +_LOGGER.setLevel(logging.DEBUG) + def country_operator(mcc, mnc): + """get the country and network operator from network ID's""" if mcc == 262: country = "Germany" if mnc == 1: @@ -40,30 +46,34 @@ def country_operator(mcc, mnc): def main(config): + """example of how to instantiate a indego object and get the network info""" 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) + + if indego.network is not None: + (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("Operator is unknown") + 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]) 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]) - + print("Error getting network info") + if __name__ == "__main__": - with open("config.json", "r") as config_file: - config = json.load(config_file) - main(config) + with open("config.json", "r",encoding="utf-8") as config_file: + _config = json.load(config_file) + main(_config) diff --git a/examples/print_next_mowing.py b/examples/print_next_mowing.py index 6b46860..f1763af 100755 --- a/examples/print_next_mowing.py +++ b/examples/print_next_mowing.py @@ -2,20 +2,29 @@ # -*- coding: utf-8 -*- import json +import logging from datetime import datetime, timezone, timedelta from pyIndego import IndegoClient +logging.basicConfig(filename="pyIndego.log", level=logging.DEBUG) +_LOGGER = logging.getLogger(__name__) +_LOGGER.setLevel(logging.DEBUG) + def main(config): + """example of how to instantiate a indego object and get the mowing time""" 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.") + + now_date = datetime.now(timezone.utc) + if indego.next_mow is not None: + if (indego.next_mow - now_date) < timedelta(hours=2, minutes=30): + print("Less than two and a half hours before mowing.") + else: + print("Error getting mowing time") if __name__ == "__main__": - with open("config.json", "r") as config_file: - config = json.load(config_file) - main(config) + with open("config.json", "r", encoding="utf-8") as config_file: + _config = json.load(config_file) + main(_config) diff --git a/examples/print_predictive_schedule.py b/examples/print_predictive_schedule.py index 5112feb..85a3d93 100755 --- a/examples/print_predictive_schedule.py +++ b/examples/print_predictive_schedule.py @@ -2,32 +2,41 @@ # -*- coding: utf-8 -*- from datetime import datetime +import logging import json from pyIndego import IndegoClient +logging.basicConfig(filename="pyIndego.log", level=logging.DEBUG) +_LOGGER = logging.getLogger(__name__) +_LOGGER.setLevel(logging.DEBUG) + def main(config): + """example of how to instantiate a indego object and get the schedule information""" 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)) + + if indego.predictive_schedule is not None: + 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)) + else: + print("Error getting predictive schedule info") if __name__ == "__main__": - with open("config.json", "r") as config_file: - config = json.load(config_file) - main(config) + with open("config.json", "r",encoding="utf-8") as config_file: + _config = json.load(config_file) + main(_config) diff --git a/pyIndego/const.py b/pyIndego/const.py index e27ecf6..5bbb8c0 100644 --- a/pyIndego/const.py +++ b/pyIndego/const.py @@ -132,7 +132,6 @@ class Methods(Enum): 99999: "Offline", } - MOWER_STATE_DESCRIPTION = { 0: "Docked", 101: "Docked", @@ -216,7 +215,6 @@ class Methods(Enum): "firmware.updateComplete": "Software update complete", } - DAY_MAPPING = { 0: "monday", 1: "tuesday",