Skip to content

Commit

Permalink
Added support for config retry logic
Browse files Browse the repository at this point in the history
  • Loading branch information
dcmeglio committed Jan 7, 2023
1 parent f835a8f commit fe3fff6
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 7 deletions.
10 changes: 8 additions & 2 deletions custom_components/petsafe/button.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
from homeassistant.exceptions import ConfigEntryNotReady

from . import ButtonEntities, PetSafeCoordinator
from .const import DOMAIN
Expand All @@ -8,8 +9,13 @@
async def async_setup_entry(hass: HomeAssistant, config: ConfigEntry, add_entities):
coordinator: PetSafeCoordinator = hass.data[DOMAIN][config.entry_id]

feeders = await coordinator.get_feeders()
litterboxes = await coordinator.get_litterboxes()
feeders = None
litterboxes = None
try:
feeders = await coordinator.get_feeders()
litterboxes = await coordinator.get_litterboxes()
except Exception as ex:
raise ConfigEntryNotReady("Failed to retrieve PetSafe devices") from ex

entities = []
for feeder in feeders:
Expand Down
2 changes: 1 addition & 1 deletion custom_components/petsafe/manifest.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "1.2.1",
"version": "1.2.2",
"domain": "petsafe",
"name": "PetSafe",
"config_flow": true,
Expand Down
10 changes: 9 additions & 1 deletion custom_components/petsafe/select.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
from homeassistant.exceptions import ConfigEntryNotReady
from homeassistant.helpers.entity import EntityCategory

from . import PetSafeCoordinator, SelectEntities
Expand All @@ -8,7 +9,14 @@

async def async_setup_entry(hass: HomeAssistant, config: ConfigEntry, add_entities):
coordinator: PetSafeCoordinator = hass.data[DOMAIN][config.entry_id]
litterboxes = await coordinator.get_litterboxes()

litterboxes = None
try:
litterboxes = await coordinator.get_litterboxes()
except Exception as ex:
raise ConfigEntryNotReady(
"Failed to retrieve PetSafe scoopfree devices"
) from ex

entities = []
for litterbox in litterboxes:
Expand Down
10 changes: 8 additions & 2 deletions custom_components/petsafe/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from homeassistant.config_entries import ConfigEntry

from homeassistant.core import HomeAssistant
from homeassistant.exceptions import ConfigEntryNotReady
from homeassistant.helpers.entity import EntityCategory

from . import PetSafeCoordinator, SensorEntities
Expand All @@ -12,8 +13,13 @@

async def async_setup_entry(hass: HomeAssistant, config: ConfigEntry, add_entities):
coordinator: PetSafeCoordinator = hass.data[DOMAIN][config.entry_id]
feeders = await coordinator.get_feeders()
litterboxes = await coordinator.get_litterboxes()
feeders = None
litterboxes = None
try:
feeders = await coordinator.get_feeders()
litterboxes = await coordinator.get_litterboxes()
except Exception as ex:
raise ConfigEntryNotReady("Failed to retrieve PetSafe devices") from ex

entities = []
for feeder in feeders:
Expand Down
10 changes: 9 additions & 1 deletion custom_components/petsafe/switch.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
from homeassistant.exceptions import ConfigEntryNotReady
from homeassistant.helpers.entity import EntityCategory

from . import PetSafeCoordinator, SwitchEntities
Expand All @@ -8,7 +9,14 @@

async def async_setup_entry(hass: HomeAssistant, config: ConfigEntry, add_entities):
coordinator: PetSafeCoordinator = hass.data[DOMAIN][config.entry_id]
feeders = await coordinator.get_feeders()

feeders = None
try:
feeders = await coordinator.get_feeders()
except Exception as ex:
raise ConfigEntryNotReady(
"Failed to retrieve PetSafe SmartFeed devices"
) from ex

entities = []
for feeder in feeders:
Expand Down

0 comments on commit fe3fff6

Please sign in to comment.