Skip to content

Commit

Permalink
Fix Issue #263 : "Alarm Input 1" switch is disable for Cameras (#264)
Browse files Browse the repository at this point in the history
Co-authored-by: Maciej <38075949+maciej-or@users.noreply.github.com>
  • Loading branch information
lebretr and maciej-or authored Nov 28, 2024
1 parent 9e3c8de commit 5eb05fa
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
7 changes: 3 additions & 4 deletions custom_components/hikvision_next/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,9 @@ async def async_setup_entry(
for event in camera.events_info:
entities.append(EventSwitch(camera.id, event, events_coordinator))

# NVR supported events
if device.device_info.is_nvr:
for event in device.events_info:
entities.append(EventSwitch(0, event, events_coordinator))
# Device supported events
for event in device.events_info:
entities.append(EventSwitch(0, event, events_coordinator))

# Output port switch
for i in range(1, device.capabilities.output_ports + 1):
Expand Down
17 changes: 17 additions & 0 deletions tests/test_switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,23 @@ async def test_event_switch_state(
assert switch_entity.disabled


@pytest.mark.parametrize("init_integration", ["DS-2CD2T86G2-ISU"], indirect=True)
async def test_event_switch_state_of_a_camera(
hass: HomeAssistant,
init_integration: MockConfigEntry,
) -> None:
"""Test switch state of a camera."""

for entity_id, state in [
("switch.ds_2cd2t86g2_isu_sl00000000aawrae0000000_1_fielddetection", STATE_ON),
("switch.ds_2cd2t86g2_isu_sl00000000aawrae0000000_1_scenechangedetection", STATE_ON),
("switch.ds_2cd2t86g2_isu_sl00000000aawrae0000000_1_io", STATE_OFF),
("switch.ds_2cd2t86g2_isu_sl00000000aawrae0000000_1_alarm_output", STATE_OFF)
]:
assert (switch := hass.states.get(entity_id))
assert switch.state == state


@pytest.mark.parametrize("init_integration", ["DS-7608NXI-I2"], indirect=True)
async def test_event_switch_payload(hass: HomeAssistant, init_integration: MockConfigEntry) -> None:
"""Test event switch."""
Expand Down

0 comments on commit 5eb05fa

Please sign in to comment.