Skip to content
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

Added optional setting http_proxy to push_image #144

Merged
merged 10 commits into from
Sep 1, 2024
17 changes: 12 additions & 5 deletions custom_components/openhasp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
ATTR_FORCE_FITSCREEN,
ATTR_HEIGHT,
ATTR_IDLE,
ATTR_PROXY,
ATTR_IMAGE,
ATTR_OBJECT,
ATTR_PAGE,
Expand Down Expand Up @@ -153,6 +154,7 @@ def hasp_object(value):
{
vol.Required(ATTR_IMAGE): vol.Any(cv.url, cv.isfile),
vol.Required(ATTR_OBJECT): hasp_object,
vol.Optional(ATTR_PROXY): cv.url,
vol.Optional(ATTR_WIDTH): cv.positive_int,
vol.Optional(ATTR_HEIGHT): cv.positive_int,
vol.Optional(ATTR_FORCE_FITSCREEN): cv.boolean,
Expand Down Expand Up @@ -587,7 +589,7 @@ async def async_config_service(self, submodule, parameters):
)

async def async_push_image(
self, image, obj, width=None, height=None, fitscreen=False
self, image, obj, http_proxy=None, width=None, height=None, fitscreen=False
):
"""Update object image."""

Expand All @@ -601,10 +603,15 @@ async def async_push_image(

cmd_topic = f"{self._topic}/command/{obj}.src"

rgb_image_url = (
f"{get_url(self.hass, allow_external=False)}/api/openhasp/serve/{image_id}"
)

if http_proxy:
rgb_image_url = (
f"{http_proxy}/api/openhasp/serve/{image_id}"
)
else:
rgb_image_url = (
f"{get_url(self.hass, allow_external=False)}/api/openhasp/serve/{image_id}"
)
#self._entry.data
_LOGGER.debug("Push %s with %s", cmd_topic, rgb_image_url)

await async_publish(self.hass, cmd_topic, rgb_image_url, qos=0, retain=False)
Expand Down
1 change: 1 addition & 0 deletions custom_components/openhasp/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@
ATTR_COMMAND_PARAMETERS = "parameters"
ATTR_CONFIG_SUBMODULE = "submodule"
ATTR_CONFIG_PARAMETERS = "parameters"
ATTR_PROXY = "http_proxy"
ATTR_IMAGE = "image"
ATTR_OBJECT = "obj"
ATTR_WIDTH = "width"
Expand Down
7 changes: 7 additions & 0 deletions custom_components/openhasp/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,13 @@ push_image:
example: "https://people.sc.fsu.edu/~jburkardt/data/jpg/lena.jpg"
selector:
text:
http_proxy:
name: HTTP (Reverse) Proxy
description: Proxy address to use. This can be used to allow HTTP access to an otherwise SSL secured HA instance. Offering the proxy functionality is out of the scope of this integration.
required: false
example: "http://people.sc.fsu.edu:port"
selector:
text:
obj:
name: Object
description: Object ID in the format p#b##
Expand Down
Loading