From 7fc571643d8fd78773a2a02f350db43f5ae934e4 Mon Sep 17 00:00:00 2001 From: wollew Date: Sat, 23 Dec 2023 00:19:05 +0100 Subject: [PATCH] power: enable HTTP port option for Zigbee/Hue devices Signed-off-by: Wolfgang Miller-Reichling --- docs/configuration.md | 4 ++++ moonraker/components/power.py | 6 +++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/docs/configuration.md b/docs/configuration.md index 2e8ee92..d45b723 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -1269,6 +1269,10 @@ The following options are available for `hue` device types: address: # A valid ip address or hostname of the Philips Hue Bridge. This # parameter must be provided. +port: +# A port number if an alternative Zigbee bridge is used on a HTTP port +# different from the default 80/443 +# user: # The api key used for request authorization. This option accepts # Jinja2 Templates, see the [secrets] section for details. diff --git a/moonraker/components/power.py b/moonraker/components/power.py index 355688b..ad9c42e 100644 --- a/moonraker/components/power.py +++ b/moonraker/components/power.py @@ -1381,7 +1381,7 @@ class MQTTDevice(PowerDevice): class HueDevice(HTTPDevice): def __init__(self, config: ConfigHelper) -> None: - super().__init__(config) + super().__init__(config, default_port=80) self.device_id = config.get("device_id") self.device_type = config.get("device_type", "light") if self.device_type == "group": @@ -1394,7 +1394,7 @@ class HueDevice(HTTPDevice): async def _send_power_request(self, state: str) -> str: new_state = True if state == "on" else False url = ( - f"{self.protocol}://{quote(self.addr)}/api/{quote(self.user)}" + f"{self.protocol}://{quote(self.addr)}:{self.port}/api/{quote(self.user)}" f"/{self.device_type}s/{quote(self.device_id)}" f"/{quote(self.state_key)}" ) @@ -1410,7 +1410,7 @@ class HueDevice(HTTPDevice): async def _send_status_request(self) -> str: url = ( - f"{self.protocol}://{quote(self.addr)}/api/{quote(self.user)}" + f"{self.protocol}://{quote(self.addr)}:{self.port}/api/{quote(self.user)}" f"/{self.device_type}s/{quote(self.device_id)}" ) ret = await self.client.request("GET", url)