Skip to content

Commit

Permalink
Merge pull request #128 from Rosi2143/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
Rosi2143 authored May 10, 2024
2 parents ed44b0e + 28d8c49 commit c3820f6
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 59 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
10 changes: 6 additions & 4 deletions pyIndego/indego_async_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ async def _request( # noqa: C901
response.raise_for_status()

except (asyncio.TimeoutError, ServerTimeoutError, HTTPGatewayTimeout) as exc:
_LOGGER.info("%s: Timeout on Bosch servers (mower offline?), retrying...", exc)
_LOGGER.info("%s %s request timed out (mower offline?): %s. Retrying...", method.value, path, exc)
return await self._request(
method=method,
path=path,
Expand All @@ -518,11 +518,13 @@ async def _request( # noqa: C901
)

except ClientOSError as exc:
_LOGGER.debug("%s: Failed to update Indego status, longpoll timeout", exc)
_LOGGER.debug("%s %s request timed out: %s", method.value, path, exc)
return None

except (TooManyRedirects, ClientResponseError, SocketError) as exc:
_LOGGER.error("%s: Failed %s to Indego, won't retry", exc, method.value)
if self._raise_request_exceptions:
raise
_LOGGER.error("%s %s failed: %s", method.value, path, exc)
return None

except asyncio.CancelledError:
Expand All @@ -532,7 +534,7 @@ async def _request( # noqa: C901
except Exception as exc:
if self._raise_request_exceptions:
raise
_LOGGER.error("Request to %s gave a unhandled error: %s", url, exc)
_LOGGER.error("Request %s %s gave a unhandled error: %s", method.value, path, exc)
return None

async def get(self, path: str, timeout: int = 30):
Expand Down

0 comments on commit c3820f6

Please sign in to comment.