15 files
This commit is contained in:
@@ -5,7 +5,7 @@ from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
||||
from .const import DOMAIN, SERVICE_NEXT_SLIDE, SERVICE_REFRESH_ALBUM, ATTR_ENTRY_ID
|
||||
from .const import DOMAIN, SERVICE_REFRESH_ALBUM, ATTR_ENTRY_ID
|
||||
from .coordinator import AlbumCoordinator
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry, async_add_e
|
||||
coordinator: AlbumCoordinator = hass.data[DOMAIN][entry.entry_id]["coordinator"]
|
||||
async_add_entities(
|
||||
[
|
||||
PreviousSlideButton(hass, entry, coordinator),
|
||||
NextSlideButton(hass, entry, coordinator),
|
||||
RefreshAlbumButton(hass, entry, coordinator),
|
||||
]
|
||||
@@ -36,6 +37,19 @@ class _BaseButton(ButtonEntity):
|
||||
}
|
||||
|
||||
|
||||
class PreviousSlideButton(_BaseButton):
|
||||
def __init__(self, hass: HomeAssistant, entry: ConfigEntry, coordinator: AlbumCoordinator) -> None:
|
||||
super().__init__(hass, entry, coordinator)
|
||||
self._attr_unique_id = f"{entry.entry_id}_previous_button"
|
||||
self._attr_name = "Previous slide"
|
||||
self._attr_icon = "mdi:skip-previous"
|
||||
|
||||
async def async_press(self) -> None:
|
||||
camera = self.hass.data[DOMAIN][self.entry.entry_id].get("camera")
|
||||
if camera is not None:
|
||||
await camera.async_force_prev()
|
||||
|
||||
|
||||
class NextSlideButton(_BaseButton):
|
||||
def __init__(self, hass: HomeAssistant, entry: ConfigEntry, coordinator: AlbumCoordinator) -> None:
|
||||
super().__init__(hass, entry, coordinator)
|
||||
@@ -44,12 +58,9 @@ class NextSlideButton(_BaseButton):
|
||||
self._attr_icon = "mdi:skip-next"
|
||||
|
||||
async def async_press(self) -> None:
|
||||
await self.hass.services.async_call(
|
||||
DOMAIN,
|
||||
SERVICE_NEXT_SLIDE,
|
||||
{ATTR_ENTRY_ID: self.entry.entry_id},
|
||||
blocking=False,
|
||||
)
|
||||
camera = self.hass.data[DOMAIN][self.entry.entry_id].get("camera")
|
||||
if camera is not None:
|
||||
await camera.async_force_next()
|
||||
|
||||
|
||||
class RefreshAlbumButton(_BaseButton):
|
||||
|
||||
Reference in New Issue
Block a user