From 0274a641b2493356f3ed91847833d0364295df09 Mon Sep 17 00:00:00 2001 From: Arksine Date: Mon, 10 May 2021 07:41:33 -0400 Subject: [PATCH] power: add LoxoneV1 support This is a refactored version of loxone V1 support submitted by EraserFX. Closes PR #94. Signed-off-by: Eric Callahan --- moonraker/components/power.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/moonraker/components/power.py b/moonraker/components/power.py index 3d370cf..65770c3 100644 --- a/moonraker/components/power.py +++ b/moonraker/components/power.py @@ -31,6 +31,7 @@ class PrinterPower: "shelly": Shelly, "homeseer": HomeSeer, "homeassistant": HomeAssistant, + "loxonev1": Loxonev1 } try: for section in prefix_sections: @@ -638,6 +639,36 @@ class HomeAssistant(HTTPDevice): res = await self._send_homeassistant_command(state) return res[0][f"state"] +class Loxonev1(HTTPDevice): + def __init__(self, config): + super().__init__(config, default_user="admin", + default_password="admin") + self.output_id = config.get("output_id", "") + + async def _send_loxonev1_command(self, command): + if command in ["on", "off"]: + out_cmd = f"jdev/sps/io/{self.output_id}/{command}" + elif command == "info": + out_cmd = f"jdev/sps/io/{self.output_id}" + else: + raise self.server.error(f"Invalid loxonev1 command: {command}") + if self.password != "": + out_pwd = f"{self.user}:{self.password}@" + else: + out_pwd = f"" + url = f"http://{out_pwd}{self.addr}/{out_cmd}" + return await self._send_http_command(url, command) + + async def _send_status_request(self): + res = await self._send_loxonev1_command("info") + state = res[f"LL"][f"value"] + return "on" if int(state) == 1 else "off" + + async def _send_power_request(self, state): + res = await self._send_loxonev1_command(state) + state = res[f"LL"][f"value"] + return "on" if int(state) == 1 else "off" + # The power component has multiple configuration sections def load_component_multi(config):