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

Conversation

arraylabs
Copy link
Contributor

Description:

  • default SCAN_INTERVAL defined as 120 seconds not the standard 15 seconds
  • SCAN_INTERVAL (the default of 120 seconds) can be overridden in configuration.yaml with scan_interval on the component
  • Switch to 0.0.16 of the pymyq library which includes an endpoint change for get_status, its a more direct endpoint and the return is much smaller. Also retries 3 times for status update if server returns an error.
  • change init to check door status immediately and if fails fall back to None, better than waiting for the update to get the status after HA start/restart
  • Updates to close_cover and open_cover based on @ehendrix23 code with additional status check. Does two things, retries sending the open/close command if it initially fails the API call. Once API is successful it queries status until it gets an open or close status or fails. Provides a quicker update of confirmed open/close than waiting for update to occur.
  • Change to update to check for False from pymyq and return either current status or None.

Related issue (if applicable): fixes #17301 #16244 #16078 #9193(maybe)

Pull request in home-assistant.io with documentation (if applicable): home-assistant/home-assistant.io#6873

Example entry for configuration.yaml (if applicable):

cover:
  - platform: myq
    username: !secret myq_username
    password: !secret myq_password
    type: chamberlain
    scan_interval: 300

Checklist:

  • The code change is tested and works locally.
  • Local tests pass with tox. Your PR cannot be merged unless tests pass

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • New dependencies have been added to the REQUIREMENTS variable (example).
  • New dependencies are only imported inside functions that use them (example).
  • New or updated dependencies have been added to requirements_all.txt by running script/gen_requirements_all.py.
  • New files were added to .coveragerc.

If the code does not interact with devices:

  • Tests have been added to verify that the new code works.

- default SCAN_INTERVAL defined as 120 seconds not the standard 15 seconds
- SCAN_INTERVAL (the default of 120 seconds) can be overridden in configuration.yaml with scan_interval on the component
- Switch to 0.0.16 of the pymyq library which includes an endpoint change for get_status, its a more direct endpoint and the return is much smaller. Also retries 3 times for status update if server returns an error.
- change init to check door status immediately and if fails fall back to None, better than waiting for the update to get the status after HA start/restart
- Updates to close_cover and open_cover based on @ehendrix23 code with additional status check. Does two things, retries sending the open/close command if it initially fails the API call. Once API is successfull it queries status until it gets an open or close status or fails. Provides a quicker update of confirmed open/close than waiting for update to occur.
- Change to update to check for False from pymyq and return either current status or None.
@@ -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.

"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.

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.

Copy link
Member

@MartinHjelmare MartinHjelmare left a comment

Choose a reason for hiding this comment

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

There is also usage of sleep in the pymyq library. That isn't allowed either while using the home assistant thread pool. If you need to sleep either run a separate thread or move to asyncio.

@arraylabs
Copy link
Contributor Author

@MartinHjelmare Thanks for the feedback! I will get the items requested changed. I didn't like the use of sleep myself and will look into changing things to asyncio (haven't used it before) as that appears the best path. I did just find information in the developer docs so I will get going through those. I'm not really a python programmer so I'm feeling some of this out along on the way.

@bachya
Copy link
Contributor

bachya commented Oct 16, 2018

@arraylabs I'm a MyQ owner and am well-versed in asyncio; happy to submit a PR to pymyq (or, if you'd rather do it, I'm at your disposal for help, questions, etc.). 👍

@arraylabs
Copy link
Contributor Author

@bachya I would welcome a PR or any help you could provide. I've only had a chance to glance over the asyncio docs on the dev site but haven't been able to dig into them yet.

@bachya
Copy link
Contributor

bachya commented Oct 20, 2018

You got it! I’ll be in touch soon.

@bachya
Copy link
Contributor

bachya commented Oct 23, 2018

@arraylabs I've submitted a PR to turn your library to async: arraylabs/pymyq#11 – I've also included suggestions for how to proceed with this PR. Let me know!

@bachya bachya mentioned this pull request Nov 15, 2018
6 tasks
@balloob
Copy link
Member

balloob commented Nov 27, 2018

This PR seems to have gone stale. Closing it.

@balloob balloob closed this Nov 27, 2018
@ghost ghost removed the in progress label Nov 27, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

MyQ - 500 Server Error
5 participants