2021-03-21 17:41:41 +00:00
|
|
|
"""Reolink parent entity class."""
|
|
|
|
|
2021-08-28 19:21:19 +00:00
|
|
|
from homeassistant.core import HomeAssistant
|
2021-03-21 17:41:41 +00:00
|
|
|
from homeassistant.helpers.device_registry import CONNECTION_NETWORK_MAC
|
|
|
|
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
|
|
|
|
|
|
|
from .const import BASE, COORDINATOR, DOMAIN
|
2021-08-28 19:21:19 +00:00
|
|
|
from .base import ReolinkBase
|
2021-03-21 17:41:41 +00:00
|
|
|
|
|
|
|
|
|
|
|
class ReolinkEntity(CoordinatorEntity):
|
|
|
|
"""Parent class for Reolink Entities."""
|
|
|
|
|
2021-08-28 19:21:19 +00:00
|
|
|
def __init__(self, hass: HomeAssistant, config):
|
2021-03-21 17:41:41 +00:00
|
|
|
"""Initialize common aspects of a Reolink entity."""
|
|
|
|
coordinator = hass.data[DOMAIN][config.entry_id][COORDINATOR]
|
|
|
|
super().__init__(coordinator)
|
|
|
|
|
2021-08-28 19:21:19 +00:00
|
|
|
self._base: ReolinkBase = hass.data[DOMAIN][config.entry_id][BASE]
|
2021-03-21 17:41:41 +00:00
|
|
|
self._hass = hass
|
|
|
|
self._state = False
|
|
|
|
|
|
|
|
@property
|
|
|
|
def device_info(self):
|
|
|
|
"""Information about this entity/device."""
|
|
|
|
return {
|
|
|
|
"identifiers": {(DOMAIN, self._base.unique_id)},
|
|
|
|
"connections": {(CONNECTION_NETWORK_MAC, self._base.api.mac_address)},
|
|
|
|
"name": self._base.name,
|
|
|
|
"sw_version": self._base.api.sw_version,
|
|
|
|
"model": self._base.api.model,
|
|
|
|
"manufacturer": self._base.api.manufacturer,
|
2021-08-28 19:21:19 +00:00
|
|
|
"channel": self._base.channel,
|
2021-03-21 17:41:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@property
|
|
|
|
def available(self):
|
|
|
|
"""Return True if entity is available."""
|
|
|
|
return self._base.api.session_active
|
|
|
|
|
|
|
|
async def request_refresh(self):
|
|
|
|
"""Call the coordinator to update the API."""
|
|
|
|
await self.coordinator.async_request_refresh()
|