Skip to content

Commit

Permalink
make tests work with new SingleKey authorization method
Browse files Browse the repository at this point in the history
Signed-off-by: Rosi2143 <[email protected]>
  • Loading branch information
Rosi2143 committed May 10, 2024
1 parent b13d963 commit 9b9725d
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 55 deletions.
5 changes: 2 additions & 3 deletions examples/config.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{
"username": "[email protected]",
"password": "xxx",
"serial": "xxxxxxxxx"
"token": "<put your token here>",
"serial": "123456789"
}
54 changes: 32 additions & 22 deletions examples/print_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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)
25 changes: 17 additions & 8 deletions examples/print_next_mowing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
49 changes: 29 additions & 20 deletions examples/print_predictive_schedule.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
2 changes: 0 additions & 2 deletions pyIndego/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ class Methods(Enum):
99999: "Offline",
}


MOWER_STATE_DESCRIPTION = {
0: "Docked",
101: "Docked",
Expand Down Expand Up @@ -216,7 +215,6 @@ class Methods(Enum):
"firmware.updateComplete": "Software update complete",
}


DAY_MAPPING = {
0: "monday",
1: "tuesday",
Expand Down

0 comments on commit 9b9725d

Please sign in to comment.