Skip to content

Commit

Permalink
HA v0.110 cover support
Browse files Browse the repository at this point in the history
  • Loading branch information
UbhiTS authored May 23, 2020
1 parent 8806a53 commit ac81ecc
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions apps/alexa_door_window_announce.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,11 @@ def initialize(self):
if "doors_windows" in self.args:
for door_window_sensor in self.args["doors_windows"]:
states = self.get_state_values(door_window_sensor)
self.listen_state(self.door_window_state_changed, door_window_sensor, old = states[0], new = states[1], duration = self.delay.total_seconds())

if states[0] in ["cover", "sensor"]:
self.listen_state(self.door_window_state_changed, door_window_sensor, old = states[3], new = states[4], duration = self.delay.total_seconds())
else:
self.log("UNSUPPORTED DOMAIN: " + door_window_sensor)

init_log = [f"START {self.time_start}, END {self.time_end}"]

if self.delay.total_seconds() > 0:
Expand All @@ -56,17 +59,16 @@ def initialize(self):


def door_window_state_changed(self, entity, attribute, old, new, kwargs):

states = self.get_state_values(entity)

if new == states[1] and self.announce_close: # door is open, and announce_closed is True
self.listen_state(self.door_window_state_changed, entity, old = states[1], new = states[0], oneshot = True)
if new == states[4] and self.announce_close: # door is open, and announce_closed is True
self.listen_state(self.door_window_state_changed, entity, old = states[1], new = states[2], oneshot = True)

friendly_name = self.get_state(entity, attribute = "friendly_name")

state = "changed"
if new == states[0]: state = "closed"
if new == states[1]: state = "opened"
if new == states[2]: state = "closed"
if new == states[4]: state = "opened"

if datetime.now().time() < self.time_start or self.time_end < datetime.now().time():
self.log(f"DOOR/WINDOW TIME LOG ONLY: {entity.split('.')[1]}|{state}")
Expand Down Expand Up @@ -97,8 +99,8 @@ def get_state_values(self, entity):
domain = entity.split(".")[0].lower()

if domain == "cover":
return [ "closed", "open" ]
return [ "cover", "closing", "closed", "opening", "open" ]
elif domain == "binary_sensor":
return [ "off", "on" ]
return [ "sensor", "on", "off", "off", "on" ]
else:
return [ "off", "on" ]
return [ "other" ]

0 comments on commit ac81ecc

Please sign in to comment.