Files
zoneminder/scripts/ZoneMinder/t/hikvision_light.t
T
Isaac ConnorandClaude Opus 4.8 e5bdb5f7a1 feat: add white-light (CanLight) control to HikVision/LTS module refs #4895
Add lightOn/lightOff/lightStatus to the HikVision control module, driving the
camera's ISAPI supplement light (ISAPI/Image/channels/<n>/supplementLight).
"On" selects the white light where the model has one (colorVuWhiteLight), else
IR; "off" restores the camera's smart/auto default (eventIntelligence) so night
IR keeps working. The methods GET the current document and rewrite only
<supplementLightMode>, preserving the std-cgi namespace and the sibling
brightness fields the firmware rejects PUTs without. Mode selection is driven by
the model's advertised supplementLight/capabilities. lightStatus returns
{ WhiteLight => 'On'|'Off'|undef } in the shape the existing web toggle consumes,
so no web changes are needed (the CanLight UI is already generic).

Add a model-specific Controls row for the LTS CMIP1342WE-28MDA (a fixed ColorVu
camera: white light, reboot, no PTZ/focus/iris), in zm_create.sql.in and
migration zm_update-1.39.16.sql. Bump version to 1.39.16.

The pure mode-selection/XML helpers are covered by t/hikvision_light.t. Verified
live against a CMIP1342WE-28MDA: the GET-modify-PUT round-trip turns the white
light on and restores the prior mode.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-09 19:59:10 -05:00

67 lines
3.1 KiB
Perl

use strict;
use warnings;
use Test::More tests => 16;
require_ok('ZoneMinder::Control::HikVision');
my $P = 'ZoneMinder::Control::HikVision';
# --- mode selection (pure, capability-driven) ---------------------------------
# ColorVu model: white light available -> "on" uses it, "off" restores smart auto.
is($P->can('light_on_mode')->(qw(eventIntelligence colorVuWhiteLight irLight close)),
'colorVuWhiteLight', 'on prefers colorVuWhiteLight when present');
is($P->can('light_on_mode')->(qw(irLight close)),
'irLight', 'on falls back to irLight on IR-only models');
is($P->can('light_on_mode')->(qw(close)),
undef, 'on is undef when the model exposes no illuminator');
is($P->can('light_off_mode')->(qw(eventIntelligence colorVuWhiteLight irLight close)),
'eventIntelligence', 'off restores eventIntelligence so night IR keeps working');
is($P->can('light_off_mode')->(qw(irLight close)),
'irLight', 'off falls back to irLight when there is no smart mode');
is($P->can('light_off_mode')->(qw(colorVuWhiteLight close)),
'close', 'off falls back to close as a last resort');
# --- parsing real LTS/std-cgi camera XML --------------------------------------
my $doc = '<?xml version="1.0" encoding="UTF-8"?>'."\n"
.'<SupplementLight version="2.0" xmlns="http://www.std-cgi.com/ver20/XMLSchema">'
.'<supplementLightMode>eventIntelligence</supplementLightMode>'
.'<mixedLightBrightnessRegulatMode>auto</mixedLightBrightnessRegulatMode>'
.'<whiteLightBrightness>100</whiteLightBrightness>'
.'</SupplementLight>';
is($P->can('light_mode_from_xml')->($doc), 'eventIntelligence',
'reads the active supplementLightMode from a camera document');
my $caps = '<SupplementLight><supplementLightMode '
.'opt="eventIntelligence,colorVuWhiteLight,irLight,close">eventIntelligence'
.'</supplementLightMode></SupplementLight>';
is_deeply([$P->can('light_modes_from_caps')->($caps)],
[qw(eventIntelligence colorVuWhiteLight irLight close)],
'reads the advertised mode list from a capabilities document');
# --- the GET-modify-PUT rewrite preserves everything but the mode -------------
my $white = $P->can('light_apply_mode')->($doc, 'colorVuWhiteLight');
like($white, qr{<supplementLightMode>colorVuWhiteLight</supplementLightMode>},
'mode is rewritten to the requested value');
like($white, qr{xmlns="http://www\.std-cgi\.com/ver20/XMLSchema"},
'namespace is preserved through the rewrite');
like($white, qr{<whiteLightBrightness>100</whiteLightBrightness>},
'sibling fields the firmware requires are preserved');
# --- toggle-button status mapping ---------------------------------------------
is($P->can('light_status_from')->('colorVuWhiteLight',
qw(eventIntelligence colorVuWhiteLight irLight close)),
'On', 'white light active reports On');
is($P->can('light_status_from')->('eventIntelligence',
qw(eventIntelligence colorVuWhiteLight irLight close)),
'Off', 'smart default reports Off');
is($P->can('light_status_from')->('irLight', qw(irLight close)),
'On', 'IR active on an IR-only model reports On');
is($P->can('light_status_from')->(undef, qw(irLight close)),
undef, 'unknown current mode reports undef');