-
-
Notifications
You must be signed in to change notification settings - Fork 32k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Extracting zoneminder to a new library #16527
Extracting zoneminder to a new library #16527
Conversation
|
||
|
||
def get_state(api_url): | ||
"""Get a state from the ZoneMinder API service.""" | ||
return _zm_request('get', api_url) | ||
global ZM | ||
return ZM._zm_request('get', api_url) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would make more sense to make a method get_state
in the ZoneMinder
class. The user of the library should probably not need to know what request method to use or what api url to use, only the state id to get. Or have specific methods for different state ids.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed, this is temporary situation (so I didn't [completely] break the sensor/switch) until I was done refactoring.
|
||
|
||
def change_state(api_url, post_data): | ||
"""Update a state using the Zoneminder API.""" | ||
return _zm_request('post', api_url, data=post_data) | ||
global ZM | ||
return ZM._zm_request('post', api_url, data=post_data) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See above. This would only need to accept the new state info and the state id.
'api/monitors/%i.json' % self._monitor_id | ||
) | ||
monitor = zoneminder.get_state(self.hass, | ||
'api/monitors/%i.json' % self._monitor_id) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
line too long (81 > 79 characters)
archived_filter) | ||
) | ||
event = zoneminder.get_state(self.hass, | ||
'api/events/consoleEvents/{}{}.json'.format( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
line too long (81 > 79 characters)
@MartinHjelmare I believe everything should be all set here besides publishing zm-py to pypi and setting the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks very good. A question and some comments.
CONF_NAME: monitor.name, | ||
CONF_MJPEG_URL: monitor.mjpeg_image_url, | ||
CONF_STILL_IMAGE_URL: monitor.still_image_url | ||
} | ||
super().__init__(hass, device_info) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hass
isn't used by the MjpegCamera
init method. It would be nice to clean that up in a separate PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, I'm happy to take care of that after this one
@MartinHjelmare All comments addressed, library published on pypi and Also since I plan on maintaining these components and own the new library, it might make sense to add me to |
self._on_state = on_state | ||
self._off_state = off_state | ||
self._state = None | ||
|
||
@property | ||
def name(self): | ||
"""Return the name of the switch.""" | ||
return "%s State" % self._monitor_name | ||
return '{}\'s State'.format(self._monitor.name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like we have changed the name here by including an apostrophe. That will also change the entity_id and make this a breaking change. Is that necessary?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wait, apostrophes should be removed by the core from the entity_id, so maybe this is ok.
Please confirm that we don't change the entity_id.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The apostrophe addition was to make the friendly name make more sense:
FrontDoor's State
makes more grammatical sense that FrontDoors State
(which was the predecessor).
I wanted to drop the s
and just make it FrontDoor State
but didn't because it would change the entity_id
. I can confirm that the entity_id
should not change. My switch is still called switch.frontdoors_state
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This did in fact change the entity names by adding an "s" :(
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mnoorenberghe I'm confused. The s
was always in the name. The only change I made there was to add an '
Can you give an example of what your switch was named before/after this change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's incorrect, %s
is for the format identifier for a string so %s
would be replaced by "Basement" for example. There was no literal 's' before.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The previous code was like:
return "{} State".format(self._monitor_name)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
D'oh you are right. I totally messed that up when changing it to the .format
approach for string formatting. :(
@MartinHjelmare is this something we want to hotfix? Because it's now a breaking change. But fixing it would make another breaking change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#17026 to fix this
conf.get(CONF_PATH_ZMS), | ||
conf.get(CONF_VERIFY_SSL)) | ||
|
||
return hass.data[DOMAIN].login() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will this log an error and return False
if eg credentials are bad?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome!
Please make a new PR and add yourself to codeowners. 👍 |
Thanks @MartinHjelmare. I'll follow up with one for removing |
Description:
In #15324, @jantman was trying to expose the ZoneMinder run state to Home Assistant and @MartinHjelmare and @balloob asked for the device specific logic to be moved to a new pypi library before any new functionality changes be made.
I've taken a first stab at splitting out the platform with the
camera.zoneminder
component so far. I was hoping to get a quick review to confirm that I'm on the right track before I continued with migrating outswitch.zoneminder
andsensor.zoneminder
. I have intentionally not set theREQUIREMENTS
variable since I have not published the library yet.I've spun up a new repo to hold the new library and have opened a PR in it for visibility: rohankapoorcom/zm-py#2
This should not require any configuration changes (nor any documentation updates) in Home Assistant.
Checklist:
tox
. Your PR cannot be merged unless tests passIf the code communicates with devices, web services, or third-party tools:
REQUIREMENTS
variable (example).requirements_all.txt
by runningscript/gen_requirements_all.py
.