Skip to content

Commit

Permalink
Improved datetime formatting (one formatter + include seconds).
Browse files Browse the repository at this point in the history
Removed duplicate datetime related attributes from HA.
Added (translation) text with link to known issues on component setup failure.
Fixed formatting the datetime values in the correct timezone. This will make sure the alert time is showed in the current timezone instead of UTC.
Bumped version to 5.7.4.
  • Loading branch information
sander1988 committed Jul 21, 2024
1 parent fd4d746 commit c20fc84
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 39 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ If you experience any readings from your mower that the sensor does not read out
## Known issues
* A special [Chrome plugin](#installing-the-chrome-extension) is required to complete the account linking in HomeAssistant.
* The Bosch Cloud (running on Azure) might block this integration from time to time. You might see HTTP 4XX errors like 'The connection to the Bosch Indego API failed!'. This might happen during component setup or during state updates. In that case you might be able to workaround the issue by changing the user agent (in Settings > Devices & services > Bosch Indego Mower > Configure).
* The Bosch Cloud (running on Azure) might block this integration from time to time. You might see HTTP 4XX errors like 'The connection to the Bosch Indego API failed!'. This might happen during component setup or during state updates. In that case you might be able to workaround the issue by changing the user agent (during initial component setup or for existing components under Settings > Devices & services > Bosch Indego Mower > Configure).
* You might see HTTP 5XX errors from time to time (most of time once a day). In that case there is a problem on the Bosch Cloud side which is temporary unavailable.
* HTTP 5XX errors can also occur right after you have sent an impossible command to the mower. Like docking the mower while it's already docked.
Expand Down
48 changes: 21 additions & 27 deletions custom_components/indego/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,16 @@ def FUNC_ICON_MOWER_ALERT(state):
}


def format_indego_date(date: datetime) -> str:
return date.astimezone().strftime("%Y-%m-%d %H:%M:%S")


def last_updated_now() -> str:
return homeassistant.util.dt.as_local(utcnow()).strftime(
"%Y-%m-%d %H:%M:%S"
)


async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Load a config entry."""
hass.data.setdefault(DOMAIN, {})
Expand Down Expand Up @@ -640,9 +650,7 @@ async def _update_operating_data(self):

self.entities[ENTITY_BATTERY].add_attributes(
{
"last_updated": homeassistant.util.dt.as_local(utcnow()).strftime(
"%Y-%m-%d %H:%M"
),
"last_updated": last_updated_now(),
"voltage_V": self._indego_client.operating_data.battery.voltage,
"discharge_Ah": self._indego_client.operating_data.battery.discharge,
"cycles": self._indego_client.operating_data.battery.cycles,
Expand Down Expand Up @@ -685,27 +693,21 @@ async def _update_state(self, longpoll: bool = True):

self.entities[ENTITY_MOWER_STATE].add_attributes(
{
"last_updated": homeassistant.util.dt.as_local(utcnow()).strftime(
"%Y-%m-%d %H:%M"
)
"last_updated": last_updated_now()
}
)

self.entities[ENTITY_MOWER_STATE_DETAIL].add_attributes(
{
"last_updated": homeassistant.util.dt.as_local(utcnow()).strftime(
"%Y-%m-%d %H:%M"
),
"last_updated": last_updated_now(),
"state_number": self._indego_client.state.state,
"state_description": self._indego_client.state_description_detail,
}
)

self.entities[ENTITY_LAWN_MOWED].add_attributes(
{
"last_updated": homeassistant.util.dt.as_local(utcnow()).strftime(
"%Y-%m-%d %H:%M"
),
"last_updated": last_updated_now(),
"last_session_operation_min": self._indego_client.state.runtime.session.operate,
"last_session_cut_min": self._indego_client.state.runtime.session.cut,
"last_session_charge_min": self._indego_client.state.runtime.session.charge,
Expand Down Expand Up @@ -749,7 +751,7 @@ async def _update_alerts(self):
"alerts_count": self._indego_client.alerts_count,
"last_alert_error_code": self._indego_client.alerts[0].error_code,
"last_alert_message": self._indego_client.alerts[0].message,
"last_alert_date": self._indego_client.alerts[0].date.strftime("%Y-%m-%d %H:%M:%S"),
"last_alert_date": format_indego_date(self._indego_client.alerts[0].date),
"last_alert_read": self._indego_client.alerts[0].read_status,
}, False
)
Expand All @@ -760,7 +762,7 @@ async def _update_alerts(self):
alert_index = 0
for index, alert in enumerate(self._indego_client.alerts):
self.entities[ENTITY_ALERT].add_attributes({
("alert_%i" % index): "%s: %s" % (alert.date.strftime("%Y-%m-%d %H:%M:%S"), alert.message)
("alert_%i" % index): "%s: %s" % (format_indego_date(alert.date), alert.message)
}, False)
alert_index = index

Expand Down Expand Up @@ -791,19 +793,9 @@ async def _update_last_completed_mow(self):
ENTITY_LAST_COMPLETED
].state = self._indego_client.last_completed_mow.isoformat()

self.entities[ENTITY_LAST_COMPLETED].add_attributes(
{
"last_completed_mow": self._indego_client.last_completed_mow.strftime(
"%Y-%m-%d %H:%M"
)
}
)

self.entities[ENTITY_LAWN_MOWED].add_attributes(
{
"last_completed_mow": self._indego_client.last_completed_mow.strftime(
"%Y-%m-%d %H:%M"
)
"last_completed_mow": format_indego_date(self._indego_client.last_completed_mow)
}
)

Expand All @@ -813,12 +805,14 @@ async def _update_next_mow(self):
if self._indego_client.next_mow:
self.entities[ENTITY_NEXT_MOW].state = self._indego_client.next_mow.isoformat()

next_mow = format_indego_date(self._indego_client.next_mow)

self.entities[ENTITY_NEXT_MOW].add_attributes(
{"next_mow": self._indego_client.next_mow.strftime("%Y-%m-%d %H:%M")}
{"next_mow": next_mow}
)

self.entities[ENTITY_LAWN_MOWED].add_attributes(
{"next_mow": self._indego_client.next_mow.strftime("%Y-%m-%d %H:%M")}
{"next_mow": next_mow}
)

@property
Expand Down
2 changes: 1 addition & 1 deletion custom_components/indego/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
"codeowners": ["@jm-73", "@eavanvalkenburg", "@sander1988"],
"requirements": ["pyIndego==3.2.2"],
"iot_class": "cloud_push",
"version": "5.7.3",
"version": "5.7.4",
"loggers": ["custom_components.indego", "pyIndego"]
}
4 changes: 2 additions & 2 deletions custom_components/indego/translations/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"config": {
"abort": {
"already_configured": "Dieser Bosch Indego Mähroboter wurde bereits konfiguriert!",
"connection_error": "Die Verbindung zur Bosch Indego API ist fehlgeschlagen!",
"connection_error": "Die Verbindung zur Bosch Indego API ist fehlgeschlagen! Please use the known issues page (https://github.com/sander1988/Indego?tab=readme-ov-file#known-issues) for possible solutions.",
"no_mowers_found": "In diesem Bosch Indego Account wurden keine Mähroboter gefunden!"
},
"step": {
Expand All @@ -12,7 +12,7 @@
"expose_mower": "Indego Mähroboter als Mower Entität in HomeAssistant anlegen",
"expose_vacuum": "Indego Mähroboter als Vacuum Entität in HomeAssistant anlegen"
},
"description": "Erweiterte Einstellung des Bosch Indego Component. Kann für die meisten Benutzer unverändert gelassen werden."
"description": "Erweiterte Einstellung des Bosch Indego Component."
},
"mower": {
"data": {
Expand Down
4 changes: 2 additions & 2 deletions custom_components/indego/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"config": {
"abort": {
"already_configured": "This Bosch Indego mower has already been configured!",
"connection_error": "The connection to the Bosch Indego API failed!",
"connection_error": "The connection to the Bosch Indego API failed! Please use the known issues page (https://github.com/sander1988/Indego?tab=readme-ov-file#known-issues) for possible solutions.",
"no_mowers_found": "No mowers found in this Bosch Indego account!"
},
"step": {
Expand All @@ -12,7 +12,7 @@
"expose_mower": "Expose Indego mower as mower entity in HomeAssistant",
"expose_vacuum": "Expose Indego mower as vacuum entity in HomeAssistant"
},
"description": "Advanced settings of the Bosch Indego component. Can be left unchanged for most users."
"description": "Advanced settings of the Bosch Indego component."
},
"mower": {
"data": {
Expand Down
4 changes: 2 additions & 2 deletions custom_components/indego/translations/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"config": {
"abort": {
"already_configured": "Cette tondeuse Bosch Indego a déjà été configurée !",
"connection_error": "La connexion à l'API Bosch Indego a échoué !",
"connection_error": "La connexion à l'API Bosch Indego a échoué ! Please use the known issues page (https://github.com/sander1988/Indego?tab=readme-ov-file#known-issues) for possible solutions.",
"no_mowers_found": "Aucune tondeuse n'a été trouvée sur ce compte Bosch Indego !"
},
"step": {
Expand All @@ -12,7 +12,7 @@
"expose_mower": "Exposer la tondeuse Indego comme une entité tondeuse dans HomeAssistant",
"expose_vacuum": "Exposer la tondeuse Indego comme une entité aspirateur dans HomeAssistant"
},
"description": "Réglages avancés du composant Bosch Indego. Peuvent être laissés inchangés pour la plupart des utilisateurs."
"description": "Réglages avancés du composant Bosch Indego."
},
"mower": {
"data": {
Expand Down
4 changes: 2 additions & 2 deletions custom_components/indego/translations/nl.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"config": {
"abort": {
"already_configured": "Deze Bosch Indego robotmaaier is al geconfigureerd!",
"connection_error": "De verbinding met de Bosch Indego API is mislukt!",
"connection_error": "De verbinding met de Bosch Indego API is mislukt! Gebruik de bekende problemen pagina (https://github.com/sander1988/Indego?tab=readme-ov-file#known-issues) voor mogelijke oplossingen.",
"no_mowers_found": "Geen robotmaaiers gevonden in deze Bosch Indego account!"
},
"step": {
Expand All @@ -12,7 +12,7 @@
"expose_mower": "Voeg de Indego robotmaaier toe als grasmaaier entiteit aan HomeAssistant",
"expose_vacuum": "Voeg de Indego robotmaaier toe als stofzuiger entiteit aan HomeAssistant"
},
"description": "Advanced settings of the Bosch Indego component. Can be left unchanged for most users."
"description": "Geavanceerde instellingen van het Bosch Indego component."
},
"mower": {
"data": {
Expand Down
4 changes: 2 additions & 2 deletions custom_components/indego/translations/pl.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"config": {
"abort": {
"already_configured": "Ta kosiarka Bosch Indego została już wcześniej skonfigurowana!",
"connection_error": "Błąd połączenia z Bosch Indego API!",
"connection_error": "Błąd połączenia z Bosch Indego API! Please use the known issues page (https://github.com/sander1988/Indego?tab=readme-ov-file#known-issues) for possible solutions.",
"no_mowers_found": "Na tym koncie Bosch Indego nie znaleziono żadnej kosiarki!"
},
"step": {
Expand All @@ -12,7 +12,7 @@
"expose_mower": "Wyświetl kosiarkę Indego jako encję kosiarki w HomeAssistant",
"expose_vacuum": "Wyświetl kosiarkę Indego jako encję odkurzacza w HomeAssistant"
},
"description": "Ustawienia zaawansowane komponentu Bosch Indego. Większość użytkowników może pozostawić je bez zmian."
"description": "Ustawienia zaawansowane komponentu Bosch Indego."
},
"mower": {
"data": {
Expand Down

0 comments on commit c20fc84

Please sign in to comment.