Skip to content

Add smarter API usage for RainMachine#31115

Merged
balloob merged 8 commits into
home-assistant:devfrom
bachya:rainmachine-api-usage
Jan 25, 2020
Merged

Add smarter API usage for RainMachine#31115
balloob merged 8 commits into
home-assistant:devfrom
bachya:rainmachine-api-usage

Conversation

@bachya
Copy link
Copy Markdown
Contributor

@bachya bachya commented Jan 23, 2020

Proposed change

Following up on #31066 (which removed monitored conditions from RainMachine and made some of its entities disabled by default), this PR smartens up the integration's internal API object. Now, when an entity is enabled, it registers its "interest" in receiving data from specific API calls and updates accordingly. If no entities exist for a particular API call, the API object won't call it.

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New integration (thank you!)
  • New feature (which adds functionality to an existing integration)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Example entry for configuration.yaml:

# Example configuration.yaml
rainmachine:
  controllers:
    - ip_address: 192.168.1.100
      password: YOUR_PASSWORD

Additional information

  • This PR fixes or closes issue: N/A
  • This PR is related to issue: N/A
  • Link to documentation pull request: N/A

Checklist

  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist
  • The code has been formatted using Black (black --fast homeassistant tests)
  • Tests have been added to verify that the new code works.

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

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

  • The manifest file has all fields filled out correctly.
    Updated and included derived files by running: python3 -m script.hassfest.
  • New or updated dependencies have been added to requirements_all.txt.
    Updated by running python3 -m script.gen_requirements_all.
  • Untested files have been added to .coveragerc.

The integration reached or maintains the following Integration Quality Scale:

  • No score or internal
  • 🥈 Silver
  • 🥇 Gold
  • 🏆 Platinum

@bachya bachya requested a review from balloob January 23, 2020 18:47
@bachya bachya self-assigned this Jan 23, 2020
@bachya bachya changed the title Make RainMachine smarter with API usage Add smarter API usage for RainMachine Jan 23, 2020
Comment thread homeassistant/components/rainmachine/__init__.py Outdated
Comment thread homeassistant/components/rainmachine/sensor.py Outdated
Comment thread homeassistant/components/rainmachine/__init__.py Outdated
"""Increment the number of entities with data needs from an API category."""
# If this is the first registration we have, start a time interval:
if not self._async_unsub_dispatcher_connect:
self._async_unsub_dispatcher_connect = async_track_time_interval(
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why is this called dispatcher connect ?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Also, track time interval is potentially dangerous. If a request takes longer than the interval, they start overlapping.

@balloob balloob merged commit 550aa6a into home-assistant:dev Jan 25, 2020
@bachya bachya deleted the rainmachine-api-usage branch January 25, 2020 05:40
@bachya bachya mentioned this pull request Jan 25, 2020
20 tasks
@lock lock Bot locked and limited conversation to collaborators Jan 26, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants