Process late feedback for Reolink (#84884)
Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
This commit is contained in:
parent
ec33f6fe78
commit
c0d5ceb18c
8 changed files with 120 additions and 101 deletions
|
@ -8,9 +8,9 @@ from homeassistant.config_entries import ConfigEntry
|
|||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
||||
from . import ReolinkData
|
||||
from .const import DOMAIN
|
||||
from .entity import ReolinkCoordinatorEntity
|
||||
from .host import ReolinkHost
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
@ -18,10 +18,11 @@ _LOGGER = logging.getLogger(__name__)
|
|||
async def async_setup_entry(
|
||||
hass: HomeAssistant,
|
||||
config_entry: ConfigEntry,
|
||||
async_add_devices: AddEntitiesCallback,
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up a Reolink IP Camera."""
|
||||
host: ReolinkHost = hass.data[DOMAIN][config_entry.entry_id].host
|
||||
reolink_data: ReolinkData = hass.data[DOMAIN][config_entry.entry_id]
|
||||
host = reolink_data.host
|
||||
|
||||
cameras = []
|
||||
for channel in host.api.channels:
|
||||
|
@ -30,25 +31,31 @@ async def async_setup_entry(
|
|||
streams.append("ext")
|
||||
|
||||
for stream in streams:
|
||||
cameras.append(ReolinkCamera(hass, config_entry, channel, stream))
|
||||
cameras.append(ReolinkCamera(reolink_data, config_entry, channel, stream))
|
||||
|
||||
async_add_devices(cameras, update_before_add=True)
|
||||
async_add_entities(cameras, update_before_add=True)
|
||||
|
||||
|
||||
class ReolinkCamera(ReolinkCoordinatorEntity, Camera):
|
||||
"""An implementation of a Reolink IP camera."""
|
||||
|
||||
_attr_supported_features: CameraEntityFeature = CameraEntityFeature.STREAM
|
||||
_attr_has_entity_name = True
|
||||
|
||||
def __init__(self, hass, config, channel, stream):
|
||||
def __init__(
|
||||
self,
|
||||
reolink_data: ReolinkData,
|
||||
config_entry: ConfigEntry,
|
||||
channel: int,
|
||||
stream: str,
|
||||
) -> None:
|
||||
"""Initialize Reolink camera stream."""
|
||||
ReolinkCoordinatorEntity.__init__(self, hass, config)
|
||||
ReolinkCoordinatorEntity.__init__(self, reolink_data, config_entry, channel)
|
||||
Camera.__init__(self)
|
||||
|
||||
self._channel = channel
|
||||
self._stream = stream
|
||||
|
||||
self._attr_name = f"{self._host.api.camera_name(self._channel)} {self._stream}"
|
||||
self._attr_name = self._stream
|
||||
self._attr_unique_id = f"{self._host.unique_id}_{self._channel}_{self._stream}"
|
||||
self._attr_entity_registry_enabled_default = stream == "sub"
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue