Skip to content

Commit 89c5d49

Browse files
authored
Add Reolink Ai person type, vehicle type and animal type (home-assistant#153170)
1 parent 76cb4d1 commit 89c5d49

File tree

4 files changed

+77
-0
lines changed

4 files changed

+77
-0
lines changed

homeassistant/components/reolink/icons.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,15 @@
462462
},
463463
"sd_storage": {
464464
"default": "mdi:micro-sd"
465+
},
466+
"person_type": {
467+
"default": "mdi:account"
468+
},
469+
"vehicle_type": {
470+
"default": "mdi:car"
471+
},
472+
"animal_type": {
473+
"default": "mdi:paw"
465474
}
466475
},
467476
"siren": {

homeassistant/components/reolink/sensor.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from decimal import Decimal
99

1010
from reolink_aio.api import Host
11+
from reolink_aio.const import YOLO_DETECT_TYPES
1112
from reolink_aio.enums import BatteryEnum
1213

1314
from homeassistant.components.sensor import (
@@ -135,6 +136,39 @@ class ReolinkHostSensorEntityDescription(
135136
value=lambda api, ch: api.wifi_signal(ch),
136137
supported=lambda api, ch: api.supported(ch, "wifi"),
137138
),
139+
ReolinkSensorEntityDescription(
140+
key="person_type",
141+
cmd_id=696,
142+
translation_key="person_type",
143+
device_class=SensorDeviceClass.ENUM,
144+
options=YOLO_DETECT_TYPES["people"],
145+
value=lambda api, ch: api.baichuan.ai_detect_type(ch, "person"),
146+
supported=lambda api, ch: (
147+
api.supported(ch, "ai_yolo_type") and api.supported(ch, "ai_people")
148+
),
149+
),
150+
ReolinkSensorEntityDescription(
151+
key="vehicle_type",
152+
cmd_id=696,
153+
translation_key="vehicle_type",
154+
device_class=SensorDeviceClass.ENUM,
155+
options=YOLO_DETECT_TYPES["vehicle"],
156+
value=lambda api, ch: api.baichuan.ai_detect_type(ch, "vehicle"),
157+
supported=lambda api, ch: (
158+
api.supported(ch, "ai_yolo_type") and api.supported(ch, "ai_vehicle")
159+
),
160+
),
161+
ReolinkSensorEntityDescription(
162+
key="animal_type",
163+
cmd_id=696,
164+
translation_key="animal_type",
165+
device_class=SensorDeviceClass.ENUM,
166+
options=YOLO_DETECT_TYPES["dog_cat"],
167+
value=lambda api, ch: api.baichuan.ai_detect_type(ch, "dog_cat"),
168+
supported=lambda api, ch: (
169+
api.supported(ch, "ai_yolo_type") and api.supported(ch, "ai_dog_cat")
170+
),
171+
),
138172
)
139173

140174
HOST_SENSORS = (

homeassistant/components/reolink/strings.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -930,6 +930,29 @@
930930
},
931931
"sd_storage": {
932932
"name": "SD {hdd_index} storage"
933+
},
934+
"person_type": {
935+
"name": "Person type",
936+
"state": {
937+
"man": "Man",
938+
"woman": "Woman"
939+
}
940+
},
941+
"vehicle_type": {
942+
"name": "Vehicle type",
943+
"state": {
944+
"sedan": "Sedan",
945+
"suv": "SUV",
946+
"pickup_truck": "Pickup truck",
947+
"motorcycle": "Motorcycle"
948+
}
949+
},
950+
"animal_type": {
951+
"name": "Animal type",
952+
"state": {
953+
"dog": "Dog",
954+
"cat": "Cat"
955+
}
933956
}
934957
},
935958
"siren": {

tests/components/reolink/conftest.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,17 @@ def _init_host_mock(host_mock: MagicMock) -> None:
185185
host_mock.baichuan.smart_ai_index.return_value = 1
186186
host_mock.baichuan.smart_ai_name.return_value = "zone1"
187187

188+
def ai_detect_type(channel: int, object_type: str) -> str | None:
189+
if object_type == "people":
190+
return "man"
191+
if object_type == "dog_cat":
192+
return "dog"
193+
if object_type == "vehicle":
194+
return "motorcycle"
195+
return None
196+
197+
host_mock.baichuan.ai_detect_type = ai_detect_type
198+
188199

189200
@pytest.fixture
190201
def reolink_host_class() -> Generator[MagicMock]:

0 commit comments

Comments
 (0)