power: Add https support for Home Assistant

Signed-off-by:  Alan Harper <alan@aussiegeek.net>
This commit is contained in:
Alan Harper 2021-05-30 00:08:24 +10:00 committed by Eric Callahan
parent 793ab6b24b
commit 541f5e54dc
1 changed files with 4 additions and 2 deletions

View File

@ -281,7 +281,8 @@ class HTTPDevice(PowerDevice):
config: ConfigHelper,
default_port: int = -1,
default_user: str = "",
default_password: str = ""
default_password: str = "",
default_protocol: str = "http"
) -> None:
super().__init__(config)
self.client = AsyncHTTPClient()
@ -290,6 +291,7 @@ class HTTPDevice(PowerDevice):
self.port = config.getint("port", default_port)
self.user = config.get("user", default_user)
self.password = config.get("password", default_password)
self.protocol = config.get("protocol", default_protocol)
async def initialize(self) -> None:
await self.refresh_status()
@ -673,7 +675,7 @@ class HomeAssistant(HTTPDevice):
else:
raise self.server.error(
f"Invalid homeassistant command: {command}")
url = f"http://{self.addr}:{self.port}/{out_cmd}"
url = f"{self.protocol}://{self.addr}:{self.port}/{out_cmd}"
headers = {
'Authorization': f'Bearer {self.token}',
'Content-Type': 'application/json'