Skip to content
This repository has been archived by the owner on Aug 26, 2022. It is now read-only.

Commit

Permalink
Merge pull request #449 from briis/fix-memory-sensor
Browse files Browse the repository at this point in the history
  • Loading branch information
bdraco authored Jan 8, 2022
2 parents b1fbc24 + 87ba5f3 commit 1acfab3
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
8 changes: 5 additions & 3 deletions custom_components/unifiprotect/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,9 +220,11 @@ def _async_update_extra_attrs_from_protect(self) -> dict[str, Any]:
if key == _KEY_DARK:
return attrs

if key == _KEY_DOORBELL:
assert isinstance(self.device, Camera)
attrs[ATTR_LAST_TRIP_TIME] = self.device.last_ring
if isinstance(self.device, Camera):
if key == _KEY_DOORBELL:
attrs[ATTR_LAST_TRIP_TIME] = self.device.last_ring
elif key == _KEY_MOTION:
attrs[ATTR_LAST_TRIP_TIME] = self.device.last_motion
elif isinstance(self.device, Sensor):
if key in (_KEY_MOTION, _KEY_DOOR):
if key == _KEY_MOTION:
Expand Down
9 changes: 6 additions & 3 deletions custom_components/unifiprotect/camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from pyunifiprotect.api import ProtectApiClient
from pyunifiprotect.data import Camera as UFPCamera
from pyunifiprotect.data import Camera as UFPCamera, StateType
from pyunifiprotect.data.devices import CameraChannel

from .const import (
Expand Down Expand Up @@ -136,9 +136,12 @@ def _async_update_device_from_protect(self) -> None:
super()._async_update_device_from_protect()
self.channel = self.device.channels[self.channel.id]
self._attr_motion_detection_enabled = (
self.device.is_connected and self.device.feature_flags.has_motion_zones
self.device.state == StateType.CONNECTED
and self.device.feature_flags.has_motion_zones
)
self._attr_is_recording = (
self.device.state == StateType.CONNECTED and self.device.is_recording
)
self._attr_is_recording = self.device.is_connected and self.device.is_recording

self._async_set_stream_source()
self._attr_extra_state_attributes = {
Expand Down
5 changes: 4 additions & 1 deletion custom_components/unifiprotect/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ class ProtectSensorEntityDescription(ProtectRequiredKeysMixin, SensorEntityDescr
),
ProtectSensorEntityDescription(
key=_KEY_CAPACITY,
name="Recording Capcity",
name="Recording Capacity",
native_unit_of_measurement=TIME_SECONDS,
icon="mdi:record-rec",
entity_registry_enabled_default=False,
Expand Down Expand Up @@ -441,6 +441,9 @@ def _async_update_device_from_protect(self) -> None:

if self.entity_description.ufp_value is None:
memory = self.device.system_info.memory
if memory.available is None or memory.total is None:
self._attr_available = False
return
value = (1 - memory.available / memory.total) * 100
else:
value = get_nested_attr(self.device, self.entity_description.ufp_value)
Expand Down

0 comments on commit 1acfab3

Please sign in to comment.