power: enable HTTP port option for Zigbee/Hue devices

Signed-off-by: Wolfgang Miller-Reichling <wolfgang+github@miller-reichling.de>
This commit is contained in:
wollew 2023-12-23 00:19:05 +01:00 committed by GitHub
parent 088d9ee59a
commit 7fc571643d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 3 deletions

View File

@ -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.

View File

@ -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)