mirror of
https://github.com/home-assistant/core.git
synced 2025-07-25 06:07:17 +00:00
UniFi Protect test sensor followup (#63563)
This commit is contained in:
parent
469b6a0eb1
commit
812cb4a9d8
@ -127,24 +127,6 @@ ALL_DEVICES_SENSORS: tuple[ProtectSensorEntityDescription, ...] = (
|
|||||||
)
|
)
|
||||||
|
|
||||||
CAMERA_SENSORS: tuple[ProtectSensorEntityDescription, ...] = (
|
CAMERA_SENSORS: tuple[ProtectSensorEntityDescription, ...] = (
|
||||||
ProtectSensorEntityDescription(
|
|
||||||
key=_KEY_RX,
|
|
||||||
name="Received Data",
|
|
||||||
native_unit_of_measurement=DATA_BYTES,
|
|
||||||
entity_registry_enabled_default=False,
|
|
||||||
entity_category=EntityCategory.DIAGNOSTIC,
|
|
||||||
state_class=SensorStateClass.TOTAL_INCREASING,
|
|
||||||
ufp_value="stats.rx_bytes",
|
|
||||||
),
|
|
||||||
ProtectSensorEntityDescription(
|
|
||||||
key=_KEY_TX,
|
|
||||||
name="Transferred Data",
|
|
||||||
native_unit_of_measurement=DATA_BYTES,
|
|
||||||
entity_registry_enabled_default=False,
|
|
||||||
entity_category=EntityCategory.DIAGNOSTIC,
|
|
||||||
state_class=SensorStateClass.TOTAL_INCREASING,
|
|
||||||
ufp_value="stats.tx_bytes",
|
|
||||||
),
|
|
||||||
ProtectSensorEntityDescription(
|
ProtectSensorEntityDescription(
|
||||||
key=_KEY_OLDEST,
|
key=_KEY_OLDEST,
|
||||||
name="Oldest Recording",
|
name="Oldest Recording",
|
||||||
@ -184,6 +166,27 @@ CAMERA_SENSORS: tuple[ProtectSensorEntityDescription, ...] = (
|
|||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
CAMERA_DISABLED_SENSORS: tuple[ProtectSensorEntityDescription, ...] = (
|
||||||
|
ProtectSensorEntityDescription(
|
||||||
|
key=_KEY_RX,
|
||||||
|
name="Received Data",
|
||||||
|
native_unit_of_measurement=DATA_BYTES,
|
||||||
|
entity_registry_enabled_default=False,
|
||||||
|
entity_category=EntityCategory.DIAGNOSTIC,
|
||||||
|
state_class=SensorStateClass.TOTAL_INCREASING,
|
||||||
|
ufp_value="stats.rx_bytes",
|
||||||
|
),
|
||||||
|
ProtectSensorEntityDescription(
|
||||||
|
key=_KEY_TX,
|
||||||
|
name="Transferred Data",
|
||||||
|
native_unit_of_measurement=DATA_BYTES,
|
||||||
|
entity_registry_enabled_default=False,
|
||||||
|
entity_category=EntityCategory.DIAGNOSTIC,
|
||||||
|
state_class=SensorStateClass.TOTAL_INCREASING,
|
||||||
|
ufp_value="stats.tx_bytes",
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
SENSE_SENSORS: tuple[ProtectSensorEntityDescription, ...] = (
|
SENSE_SENSORS: tuple[ProtectSensorEntityDescription, ...] = (
|
||||||
ProtectSensorEntityDescription(
|
ProtectSensorEntityDescription(
|
||||||
key=_KEY_BATTERY,
|
key=_KEY_BATTERY,
|
||||||
@ -229,36 +232,6 @@ NVR_SENSORS: tuple[ProtectSensorEntityDescription, ...] = (
|
|||||||
entity_category=EntityCategory.DIAGNOSTIC,
|
entity_category=EntityCategory.DIAGNOSTIC,
|
||||||
ufp_value="up_since",
|
ufp_value="up_since",
|
||||||
),
|
),
|
||||||
ProtectSensorEntityDescription(
|
|
||||||
key=_KEY_CPU,
|
|
||||||
name="CPU Utilization",
|
|
||||||
native_unit_of_measurement=PERCENTAGE,
|
|
||||||
icon="mdi:speedometer",
|
|
||||||
entity_registry_enabled_default=False,
|
|
||||||
entity_category=EntityCategory.DIAGNOSTIC,
|
|
||||||
state_class=SensorStateClass.MEASUREMENT,
|
|
||||||
ufp_value="system_info.cpu.average_load",
|
|
||||||
),
|
|
||||||
ProtectSensorEntityDescription(
|
|
||||||
key=_KEY_CPU_TEMP,
|
|
||||||
name="CPU Temperature",
|
|
||||||
native_unit_of_measurement=TEMP_CELSIUS,
|
|
||||||
device_class=DEVICE_CLASS_TEMPERATURE,
|
|
||||||
entity_registry_enabled_default=False,
|
|
||||||
entity_category=EntityCategory.DIAGNOSTIC,
|
|
||||||
state_class=SensorStateClass.MEASUREMENT,
|
|
||||||
ufp_value="system_info.cpu.temperature",
|
|
||||||
),
|
|
||||||
ProtectSensorEntityDescription(
|
|
||||||
key=_KEY_MEMORY,
|
|
||||||
name="Memory Utilization",
|
|
||||||
native_unit_of_measurement=PERCENTAGE,
|
|
||||||
icon="mdi:memory",
|
|
||||||
entity_registry_enabled_default=False,
|
|
||||||
entity_category=EntityCategory.DIAGNOSTIC,
|
|
||||||
state_class=SensorStateClass.MEASUREMENT,
|
|
||||||
precision=2,
|
|
||||||
),
|
|
||||||
ProtectSensorEntityDescription(
|
ProtectSensorEntityDescription(
|
||||||
key=_KEY_DISK,
|
key=_KEY_DISK,
|
||||||
name="Storage Utilization",
|
name="Storage Utilization",
|
||||||
@ -340,6 +313,39 @@ NVR_SENSORS: tuple[ProtectSensorEntityDescription, ...] = (
|
|||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
NVR_DISABLED_SENSORS: tuple[ProtectSensorEntityDescription, ...] = (
|
||||||
|
ProtectSensorEntityDescription(
|
||||||
|
key=_KEY_CPU,
|
||||||
|
name="CPU Utilization",
|
||||||
|
native_unit_of_measurement=PERCENTAGE,
|
||||||
|
icon="mdi:speedometer",
|
||||||
|
entity_registry_enabled_default=False,
|
||||||
|
entity_category=EntityCategory.DIAGNOSTIC,
|
||||||
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
|
ufp_value="system_info.cpu.average_load",
|
||||||
|
),
|
||||||
|
ProtectSensorEntityDescription(
|
||||||
|
key=_KEY_CPU_TEMP,
|
||||||
|
name="CPU Temperature",
|
||||||
|
native_unit_of_measurement=TEMP_CELSIUS,
|
||||||
|
device_class=DEVICE_CLASS_TEMPERATURE,
|
||||||
|
entity_registry_enabled_default=False,
|
||||||
|
entity_category=EntityCategory.DIAGNOSTIC,
|
||||||
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
|
ufp_value="system_info.cpu.temperature",
|
||||||
|
),
|
||||||
|
ProtectSensorEntityDescription(
|
||||||
|
key=_KEY_MEMORY,
|
||||||
|
name="Memory Utilization",
|
||||||
|
native_unit_of_measurement=PERCENTAGE,
|
||||||
|
icon="mdi:memory",
|
||||||
|
entity_registry_enabled_default=False,
|
||||||
|
entity_category=EntityCategory.DIAGNOSTIC,
|
||||||
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
|
precision=2,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(
|
async def async_setup_entry(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
@ -352,7 +358,7 @@ async def async_setup_entry(
|
|||||||
data,
|
data,
|
||||||
ProtectDeviceSensor,
|
ProtectDeviceSensor,
|
||||||
all_descs=ALL_DEVICES_SENSORS,
|
all_descs=ALL_DEVICES_SENSORS,
|
||||||
camera_descs=CAMERA_SENSORS,
|
camera_descs=CAMERA_SENSORS + CAMERA_DISABLED_SENSORS,
|
||||||
sense_descs=SENSE_SENSORS,
|
sense_descs=SENSE_SENSORS,
|
||||||
)
|
)
|
||||||
entities += _async_nvr_entities(data)
|
entities += _async_nvr_entities(data)
|
||||||
@ -366,7 +372,7 @@ def _async_nvr_entities(
|
|||||||
) -> list[ProtectDeviceEntity]:
|
) -> list[ProtectDeviceEntity]:
|
||||||
entities: list[ProtectDeviceEntity] = []
|
entities: list[ProtectDeviceEntity] = []
|
||||||
device = data.api.bootstrap.nvr
|
device = data.api.bootstrap.nvr
|
||||||
for description in NVR_SENSORS:
|
for description in NVR_SENSORS + NVR_DISABLED_SENSORS:
|
||||||
entities.append(ProtectNVRSensor(data, device, description))
|
entities.append(ProtectNVRSensor(data, device, description))
|
||||||
_LOGGER.debug("Adding NVR sensor entity %s", description.name)
|
_LOGGER.debug("Adding NVR sensor entity %s", description.name)
|
||||||
|
|
||||||
|
@ -12,7 +12,9 @@ from pyunifiprotect.data.nvr import NVR
|
|||||||
from homeassistant.components.unifiprotect.const import DEFAULT_ATTRIBUTION
|
from homeassistant.components.unifiprotect.const import DEFAULT_ATTRIBUTION
|
||||||
from homeassistant.components.unifiprotect.sensor import (
|
from homeassistant.components.unifiprotect.sensor import (
|
||||||
ALL_DEVICES_SENSORS,
|
ALL_DEVICES_SENSORS,
|
||||||
|
CAMERA_DISABLED_SENSORS,
|
||||||
CAMERA_SENSORS,
|
CAMERA_SENSORS,
|
||||||
|
NVR_DISABLED_SENSORS,
|
||||||
NVR_SENSORS,
|
NVR_SENSORS,
|
||||||
SENSE_SENSORS,
|
SENSE_SENSORS,
|
||||||
)
|
)
|
||||||
@ -191,9 +193,6 @@ async def test_sensor_setup_nvr(
|
|||||||
"50.0",
|
"50.0",
|
||||||
"50.0",
|
"50.0",
|
||||||
"50.0",
|
"50.0",
|
||||||
"50.0",
|
|
||||||
"50.0",
|
|
||||||
"50.0",
|
|
||||||
"50",
|
"50",
|
||||||
)
|
)
|
||||||
for index, description in enumerate(NVR_SENSORS):
|
for index, description in enumerate(NVR_SENSORS):
|
||||||
@ -214,6 +213,24 @@ async def test_sensor_setup_nvr(
|
|||||||
assert state.state == expected_values[index]
|
assert state.state == expected_values[index]
|
||||||
assert state.attributes[ATTR_ATTRIBUTION] == DEFAULT_ATTRIBUTION
|
assert state.attributes[ATTR_ATTRIBUTION] == DEFAULT_ATTRIBUTION
|
||||||
|
|
||||||
|
expected_values = ("50.0", "50.0", "50.0")
|
||||||
|
for index, description in enumerate(NVR_DISABLED_SENSORS):
|
||||||
|
unique_id, entity_id = ids_from_device_description(
|
||||||
|
Platform.SENSOR, nvr, description
|
||||||
|
)
|
||||||
|
|
||||||
|
entity = entity_registry.async_get(entity_id)
|
||||||
|
assert entity
|
||||||
|
assert entity.disabled is not description.entity_registry_enabled_default
|
||||||
|
assert entity.unique_id == unique_id
|
||||||
|
|
||||||
|
await enable_entity(hass, mock_entry.entry.entry_id, entity_id)
|
||||||
|
|
||||||
|
state = hass.states.get(entity_id)
|
||||||
|
assert state
|
||||||
|
assert state.state == expected_values[index]
|
||||||
|
assert state.attributes[ATTR_ATTRIBUTION] == DEFAULT_ATTRIBUTION
|
||||||
|
|
||||||
|
|
||||||
async def test_sensor_setup_camera(
|
async def test_sensor_setup_camera(
|
||||||
hass: HomeAssistant, mock_entry: MockEntityFixture, camera: Camera, now: datetime
|
hass: HomeAssistant, mock_entry: MockEntityFixture, camera: Camera, now: datetime
|
||||||
@ -223,8 +240,6 @@ async def test_sensor_setup_camera(
|
|||||||
entity_registry = er.async_get(hass)
|
entity_registry = er.async_get(hass)
|
||||||
|
|
||||||
expected_values = (
|
expected_values = (
|
||||||
"100",
|
|
||||||
"100",
|
|
||||||
now.replace(second=0, microsecond=0).isoformat(),
|
now.replace(second=0, microsecond=0).isoformat(),
|
||||||
"100",
|
"100",
|
||||||
"100.0",
|
"100.0",
|
||||||
@ -240,7 +255,22 @@ async def test_sensor_setup_camera(
|
|||||||
assert entity.disabled is not description.entity_registry_enabled_default
|
assert entity.disabled is not description.entity_registry_enabled_default
|
||||||
assert entity.unique_id == unique_id
|
assert entity.unique_id == unique_id
|
||||||
|
|
||||||
if not description.entity_registry_enabled_default:
|
state = hass.states.get(entity_id)
|
||||||
|
assert state
|
||||||
|
assert state.state == expected_values[index]
|
||||||
|
assert state.attributes[ATTR_ATTRIBUTION] == DEFAULT_ATTRIBUTION
|
||||||
|
|
||||||
|
expected_values = ("100", "100")
|
||||||
|
for index, description in enumerate(CAMERA_DISABLED_SENSORS):
|
||||||
|
unique_id, entity_id = ids_from_device_description(
|
||||||
|
Platform.SENSOR, camera, description
|
||||||
|
)
|
||||||
|
|
||||||
|
entity = entity_registry.async_get(entity_id)
|
||||||
|
assert entity
|
||||||
|
assert entity.disabled is not description.entity_registry_enabled_default
|
||||||
|
assert entity.unique_id == unique_id
|
||||||
|
|
||||||
await enable_entity(hass, mock_entry.entry.entry_id, entity_id)
|
await enable_entity(hass, mock_entry.entry.entry_id, entity_id)
|
||||||
|
|
||||||
state = hass.states.get(entity_id)
|
state = hass.states.get(entity_id)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user