Repository navigation
Conversation
24d641d to
c6b1967
Compare
mezz64
left a comment
There was a problem hiding this comment.
I'm onboard with adding this, but considering the ISAPI functionality is only a subset of what pyHik can do, I don't know that the path should be simply called "check" as i'd expect that to check the basic event stream functionality. I think this is better suited as "checkiaspi" or something similar so a separate module can be added later to perform the same function on the base event stream monitoring code.
Also, the readme changes need cleaned up now that #151 is merged and I'd prefer you split out the xmldict change into a separate PR.
Otherwise a review flagged a couple small issues:
- An error during the restore step in check_write can hide the original error, and the restore keeps sending requests after an auth error.
- The restore writes back every value that changed, not just the ones in result.also_changed.
- TESTING.md says cd pyhik; it should be cd pyHik.
07943e0 to
083ec2a
Compare
|
Made all the changes you requested. It was trouble to fix conflicts, I started over and ended up w/ a single commit :/ Putting here below the actual changes per your comments, made since your previous review.
Rename done.
Added
Done. |
|
Omg... I thought I'd create the first PR for Home-Assistant (core and docs) and ended up creating them as Draft. I think I'm starting a headache :D I'll revisit them later. |
|
Thanks for working through all of that, and no worries about the single commit. The rename and the Another pass turned up a few more things, mostly in the restore paths. I'd like these fixed before merging, since they can leave a camera with changed settings or add failed logins:
There are also some smaller things (a TESTING.md note about port 443, |
A rejected login or a missing permission (401 or 403) is not carried on from: the run stops at that request and prevents a wrong password to be tried again.
put_back now reads the device first and only writes what differs from before. When the write raised, that is everything that differs, not just the setting under test. If the device cannot be read at that point, the run fails and says to compare WDR, HLC, BLC and defog by hand. Reading first also means nothing is written when the device refused the change and nothing differs.
The restore now goes through put_back, as --write does. Nothing is sent after an authentication error and every setting is reported as NOT TRIED with its old value; any other error is reported for that setting and the rest are still put back. Only the settings the last case left different are written, instead of every feature twice.
The conflicts check only restored the settings it had built a table for. Now after a restore, any other setting that differs from before is listed in a "note:" line and left alone. The check did not change it (a device can reset a level when its feature is switched), it;s not written, but it is no longer left unmentioned.
The table only knew HLC as a plain switch and BLC as a mode linked to its enabled flag. Firmware that has it the other way round (HLC/HLCMode linked to HLC/enabled, or a BLC mode list without an off option) lost that row without notice, and with fewer than two rows the check was skipped. Both are now built the same way: a linked select if pyhik reports one, otherwise the enabled switch. From Hikvision NVR dev guide: HLC with a mode: - One HLC block has <enabled> plus <HLCMode opt="close,open,auto"> and <HLCLevel>. That is the linked-select form pyHik folds into one setting, with “close” as the off value. - HLC as a plain switch: Another HLC block has only <enabled> and <HLCLevel>, with no mode. That matches a DS-2CD2385G1. The guide documents both forms, which is why this patch builds HLC as a linked select when pyHik reports one and as a plain switch otherwise. - BLC: <BLCMode opt="UP,DOWN,LEFT,RIGHT,CENTER,MULTI-AREA,Region,AUTO"> has no “close”. pyHik won’t fold it, so BLC stays a plain switch with a separate mode That is the plain-switch BLC form that is now handle.
get_image_settings also lists what the capabilities offer but the current document leaves out, with the default as its value (example, the levels of a noise reduction mode that is not selected). --write --path on one of those failed with pathNotFound and then reported a failed restore. - Such a path is a SKIP that says why. - A number is not moved outside its range - The paths suggested after a plain --write are ones that can be changed.
- TESTING.md said port 443 enables HTTPS. It does not: CAMERA_SSL=1 or --ssl does, and then 443 is the default port. - -v no longer loses pyhik's debug log during --conflicts. The check lowered the logger to INFO to collect the conflict codes even when it was already at DEBUG. - A failed write says whether the device refused it (with the reason) or accepted it and read back something else. - A conflict case whose starting point could not be set up is marked "?" instead of being tried anyway, the summary counts those, and a table with no case tried is a SKIP, not a PASS. - --path without --write is an error instead of being ignored. - The client is closed at the end of the run. - Removed the check for a pyhik without HikCamera.auth_failed, and an except clause that named a subclass next to its base class. - Tests for --bad-password, which had none.
|
If I had to start over, conflict resolution and perhaps even checkisapi would not exist :) it has honestly turned into a massive beast. To tackle this cleanly, I fed the Hikvision NVR developer guide into Claude to cross-reference everything, trying to make sure we hit every edge case, fix any other possible bugs and tie up loose ends from your last review. It did find quite a lot. It found quite a lot more than I would have expended. I did multiple commit, will make your life easier. If you find there's too many changes, please blame Claude ;) That said, I had to reinstall MacOS and doing that nuked my VPN configuration :( I'm away from home since 2 days, I can't test anything until I return sometimes next week or weekend. If you have time to test, great... otherwise perhaps we wait before merging this PR and just move ahead with a release? As you wish, I don't mind. |
|
Thanks for working through all of those. Every item from my last comment is addressed, and the extra tests (including the first ones for I ran it against a camera on my local network, a DS-2CD3132-I on firmware V5.2.5:
What I couldn't check is the BLC/HLC side: the conflicts table, the linked BLC restore, and recovery after a failed write. This camera has no HLC or defog. Its firmware also lists Since that's where most of the new restore logic lives, I'll cut the release without this one. Once you're back and can run |
|
@mezz64 @ptarjan thank you both for taking the time to make this happen! I see 0.5.0 is released and I agree the current PR (154) can be merged later. I'm not sure yet when I'll be home to test w/ my camera. I'll update once I have done that. I admit I was a bit depressed with all the PRs to open with HA core and the docs. I took a Claude subscription and ask to create the docs and assemble all the core PRs. I was still unhappy to have to open all those PRs... so I ask Claude to write a script, open the documentation PRs, use the create PR and include it in the core PR (documentation link), etc. I just ran the script but I won't have time to check them all tonight. I hope Claude did everything good ;) Documentations : 01-50766-verify-ssl - Review ready Core pyHik 0.5.0: 00-193189-bump-pyhik - Merged pyHik 0.5.1+: 01-158-stream-auth-failed - Review ready Core pyHik 0.5.1+: 19-193297-bump-pyhik-0-5-1 |
|
I'm using this PR to update you on the latest. First ... I have a 3-4 months trip abroad leaving in ~ 2-4 weeks, haven't decided of the date yet. I will have my computer with me but won't be on it often. I feel rushed to open PRs to get things done before I leave :( The HA integration on my side was running just fine but yesterday Claude identified a lot of things (not sure if I should cry or laugh!). If you have time to review any PR / leave comments, please go ahead. I do plan to review and tests all changes myself whenever I get back home.
hikvision-core-11-bump-pyhik-0-5-1 I'm editing the list in previous comments to add those. I should have time to check the updated and new core PRs before my 2 appointments but might not have time to fix anything :/ |
|
I forgot 1 thing... since I have plenty of Claude token, I ask to check HA Hikvision code and it came with a long list of things. I won't create those PRs, I think we have plenty now but before losing them, I'll create the branch in my repo and you could consult them and decide if anything should be prioritized. I'll let you know once this is done. |
|
Unless you flag any changes, I'm done with all of the Draft or Open PRs in pyHik, HA core & home-assistant.io I wasn't expecting Copilot to find so many things that Claude didn't get right at first. Copilot being a MS product and Github owned by MS probably explains why it found so many little things. Obviously MS likely trained Copilot using Github repos, PR descriptions, etc. Copilot isn't perfect either, sometimes it would flag a change in a PR but the code was implemented in a previous PR (stackable) and ... new things to resolve would popup. If I knew it would have taken many days to go over all the Copilot comments, maybe I'd never started this work. I'll admit at some point I gave up on validating any changes and relied purely on Anthropic and Copilot to agree on the changes. After all Copilot comments on all PRs were all resolved, I went ahead and ask Anthropic to check edge cases for all HA changes based on the pyHik changes from 0.4.8 to 0.5.1. Here's the report and all 3 changes were pushed minutes ago: Updated PRs list in this comment below. I now need to take care of my family and might not have time to test anything this coming week as I need to prep my long trip. |
|
I figured I'd ask Claude "Go over all HA changes we made, make sure tests cover everything so that if some logic is broken, any test will tell us" - it's not over yet but from the output, more tests are coming and perhaps fixes as well. Will update later, need to run errands. |
After reading the below report, I feel more confident things might still be working :) FYI coverage sits now at a whopping 99% of lines and branches! Tests that catch broken logicEvery condition, call and return in the code the stack changed was broken on purpose What changed
Kept on purpose (no test can tell them apart): thread-race guards, shutdown of The above list of PRs have been updated; that said, we still need to test everything manually :/ |
|
I woke up early this morning and figured I should test and eat my own dogfood :) I installed hikksion w/ PR 193190 to 193199 coming w/ pyHik 0.5.0 ; nothing is broken, I'm amazed everything works as it should except so far 1 bug need to be addressed, likely in pyHik. There's a zip file here you can download and unzip in /config: Test w/ camera DS-2CD2385G1-I
Bug
I propose we fix this in pyHik PR #161 ; this is cleaner for every pyHik user but for this bug to be closed requires a new pyHik release. Investigate
Note : I didn't test every single number, select, and switch but I did most of them. Findings
New PR
Changes to open core PRs following tests and reading the logs
CopilotWith the above new/change PRs, it raised a few comments; everything has been addressed... Copilot is a great coworker for Claude :D |
|
Took many breaks from prepping my long trip, and came up with missing items to add.
Once the PRs are open I'll add them to the list in this comment. |
|
@baylanger since the NVR parts can't be tested on your side, a reference that might help: the custom integration maciej-or/hikvision_next has been running on real NVRs for a while. Reading it at f6dac0da, three spots where it does something different from #163 / #162, offered as questions rather than blockers (mezz64's call):
Note that hikvision_next has no license file (its issue #384), so endpoints and quirks are fair to learn from, but the code shouldn't be copied. |
|
@ptarjan indeed hikvision_next has no license, so I didn't peak at the code. Getting XML output from a NVR would help code everything the right way. If #162 & #163 aren't complete, we can address them later. As I don't even have a NVR, honestly I don't need them :) but if we completed them, it might give me a reason to get a NVR ;) |
|
@ptarjan I just realized I have the NVR developer guide ... PDF file. Claude could probably analyze it and figure it all out but I'm almost out of token for the rest of the week, currently at 95% :( Will have to wait 'til Saturday. |
|
@ptarjan On the NVR parts... I uploaded to Claude a while ago the NVR developer guide, gotta wonder why he didn't look at it while writing the NVR code. Any good engineers would have done that ;) Here's Claude response after asking to refer to the dev. guide and if we missed anything :) and I'm at 96% ... so I just ask Claude to work on the PRs. Yes, I still have it: the NVR guide is in your uploads, along with the core protocol guide, and I checked both. The basics we built match the documented formats:
What we're missing, most important first:
Things we could add but I'd leave out for now:
|
|
If this can make your life easier I made a new release ; it includes all hikvision and pyHik PRs. In the release notes you will find the list of the included files as well as for the PRs. I installed it earlier and did a few tests; everything seems to work just fine with a camera. |
Add
python -m pyhik checkisapiA check to run by hand against a real camera or NVR. Unit tests have to run
without hardware. This is for people with a device who want to try the
image settings code or report a problem.
python -m pyhik <command>is a small dispatcher (pyhik/__main__.py) that imports acommand only when it is asked for.
checkisapiis the first command, so others (for exampledump) can be added later.Run
Optional:
CAMERA_PORT(80, or 443 with HTTPS),CAMERA_SSL=1,CAMERA_VERIFY_SSL=0for aself-signed certificate.
--host,--port,--username,--ssland--no-verifydo the same asCAMERA_HOST,CAMERA_PORT,CAMERA_USERNAME,CAMERA_SSL=1andCAMERA_VERIFY_SSL=0, and win overthem. The password is read only from the environment, never from the command line, and never printed.
What it does
python -m pyhik checkisapi... --writeColor/brightnessLevelby one step, reads it back, restores it.... --write --path Color/contrastLevel--pathis only used with--write.... --conflicts... --bad-passwordISAPIClientandHikCamera: at least two failed logins.... --all... -vA plain
--writeends by naming a few switch and select paths to try with--path. If a changeswitches another setting off to make room (WDR, BLC, HLC and defog exclude each other), that setting
is put back too and listed.
One channel is checked per run (the first listed unless
--channelisgiven). On an NVR or DVR the attached camera is used through the ImageProxy
endpoints:
The NVR is detected from the device type. That is not enough on its own: some NVRs report
IPC, and the device information may not be readable at all. When the camera image endpoints failand the NVR ones work, the NVR endpoints are used, and it prints which it chose and why.
--proxy/--no-proxyoverride the detection.The device information is asked once per run, whether it answers or not. When it fails, the device
line shows the error with its HTTP status (for example
model=? (ISAPIError: Request failed with status 503)) and the run goes on.Safety
after an error, and prints
NOT RESTORED, set it back by handif itcould not.
lock an account.
--bad-passwordmakes at least two failed logins (one perclient, more if a client retries); do not use it on an account that is close
to being locked.
Tested
Unit tests (
test/test_check.py) cover the NVR detection, the write path (number, switch, select, a conflict, a failed restore), the connection options (host, port, username, HTTPS, certificate check) and thepython -m pyhikdispatch, with fake devices.On real camera DS-2CD2385G1
On a DS-7608NI-EV2/8P NVR (V3.4.96): 8 channels listed, a read, and a write of a switch
(enableImageLossDetection) through ImageProxy with the read back and the restore both
checked.
Dependencies
[ ] Requires #151 (PR4 List image channels and support NVR-attached cameras through ImageProxy) to be merged first.