Repository navigation
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Reported by @billjes in #1043, on an Amcrest NV5232E-16P running 1.3.0-rc.1:
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 bydevice_infoand by both sensors: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_dateis 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_idon both sensors is built fromget_serial_number, the channel-suffixed bookkeeping key, and nothing here touches it. A changedunique_idorphans 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:
test_the_firmware_sensor_reports_the_camera_on_a_channel_pagetest_the_serial_sensor_reports_the_camera_on_a_channel_pagetest_the_build_date_is_dropped_when_the_firmware_is_the_camerastest_the_sensors_report_the_box_on_the_page_that_is_the_boxThree existing doubles learned the new question. One of them is in
test_sensor_entities.py, which thedevice_infodouble guard does not police because it never mentionsdevice_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_keycarried 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