Skip to content

Commit

Permalink
Merge pull request #18 from dougiteixeira/fix-vehicle-non-existent
Browse files Browse the repository at this point in the history
Protects error integration in case the vehicle is deleted in the app
  • Loading branch information
hudsonbrendon authored Apr 27, 2023
2 parents 6a54d75 + d25500f commit 3c3222e
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 2 deletions.
2 changes: 1 addition & 1 deletion custom_components/drivvo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,4 +154,4 @@ def sort_by_key(list):
return data

_LOGGER.debug("API Response Data Vehicle - %s: %s", info, response)
return False
return None
11 changes: 10 additions & 1 deletion custom_components/drivvo/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@
from homeassistant.data_entry_flow import FlowResult
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers import device_registry as dr
from homeassistant.helpers.issue_registry import IssueSeverity, async_create_issue
from homeassistant.helpers.issue_registry import (
IssueSeverity,
async_create_issue,
async_delete_issue,
)

from . import auth, get_vehicles
from .const import (
Expand Down Expand Up @@ -63,6 +67,11 @@ async def async_step_init(self, user_input: dict[str, Any]) -> FlowResult:
device_id=device.id,
remove_config_entry_id=self.config_entry.entry_id,
)
async_delete_issue(
self.hass,
DOMAIN,
f"{vehicle}_vehicle_non_existent",
)
_LOGGER.debug("Device %s (%s) removed", device.name, device.id)

self.hass.config_entries.async_update_entry(
Expand Down
12 changes: 12 additions & 0 deletions custom_components/drivvo/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,18 @@ async def async_setup_entry(
],
update_before_add=True,
)
else:
async_create_issue(
hass,
DOMAIN,
f"{vehicle}_vehicle_non_existent",
is_fixable=False,
severity=IssueSeverity.WARNING,
translation_key="vehicle_non_existent",
translation_placeholders={
"vehicle": vehicle,
},
)


async def async_setup_platform(
Expand Down
4 changes: 4 additions & 0 deletions custom_components/drivvo/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@
"import_already_configured": {
"title": "Account {email} already exists",
"description": "Account {email} already exists and therefore was not imported.\n\nYou can remove the configuration from your `configuration.yaml` file."
},
"vehicle_non_existent": {
"title": "The vehicle ID {vehicle} does not exist in the Drivvo app",
"description": "The vehicle ID {vehicle} does not exist, it may have been deleted.\n\nGo to the integration configuration options and remove the vehicle."
}
},
"options": {
Expand Down
4 changes: 4 additions & 0 deletions custom_components/drivvo/translations/pt-BR.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@
"import_already_configured": {
"title": "A configuração da conta {email} já existe",
"description": "A configuração da conta {email} já existe e por isso não foi importada.\n\nVocê pode remover a configuração do seu arquivo `configuration.yaml`."
},
"vehicle_non_existent": {
"title": "O veículo ID {vehicle} não existe no aplicativo Drivvo",
"description": "O veículo {vehicle} não existe, ele pode ter sido excluído.\n\nAcesse as opções de configuração da integração e remova o veículo."
}
},
"options": {
Expand Down

0 comments on commit 3c3222e

Please sign in to comment.