Use _attr_*
properties for Doorbird camera (#64734)
Co-authored-by: J. Nick Koston <nick@koston.org>
This commit is contained in:
parent
dba6562356
commit
cd34beb832
3 changed files with 13 additions and 33 deletions
|
@ -81,7 +81,6 @@ class DoorBirdButton(DoorBirdEntity, ButtonEntity):
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Initialize a relay in a DoorBird device."""
|
"""Initialize a relay in a DoorBird device."""
|
||||||
super().__init__(doorstation, doorstation_info)
|
super().__init__(doorstation, doorstation_info)
|
||||||
self._doorstation = doorstation
|
|
||||||
self._relay = relay
|
self._relay = relay
|
||||||
self.entity_description = entity_description
|
self.entity_description = entity_description
|
||||||
|
|
||||||
|
|
|
@ -87,40 +87,25 @@ class DoorBirdCamera(DoorBirdEntity, Camera):
|
||||||
camera_id,
|
camera_id,
|
||||||
name,
|
name,
|
||||||
doorstation_events,
|
doorstation_events,
|
||||||
interval=None,
|
interval,
|
||||||
stream_url=None,
|
stream_url=None,
|
||||||
):
|
) -> None:
|
||||||
"""Initialize the camera on a DoorBird device."""
|
"""Initialize the camera on a DoorBird device."""
|
||||||
super().__init__(doorstation, doorstation_info)
|
super().__init__(doorstation, doorstation_info)
|
||||||
self._url = url
|
self._url = url
|
||||||
self._stream_url = stream_url
|
self._stream_url = stream_url
|
||||||
self._name = name
|
self._attr_name = name
|
||||||
self._last_image = None
|
self._last_image: bytes | None = None
|
||||||
self._supported_features = SUPPORT_STREAM if self._stream_url else 0
|
self._attr_supported_features = SUPPORT_STREAM if self._stream_url else 0
|
||||||
self._interval = interval or datetime.timedelta
|
self._interval = interval
|
||||||
self._last_update = datetime.datetime.min
|
self._last_update = datetime.datetime.min
|
||||||
self._unique_id = f"{self._mac_addr}_{camera_id}"
|
self._attr_unique_id = f"{self._mac_addr}_{camera_id}"
|
||||||
self._doorstation_events = doorstation_events
|
self._doorstation_events = doorstation_events
|
||||||
|
|
||||||
async def stream_source(self):
|
async def stream_source(self):
|
||||||
"""Return the stream source."""
|
"""Return the stream source."""
|
||||||
return self._stream_url
|
return self._stream_url
|
||||||
|
|
||||||
@property
|
|
||||||
def unique_id(self):
|
|
||||||
"""Camera Unique id."""
|
|
||||||
return self._unique_id
|
|
||||||
|
|
||||||
@property
|
|
||||||
def supported_features(self):
|
|
||||||
"""Return supported features."""
|
|
||||||
return self._supported_features
|
|
||||||
|
|
||||||
@property
|
|
||||||
def name(self):
|
|
||||||
"""Get the name of the camera."""
|
|
||||||
return self._name
|
|
||||||
|
|
||||||
async def async_camera_image(
|
async def async_camera_image(
|
||||||
self, width: int | None = None, height: int | None = None
|
self, width: int | None = None, height: int | None = None
|
||||||
) -> bytes | None:
|
) -> bytes | None:
|
||||||
|
@ -139,11 +124,11 @@ class DoorBirdCamera(DoorBirdEntity, Camera):
|
||||||
self._last_update = now
|
self._last_update = now
|
||||||
return self._last_image
|
return self._last_image
|
||||||
except asyncio.TimeoutError:
|
except asyncio.TimeoutError:
|
||||||
_LOGGER.error("DoorBird %s: Camera image timed out", self._name)
|
_LOGGER.error("DoorBird %s: Camera image timed out", self.name)
|
||||||
return self._last_image
|
return self._last_image
|
||||||
except aiohttp.ClientError as error:
|
except aiohttp.ClientError as error:
|
||||||
_LOGGER.error(
|
_LOGGER.error(
|
||||||
"DoorBird %s: Error getting camera image: %s", self._name, error
|
"DoorBird %s: Error getting camera image: %s", self.name, error
|
||||||
)
|
)
|
||||||
return self._last_image
|
return self._last_image
|
||||||
|
|
||||||
|
|
|
@ -18,20 +18,16 @@ class DoorBirdEntity(Entity):
|
||||||
def __init__(self, doorstation, doorstation_info):
|
def __init__(self, doorstation, doorstation_info):
|
||||||
"""Initialize the entity."""
|
"""Initialize the entity."""
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self._doorstation_info = doorstation_info
|
|
||||||
self._doorstation = doorstation
|
self._doorstation = doorstation
|
||||||
self._mac_addr = get_mac_address_from_doorstation_info(doorstation_info)
|
self._mac_addr = get_mac_address_from_doorstation_info(doorstation_info)
|
||||||
|
|
||||||
@property
|
firmware = doorstation_info[DOORBIRD_INFO_KEY_FIRMWARE]
|
||||||
def device_info(self) -> DeviceInfo:
|
firmware_build = doorstation_info[DOORBIRD_INFO_KEY_BUILD_NUMBER]
|
||||||
"""Doorbird device info."""
|
self._attr_device_info = DeviceInfo(
|
||||||
firmware = self._doorstation_info[DOORBIRD_INFO_KEY_FIRMWARE]
|
|
||||||
firmware_build = self._doorstation_info[DOORBIRD_INFO_KEY_BUILD_NUMBER]
|
|
||||||
return DeviceInfo(
|
|
||||||
configuration_url="https://webadmin.doorbird.com/",
|
configuration_url="https://webadmin.doorbird.com/",
|
||||||
connections={(dr.CONNECTION_NETWORK_MAC, self._mac_addr)},
|
connections={(dr.CONNECTION_NETWORK_MAC, self._mac_addr)},
|
||||||
manufacturer=MANUFACTURER,
|
manufacturer=MANUFACTURER,
|
||||||
model=self._doorstation_info[DOORBIRD_INFO_KEY_DEVICE_TYPE],
|
model=doorstation_info[DOORBIRD_INFO_KEY_DEVICE_TYPE],
|
||||||
name=self._doorstation.name,
|
name=self._doorstation.name,
|
||||||
sw_version=f"{firmware} {firmware_build}",
|
sw_version=f"{firmware} {firmware_build}",
|
||||||
)
|
)
|
||||||
|
|
Loading…
Add table
Reference in a new issue