Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MyQ updates, scan_interval, status retries #17535

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 71 additions & 6 deletions homeassistant/components/cover/myq.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
https://home-assistant.io/components/cover.myq/
"""
import logging

from datetime import timedelta
from time import sleep
import voluptuous as vol

from homeassistant.components.cover import (
Expand All @@ -15,7 +16,7 @@
STATE_OPEN, STATE_OPENING)
import homeassistant.helpers.config_validation as cv

REQUIREMENTS = ['pymyq==0.0.15']
REQUIREMENTS = ['pymyq==0.0.16']

_LOGGER = logging.getLogger(__name__)

Expand All @@ -37,6 +38,8 @@
vol.Required(CONF_PASSWORD): cv.string
})

SCAN_INTERVAL = timedelta(seconds=120)


def setup_platform(hass, config, add_entities, discovery_info=None):
"""Set up the MyQ component."""
Expand Down Expand Up @@ -76,7 +79,11 @@ def __init__(self, myq, device):
self.myq = myq
self.device_id = device['deviceid']
self._name = device['name']
self._status = None

if self.myq.get_status(self.device_id):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this and instead call add_entities with second argument True. It will make sure update is called during entity addition.

Also, this would have made two requests to get the same status. That seems inefficient.

self._status = self.myq.get_status(self.device_id)
else:
self._status = None

@property
def device_class(self):
Expand Down Expand Up @@ -112,11 +119,65 @@ def is_opening(self):

def close_cover(self, **kwargs):
"""Issue close command to cover."""
self.myq.close_device(self.device_id)
iterations = 0
while True:
if self.myq.close_device(self.device_id):
break
if iterations > 5:
_LOGGER.error(
"Failed to close %s "
"after 6 attempts", self._name)
break
iterations += 1
sleep(10)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sleep is not allowed in our thread pool.


if iterations <= 5:
closed_confired_interations = 0
while True:
self._status = self.myq.get_status(self.device_id)
if self._status == STATE_CLOSED:
break
if closed_confired_interations > 5:
_LOGGER.error(
"Failed to confirm closed status for %s "
"after 60 seconds", self._name)
self._status = None
break
closed_confired_interations += 1
sleep(10)

return iterations <= 5 and closed_confired_interations <= 5

def open_cover(self, **kwargs):
"""Issue open command to cover."""
self.myq.open_device(self.device_id)
iterations = 0
while True:
if self.myq.open_device(self.device_id):
break
if iterations > 5:
_LOGGER.error(
"Failed to open %s "
"after 6 attempts", self._name)
break
iterations += 1
sleep(10)

if iterations <= 5:
open_confirmed_interations = 0
while True:
self._status = self.myq.get_status(self.device_id)
if self._status == STATE_OPEN:
break
if open_confirmed_interations > 5:
_LOGGER.error(
"Failed to confirm open status for %s "
"after 60 seconds", self._name)
self._status = None
break
open_confirmed_interations += 1
sleep(10)

return iterations <= 5 and open_confirmed_interations <= 5

@property
def supported_features(self):
Expand All @@ -130,4 +191,8 @@ def unique_id(self):

def update(self):
"""Update status of cover."""
self._status = self.myq.get_status(self.device_id)
current = self.myq.get_status(self.device_id)
if current is not False:
self._status = current
else:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This case is already handled in is_closed.

self._status = None
2 changes: 1 addition & 1 deletion requirements_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -999,7 +999,7 @@ pymonoprice==0.3
pymusiccast==0.1.6

# homeassistant.components.cover.myq
pymyq==0.0.15
pymyq==0.0.16

# homeassistant.components.mysensors
pymysensors==0.17.0
Expand Down