Skip to content

Commit ba8538c

Browse files
committed
Set the Cover to a specific percentage
1 parent 3a9bae8 commit ba8538c

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

plugin.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"Name": "HA-Commander",
55
"Description": "Search, and interact with Home Assistant using Wox or Flow Launcher.",
66
"Author": "Garulf",
7-
"Version": "5.2.1",
7+
"Version": "5.3.0",
88
"Language": "python",
99
"Website": "https://github.com/Garulf/HA-Commander",
1010
"IcoPath": "icons\\home-assistant.png",

plugin/homeassistant.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -503,3 +503,17 @@ def _default_action(self):
503503
def press(self) -> None:
504504
"""Press button"""
505505
self._client.call_services("button", "press", data=self.target)
506+
507+
class Cover(Entity):
508+
"""Representation of a Cover entity."""
509+
def __init__(self, client: Client, entity: dict) -> None:
510+
super().__init__(client, entity)
511+
self.current_position = self._entity["attributes"].get("current_position", 'None')
512+
self.current = entity.get("attributes", "").get("current_position", "");
513+
514+
def _current_position(self, current_position: int) -> None:
515+
"""Set Current Postion of the Cover."""
516+
#self.turn_on(**{"current_position": current_position})
517+
data = self.target
518+
data["position"] = current_position
519+
self._client.call_services("cover", "set_cover_position", data=data)

plugin/main.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,10 @@ def query(self, query):
9898
entity.entity_id, "light"
9999
):
100100
subtitle = f"{subtitle} - Press ENTER to change brightness to: {q.split('_')[-1]}%"
101+
if q.split("_")[-1].isdigit() and self.client.domain(
102+
entity.entity_id, "cover"
103+
):
104+
subtitle = f"{subtitle} - Press ENTER to open Cover to: {q.split('_')[-1]}%"
101105
self.add_item(
102106
title=f"{entity.friendly_name or entity.entity_id}",
103107
subtitle=subtitle.replace("_", " ").title(),
@@ -165,6 +169,11 @@ def action(self, entity_id, query="", service="_default_action"):
165169
and query.split("_")[-1].isdigit()
166170
):
167171
entity._brightness_pct(int(query.split("_")[-1]))
172+
elif (
173+
self.client.domain(entity.entity_id, "cover")
174+
and query.split("_")[-1].isdigit()
175+
):
176+
entity._current_position(int(query.split("_")[-1]))
168177
else:
169178
getattr(entity, service)()
170179
except (HTTPError, ReadTimeout, ConnectionError):

0 commit comments

Comments
 (0)