dahua
dahua copied to clipboard
Support for adjust focus function
Utilizing this integration to auto-set the profile of a z12e for night/day. My headache is that the focus for the two sensors is just slightly off. It looks like bp2008's service was running a method utilizing http://
Thank you though for this integration, made my life a lot easier than having to run a windows service.
Agree with above commenter. Need to see if able to zoom in or zoom out like BP's service :)
My experience with github isn't the greatest so I won't try and do a pull request (as well as this is my first time toying around with python, so I bet there are better ways to do what I did other than just frankensteining your current work)
I created an adjust focus method that utilizes the above api. You would need to pull your current zoom/focus from your camera to utilize in your service calls. You could also incorporate a call to "/cgi-bin/devVideoInput.cgi?action=getFocusStatus" to get those current values as well.
One headache that would need to be taken into account is that you have to call the method a couple times over a few seconds each attempt. It appears that when you first call it tries to adjust the zoom and focus at the same time which it doesn't like, so each successive call gets the zoom into the right position then gets the focus in the right location
Hope you consider it worth adding into the integration :)
Oh also, the items added
Camera.py:
SERVICE_SET_FOCUS_ZOOM = "set_focus_zoom"
platform.async_register_entity_service(
SERVICE_SET_FOCUS_ZOOM,
{
vol.Required("focus", default=""): str,
vol.Required("zoom", default=""): str,
},
"async_adjustfocus"
)
async def async_adjustfocus(self, focus: str, zoom: str):
""" Handles the service call from SERVICE_SET_INFRARED_MODE to set zoom and focus """
await self._coordinator.client.async_adjustfocus_v1(focus, zoom)
await self._coordinator.async_refresh()
Services.yaml:
set_focus_zoom:
name: Set the Dahua Focus and Zoom
description: Sets the camera's focus and zoom
target:
entity:
integration: dahua
domain: camera
fields:
focus:
name: focus
description: "Decimal Value for Focus"
example: "0.758333"
required: true
default: "0.758333"
selector:
text:
zoom:
name: zoom
description: "Decimal value for zoom"
example: "0.898502"
required: true
default: "0.898502"
selector:
text:
Client.py:
async def async_adjustfocus_v1(self, focus: str, zoom: str):
"""
async_adjustfocus will set the zoom and focus
"""
url = "/cgi-bin/devVideoInput.cgi?action=adjustFocus&focus={0}&zoom={1}".format(focus, zoom)
return await self.get(url, True)