Use _attr_* properties for Doorbird camera (#64734)

Co-authored-by: J. Nick Koston <nick@koston.org>
This commit is contained in:
Sean Vig 2022-01-22 22:53:44 -05:00 committed by GitHub
parent dba6562356
commit cd34beb832
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 33 deletions

View file

@ -81,7 +81,6 @@ class DoorBirdButton(DoorBirdEntity, ButtonEntity):
) -> None:
"""Initialize a relay in a DoorBird device."""
super().__init__(doorstation, doorstation_info)
self._doorstation = doorstation
self._relay = relay
self.entity_description = entity_description

View file

@ -87,40 +87,25 @@ class DoorBirdCamera(DoorBirdEntity, Camera):
camera_id,
name,
doorstation_events,
interval=None,
interval,
stream_url=None,
):
) -> None:
"""Initialize the camera on a DoorBird device."""
super().__init__(doorstation, doorstation_info)
self._url = url
self._stream_url = stream_url
self._name = name
self._last_image = None
self._supported_features = SUPPORT_STREAM if self._stream_url else 0
self._interval = interval or datetime.timedelta
self._attr_name = name
self._last_image: bytes | None = None
self._attr_supported_features = SUPPORT_STREAM if self._stream_url else 0
self._interval = interval
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
async def stream_source(self):
"""Return the stream source."""
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(
self, width: int | None = None, height: int | None = None
) -> bytes | None:
@ -139,11 +124,11 @@ class DoorBirdCamera(DoorBirdEntity, Camera):
self._last_update = now
return self._last_image
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
except aiohttp.ClientError as 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

View file

@ -18,20 +18,16 @@ class DoorBirdEntity(Entity):
def __init__(self, doorstation, doorstation_info):
"""Initialize the entity."""
super().__init__()
self._doorstation_info = doorstation_info
self._doorstation = doorstation
self._mac_addr = get_mac_address_from_doorstation_info(doorstation_info)
@property
def device_info(self) -> DeviceInfo:
"""Doorbird device info."""
firmware = self._doorstation_info[DOORBIRD_INFO_KEY_FIRMWARE]
firmware_build = self._doorstation_info[DOORBIRD_INFO_KEY_BUILD_NUMBER]
return DeviceInfo(
firmware = doorstation_info[DOORBIRD_INFO_KEY_FIRMWARE]
firmware_build = doorstation_info[DOORBIRD_INFO_KEY_BUILD_NUMBER]
self._attr_device_info = DeviceInfo(
configuration_url="https://webadmin.doorbird.com/",
connections={(dr.CONNECTION_NETWORK_MAC, self._mac_addr)},
manufacturer=MANUFACTURER,
model=self._doorstation_info[DOORBIRD_INFO_KEY_DEVICE_TYPE],
model=doorstation_info[DOORBIRD_INFO_KEY_DEVICE_TYPE],
name=self._doorstation.name,
sw_version=f"{firmware} {firmware_build}",
)