Skip to content

Commit

Permalink
Merge pull request #41 from brenard/refresh-button
Browse files Browse the repository at this point in the history
Ajout d'un bouton pour rafraichir les données de l'intégration
  • Loading branch information
cyr-ius authored Dec 12, 2024
2 parents 34dc56f + 9d48f25 commit e947551
Showing 1 changed file with 25 additions and 5 deletions.
30 changes: 25 additions & 5 deletions custom_components/bbox/button.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,26 @@

_LOGGER = logging.getLogger(__name__)

BUTTON_RESTART: tuple[ButtonEntityDescription, ...] = ButtonEntityDescription(
key="restart", name="Restart", icon="mdi:restart-alert"
)


async def async_setup_entry(
hass: HomeAssistant, entry: BBoxConfigEntry, async_add_entities: AddEntitiesCallback
) -> None:
"""Set up sensor."""
coordinator = entry.runtime_data
entities = [RestartButton(coordinator, BUTTON_RESTART)]
entities = [
RestartButton(
coordinator,
ButtonEntityDescription(
key="restart", name="Restart", icon="mdi:restart-alert"
),
),
RefreshButton(
coordinator,
ButtonEntityDescription(
key="refresh", name="Refresh", icon="mdi:refresh-circle"
),
),
]
async_add_entities(entities)


Expand All @@ -36,3 +45,14 @@ async def async_press(self) -> None:
await self.coordinator.bbox.device.async_reboot()
except BboxException as error:
_LOGGER.error(error)


class RefreshButton(BboxEntity, ButtonEntity):
"""Representation of a button for refreshing integration data."""

async def async_press(self) -> None:
"""Handle the button press."""
try:
await self.coordinator.async_request_refresh()
except BboxException as error:
_LOGGER.error(error)

0 comments on commit e947551

Please sign in to comment.