From ba8538cec2bcf18c1c7054931458c53bf2493527 Mon Sep 17 00:00:00 2001 From: D3thRoned <19372864+D3thRoned@users.noreply.github.com> Date: Sat, 18 Jan 2025 13:12:24 +0000 Subject: [PATCH] Set the Cover to a specific percentage --- plugin.json | 2 +- plugin/homeassistant.py | 14 ++++++++++++++ plugin/main.py | 9 +++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/plugin.json b/plugin.json index 86e6ead..713272f 100644 --- a/plugin.json +++ b/plugin.json @@ -4,7 +4,7 @@ "Name": "HA-Commander", "Description": "Search, and interact with Home Assistant using Wox or Flow Launcher.", "Author": "Garulf", - "Version": "5.2.1", + "Version": "5.3.0", "Language": "python", "Website": "https://github.com/Garulf/HA-Commander", "IcoPath": "icons\\home-assistant.png", diff --git a/plugin/homeassistant.py b/plugin/homeassistant.py index 436fda1..b89e01f 100644 --- a/plugin/homeassistant.py +++ b/plugin/homeassistant.py @@ -503,3 +503,17 @@ def _default_action(self): def press(self) -> None: """Press button""" self._client.call_services("button", "press", data=self.target) + +class Cover(Entity): + """Representation of a Cover entity.""" + def __init__(self, client: Client, entity: dict) -> None: + super().__init__(client, entity) + self.current_position = self._entity["attributes"].get("current_position", 'None') + self.current = entity.get("attributes", "").get("current_position", ""); + + def _current_position(self, current_position: int) -> None: + """Set Current Postion of the Cover.""" + #self.turn_on(**{"current_position": current_position}) + data = self.target + data["position"] = current_position + self._client.call_services("cover", "set_cover_position", data=data) diff --git a/plugin/main.py b/plugin/main.py index c49a605..d13dcee 100644 --- a/plugin/main.py +++ b/plugin/main.py @@ -98,6 +98,10 @@ def query(self, query): entity.entity_id, "light" ): subtitle = f"{subtitle} - Press ENTER to change brightness to: {q.split('_')[-1]}%" + if q.split("_")[-1].isdigit() and self.client.domain( + entity.entity_id, "cover" + ): + subtitle = f"{subtitle} - Press ENTER to open Cover to: {q.split('_')[-1]}%" self.add_item( title=f"{entity.friendly_name or entity.entity_id}", subtitle=subtitle.replace("_", " ").title(), @@ -165,6 +169,11 @@ def action(self, entity_id, query="", service="_default_action"): and query.split("_")[-1].isdigit() ): entity._brightness_pct(int(query.split("_")[-1])) + elif ( + self.client.domain(entity.entity_id, "cover") + and query.split("_")[-1].isdigit() + ): + entity._current_position(int(query.split("_")[-1])) else: getattr(entity, service)() except (HTTPError, ReadTimeout, ConnectionError):