From 96529ec245b2969891ea7c256d2c8657b0e91775 Mon Sep 17 00:00:00 2001 From: starkillerOG Date: Mon, 28 Jul 2025 16:12:53 +0200 Subject: [PATCH] Add Reolink pre-recording entities (#149522) Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- homeassistant/components/reolink/icons.json | 12 +++++++ homeassistant/components/reolink/number.py | 34 ++++++++++++++++++- homeassistant/components/reolink/select.py | 14 ++++++++ homeassistant/components/reolink/strings.json | 12 +++++++ homeassistant/components/reolink/switch.py | 9 +++++ .../reolink/snapshots/test_diagnostics.ambr | 4 +++ 6 files changed, 84 insertions(+), 1 deletion(-) diff --git a/homeassistant/components/reolink/icons.json b/homeassistant/components/reolink/icons.json index 0c9831af2a8..597a3372400 100644 --- a/homeassistant/components/reolink/icons.json +++ b/homeassistant/components/reolink/icons.json @@ -300,6 +300,12 @@ }, "image_hue": { "default": "mdi:image-edit" + }, + "pre_record_time": { + "default": "mdi:history" + }, + "pre_record_battery_stop": { + "default": "mdi:history" } }, "select": { @@ -390,6 +396,9 @@ "packing_time": { "default": "mdi:record-rec" }, + "pre_record_fps": { + "default": "mdi:history" + }, "post_rec_time": { "default": "mdi:record-rec" } @@ -470,6 +479,9 @@ "manual_record": { "default": "mdi:record-rec" }, + "pre_record": { + "default": "mdi:history" + }, "hub_ringtone_on_event": { "default": "mdi:music-note" }, diff --git a/homeassistant/components/reolink/number.py b/homeassistant/components/reolink/number.py index 2de2468ca3d..d0222b0cffb 100644 --- a/homeassistant/components/reolink/number.py +++ b/homeassistant/components/reolink/number.py @@ -14,7 +14,7 @@ from homeassistant.components.number import ( NumberEntityDescription, NumberMode, ) -from homeassistant.const import EntityCategory, UnitOfTime +from homeassistant.const import PERCENTAGE, EntityCategory, UnitOfTime from homeassistant.core import HomeAssistant from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback @@ -542,6 +542,38 @@ NUMBER_ENTITIES = ( value=lambda api, ch: api.image_hue(ch), method=lambda api, ch, value: api.set_image(ch, hue=int(value)), ), + ReolinkNumberEntityDescription( + key="pre_record_time", + cmd_key="594", + translation_key="pre_record_time", + entity_category=EntityCategory.CONFIG, + entity_registry_enabled_default=False, + native_step=1, + native_min_value=2, + native_max_value=10, + native_unit_of_measurement=UnitOfTime.SECONDS, + supported=lambda api, ch: api.supported(ch, "pre_record"), + value=lambda api, ch: api.baichuan.pre_record_time(ch), + method=lambda api, ch, value: api.baichuan.set_pre_recording( + ch, time=int(value) + ), + ), + ReolinkNumberEntityDescription( + key="pre_record_battery_stop", + cmd_key="594", + translation_key="pre_record_battery_stop", + entity_category=EntityCategory.CONFIG, + entity_registry_enabled_default=False, + native_step=1, + native_min_value=10, + native_max_value=80, + native_unit_of_measurement=PERCENTAGE, + supported=lambda api, ch: api.supported(ch, "pre_record"), + value=lambda api, ch: api.baichuan.pre_record_battery_stop(ch), + method=lambda api, ch, value: api.baichuan.set_pre_recording( + ch, battery_stop=int(value) + ), + ), ) SMART_AI_NUMBER_ENTITIES = ( diff --git a/homeassistant/components/reolink/select.py b/homeassistant/components/reolink/select.py index d55cf9386f9..242ea784cd9 100644 --- a/homeassistant/components/reolink/select.py +++ b/homeassistant/components/reolink/select.py @@ -250,6 +250,20 @@ SELECT_ENTITIES = ( value=lambda api, ch: str(api.bit_rate(ch, "sub")), method=lambda api, ch, value: api.set_bit_rate(ch, int(value), "sub"), ), + ReolinkSelectEntityDescription( + key="pre_record_fps", + cmd_key="594", + translation_key="pre_record_fps", + entity_category=EntityCategory.CONFIG, + entity_registry_enabled_default=False, + unit_of_measurement=UnitOfFrequency.HERTZ, + get_options=["1", "2", "5"], + supported=lambda api, ch: api.supported(ch, "pre_record"), + value=lambda api, ch: str(api.baichuan.pre_record_fps(ch)), + method=lambda api, ch, value: api.baichuan.set_pre_recording( + ch, fps=int(value) + ), + ), ReolinkSelectEntityDescription( key="post_rec_time", cmd_key="GetRec", diff --git a/homeassistant/components/reolink/strings.json b/homeassistant/components/reolink/strings.json index 1b155af6a4d..7e8bf94eeae 100644 --- a/homeassistant/components/reolink/strings.json +++ b/homeassistant/components/reolink/strings.json @@ -654,6 +654,12 @@ }, "image_hue": { "name": "Image hue" + }, + "pre_record_time": { + "name": "Pre-recording time" + }, + "pre_record_battery_stop": { + "name": "Pre-recording stop battery level" } }, "select": { @@ -858,6 +864,9 @@ "packing_time": { "name": "Recording packing time" }, + "pre_record_fps": { + "name": "Pre-recording frame rate" + }, "post_rec_time": { "name": "Post-recording time" } @@ -946,6 +955,9 @@ "manual_record": { "name": "Manual record" }, + "pre_record": { + "name": "Pre-recording" + }, "hub_ringtone_on_event": { "name": "Hub ringtone on event" }, diff --git a/homeassistant/components/reolink/switch.py b/homeassistant/components/reolink/switch.py index 47b14f7f4ad..00934bc9777 100644 --- a/homeassistant/components/reolink/switch.py +++ b/homeassistant/components/reolink/switch.py @@ -169,6 +169,15 @@ SWITCH_ENTITIES = ( value=lambda api, ch: api.manual_record_enabled(ch), method=lambda api, ch, value: api.set_manual_record(ch, value), ), + ReolinkSwitchEntityDescription( + key="pre_record", + cmd_key="594", + translation_key="pre_record", + entity_category=EntityCategory.CONFIG, + supported=lambda api, ch: api.supported(ch, "pre_record"), + value=lambda api, ch: api.baichuan.pre_record_enabled(ch), + method=lambda api, ch, value: api.baichuan.set_pre_recording(ch, enabled=value), + ), ReolinkSwitchEntityDescription( key="buzzer", cmd_key="GetBuzzerAlarmV20", diff --git a/tests/components/reolink/snapshots/test_diagnostics.ambr b/tests/components/reolink/snapshots/test_diagnostics.ambr index 25a9dc299aa..c2b059d658b 100644 --- a/tests/components/reolink/snapshots/test_diagnostics.ambr +++ b/tests/components/reolink/snapshots/test_diagnostics.ambr @@ -77,6 +77,10 @@ '0': 1, 'null': 1, }), + '594': dict({ + '0': 1, + 'null': 1, + }), 'DingDongOpt': dict({ '0': 2, 'null': 2,