Skip to content

A sensor must not contradict the page it sits on - #1058

Open
zios0007 wants to merge 1 commit into
rroller:mainfrom
zios0007:fix/the-channel-sensors-say-the-recorder
Open

zios0007 wants to merge 1 commit into
rroller:mainfrom
zios0007:fix/the-channel-sensors-say-the-recorder

Conversation

@zios0007

Copy link
Copy Markdown
Collaborator

Reported by @billjes in #1043, on an Amcrest NV5232E-16P running 1.3.0-rc.1:

on both channels the Diagnostic firmware/serial sensors show the recorder's values (4.000.00AC000.0.R, AMR044032F4F06B33E), while Device info shows each camera's own firmware (2.460.AC01.0.R) and serial.

Two answers to one question, a few centimetres apart on the same page.

The page was right. #1044 made a recorder channel's device page describe the camera in that slot, and #1054 gave the box a page of its own to be described on. These two sensors were never moved with it.

One rule, not two copies

The condition that decides whose identity a page shows was written out twice, which is how the page and the sensors drifted apart. It is now stands_in_for_the_host() on the coordinator, defined once and read by device_info and by both sensors:

return (
    self.get_serial_number() == self.get_device_serial_number()
    and not self.uses_separate_host_device()
)

True only for the lowest channel of a device with no separate host device, which is the one page that has to describe the box, because the box has nowhere else to be described. A standalone camera is unaffected: it is that page.

The build date

get_build_date is the box's, and #1044 deliberately strips the date from the camera version it reads out of the slot table. Showing both would have paired the recorder's build date with a camera's version, which is the same disagreement one level quieter and much less likely to get reported. The attribute is now only shown alongside the box's own firmware.

What does not move

unique_id on both sensors is built from get_serial_number, the channel-suffixed bookkeeping key, and nothing here touches it. A changed unique_id orphans the entity and takes its history and its automations with it, so there is a test pinning both keys.

Tests

A new file with nine tests, and four mistakes reintroduced to check they are caught:

reintroduced caught by
the firmware sensor reports the box on every page test_the_firmware_sensor_reports_the_camera_on_a_channel_page
the serial sensor reports the box on every page test_the_serial_sensor_reports_the_camera_on_a_channel_page
the box's build date beside a camera's firmware test_the_build_date_is_dropped_when_the_firmware_is_the_cameras
the camera's value wins on the box's own page test_the_sensors_report_the_box_on_the_page_that_is_the_box

Three existing doubles learned the new question. One of them is in test_sensor_entities.py, which the device_info double guard does not police because it never mentions device_info; it was found by grepping for the sensor classes instead of waiting for CI to say so.

test_the_serial_sensor_reports_the_device_serial_not_the_entity_key carried the rationale "every channel of one NVR is the same box and must say the same serial", which this makes false. Its surviving claim, that the value is a serial and not the _15-suffixed entity key, is still asserted under a name that matches it.

🤖 Generated with Claude Code

Reported in rroller#1043 on an Amcrest NV5232E-16P. A channel's device page showed the
camera's firmware 2.460.AC01.0.R and the camera's serial, while the Firmware
version and Serial number sensors on that same page showed the recorder's
4.000.00AC000.0.R and AMR044032F4F06B33E. Two answers to one question, a few
centimetres apart.

The page was right. rroller#1044 made a recorder channel's page describe the camera in
that slot, and rroller#1054 gave the box a page of its own to be described on. These
two sensors were simply not moved with it, so they went on reporting the box
from a page that is now a camera's.

The rule that decides this was written out twice, which is how they drifted. It
is now `stands_in_for_the_host` on the coordinator, defined once and read by
`device_info` and by both sensors. True only for the lowest channel of a device
with no separate host device, which is the page that has to describe the box
because the box has nowhere else to be described.

The build date goes with the firmware it belongs to. `get_build_date` is the
box's, and the camera's version comes out of the recorder's slot table with its
date stripped (rroller#1044), so showing both would have put the recorder's build date
beside a camera's version: the same disagreement, one level quieter and far
less likely to be reported.

unique_id is untouched. Both keys are built from the channel-suffixed
bookkeeping key, and a changed unique_id orphans the entity along with its
history and anything automating on it. There is a test saying so.

Four mistakes reintroduced and all four caught: either sensor reporting the box
everywhere, the build date shown beside a camera's firmware, and the camera's
value winning on the page that is the box's. Three doubles learned the new
question, one of them in a file the device_info guard does not police, found by
grepping for the classes rather than waiting for CI.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant