-
-
Notifications
You must be signed in to change notification settings - Fork 31.9k
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
arraylabs
wants to merge
4
commits into
home-assistant:dev
from
arraylabs:myq-fix-status-updates-scan-interval
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 ( | ||
|
@@ -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__) | ||
|
||
|
@@ -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.""" | ||
|
@@ -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): | ||
self._status = self.myq.get_status(self.device_id) | ||
else: | ||
self._status = None | ||
|
||
@property | ||
def device_class(self): | ||
|
@@ -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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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): | ||
|
@@ -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: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This case is already handled in |
||
self._status = None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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 argumentTrue
. It will make sureupdate
is called during entity addition.Also, this would have made two requests to get the same status. That seems inefficient.