Add variable domain support for Home Assistant
Defaults to the hard-coded "switch" domain used before Signed-off-by: Rafael Schridi <r.schridi@gmail.com>
This commit is contained in:
parent
42bdb42573
commit
3b4bfba85e
|
@ -281,9 +281,11 @@ address:
|
||||||
port:
|
port:
|
||||||
device:
|
device:
|
||||||
token:
|
token:
|
||||||
|
domain:
|
||||||
# The above options are used for "homeassistant" devices. The
|
# The above options are used for "homeassistant" devices. The
|
||||||
# address should be a valid ip or hostname for the homeassistant controller.
|
# address should be a valid ip or hostname for the homeassistant controller.
|
||||||
# "device" should be the ID of the switch to control.
|
# "device" should be the ID of the switch to control.
|
||||||
|
# "domain" is the class of device set managed by homeassistant, defaults to "switch".
|
||||||
address:
|
address:
|
||||||
user:
|
user:
|
||||||
password:
|
password:
|
||||||
|
@ -337,6 +339,7 @@ address: 192.168.1.126
|
||||||
port: 8123
|
port: 8123
|
||||||
device: switch.1234567890abcdefghij
|
device: switch.1234567890abcdefghij
|
||||||
token: home-assistant-very-long-token
|
token: home-assistant-very-long-token
|
||||||
|
domain: switch
|
||||||
```
|
```
|
||||||
|
|
||||||
It is possible to toggle device power from the Klippy host, this can be done
|
It is possible to toggle device power from the Klippy host, this can be done
|
||||||
|
|
|
@ -657,16 +657,17 @@ class HomeAssistant(HTTPDevice):
|
||||||
super().__init__(config, default_port=8123)
|
super().__init__(config, default_port=8123)
|
||||||
self.device: str = config.get("device")
|
self.device: str = config.get("device")
|
||||||
self.token: str = config.get("token")
|
self.token: str = config.get("token")
|
||||||
|
self.domain: str = config.get("domain", "switch")
|
||||||
|
|
||||||
async def _send_homeassistant_command(self,
|
async def _send_homeassistant_command(self,
|
||||||
command: str
|
command: str
|
||||||
) -> Dict[Union[str, int], Any]:
|
) -> Dict[Union[str, int], Any]:
|
||||||
if command == "on":
|
if command == "on":
|
||||||
out_cmd = f"api/services/switch/turn_on"
|
out_cmd = f"api/services/{self.domain}/turn_on"
|
||||||
body = {"entity_id": self.device}
|
body = {"entity_id": self.device}
|
||||||
method = "POST"
|
method = "POST"
|
||||||
elif command == "off":
|
elif command == "off":
|
||||||
out_cmd = f"api/services/switch/turn_off"
|
out_cmd = f"api/services/{self.domain}/turn_off"
|
||||||
body = {"entity_id": self.device}
|
body = {"entity_id": self.device}
|
||||||
method = "POST"
|
method = "POST"
|
||||||
elif command == "info":
|
elif command == "info":
|
||||||
|
|
Loading…
Reference in New Issue