Skip to content

Add config flow for Rain Bird#85271

Merged
allenporter merged 19 commits into
home-assistant:devfrom
allenporter:rainbird-config-entry
Jan 7, 2023
Merged

Add config flow for Rain Bird#85271
allenporter merged 19 commits into
home-assistant:devfrom
allenporter:rainbird-config-entry

Conversation

@allenporter
Copy link
Copy Markdown
Contributor

@allenporter allenporter commented Jan 6, 2023

Breaking change

Rainbird is now configured via the UI and configuration from YAML has been imported. However, there are a few notable changes:

  • Custom per zone overrides for irrigation time are no longer supported.
  • The Rain delay binary_sensor that duplicates the Rain delay time sensor has been removed. You should move all uses to the sensor value and check for a non-zero value to get equivalent behavior.
  • The Rain sensor that duplicates the Rain binary_sensor has been removed. You may check the binary_sensor state to get equivalent behavior.
  • The set_rain_delay now requires a configuration entry parameter. Previously the service had undefined behavior when multiple devices were configured.

Note for release notes maintainer: The last bullet can be superseded by the breaking change note in #86208

Proposed change

Add a config flow for Rain Bird. Existing YAML configuration is imported, with the exception of per-zone overrides for irrigation time which are not supported. Irrigation times can be specified with a service call.

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)
  • Deprecation (breaking change to happen in the future)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Additional information

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.
  • For the updated dependencies - a link to the changelog, or at minimum a diff between library versions is added to the PR description.
  • Untested files have been added to .coveragerc.

To help with the load of incoming pull requests:

@home-assistant
Copy link
Copy Markdown
Contributor

home-assistant Bot commented Jan 6, 2023

Hey there @konikvranik, mind taking a look at this pull request as it has been labeled with an integration (rainbird) you are listed as a code owner for? Thanks!

Code owner commands

Code owners of rainbird can trigger bot actions by commenting:

  • @home-assistant close Closes the issue.
  • @home-assistant rename Awesome new title Change the title of the issue.
  • @home-assistant reopen Reopen the issue.
  • @home-assistant unassign rainbird Removes the current integration label and assignees on the issue, add the integration domain after the command.

Comment thread homeassistant/components/rainbird/__init__.py Outdated
hass, "Rain delay", controller.get_rain_delay
)

hass.data[DOMAIN][entry.entry_id] = {
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.

I recommend using a dataclass to store multiple items in hass.data.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Based on this comment and the comment about initializing the update coordinators in the platforms, I decided to just simplify the overall interactions between the device and the integration, moving all the rpcs into a single data update coordinator. This required changing the tests, so i added additional test fixtures to help manage the request setup and ordering expected by the integration.

The consequence of this is now a single update coordinator handles rpcs for all platforms so there isn't independence for each sensor, but in hindsight that is probably simpler overall (e.g. if the device is offline, there is just one coordinator trying to hit it rather than 3).

While I was here, I also removed some unnecessary duplicate sensors. Today there is a rain sensor and a rain delay sensor both exported as a sensor and binary sensor and it doesn't really make a lot of sense to me. I've just left the sensors that provide unique value and have updated the breaking changes in the description.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

If this is too much for a single PR, I can break into smaller chunks, or move into another branch to not have to worry about leaving dev in a bad state.

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.

It's not too much.

What did the four binary sensors and sensors represent? How would a user replace the removed sensors?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

There were four total sensors representing two values that were redundant. I updated the PR to describe but can reword if it is not clear.

The "rain" sensor was a binary sensor and a sensor with a string boolean value. This represents whether the device knows it is raining (I'm not sure if it's from a separate sensors only or also from a cloud weather report)

The "rain delay" represents the number of days that the sprinkler is paused due to rain. This is a sensor and also had a binary sensor when it was non-zero. The rain delay service can update this value so maybe this should just be a Number?

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.

Ok.

Yeah, if the rain delay service and sensor are in sync it should be a number entity.

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.

We can deprecate the service and raise a repair issue telling users to move to the number entity and service when that's in place.

Comment thread homeassistant/components/rainbird/__init__.py Outdated
Comment thread homeassistant/components/rainbird/__init__.py Outdated
Comment thread homeassistant/components/rainbird/binary_sensor.py Outdated
Comment thread homeassistant/components/rainbird/strings.json Outdated
Comment thread homeassistant/components/rainbird/switch.py Outdated
Comment thread tests/components/rainbird/conftest.py Outdated
Comment thread tests/components/rainbird/conftest.py
Comment thread homeassistant/components/rainbird/switch.py Outdated
Comment thread homeassistant/components/rainbird/switch.py Outdated
Comment thread homeassistant/components/rainbird/config_flow.py Outdated
Comment thread homeassistant/components/rainbird/switch.py Outdated
allenporter and others added 2 commits January 6, 2023 14:43
Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
Comment thread homeassistant/components/rainbird/__init__.py Outdated
Copy link
Copy Markdown
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.

Great!

Further work is good to do in follow ups. 👍

@allenporter allenporter merged commit 5000c42 into home-assistant:dev Jan 7, 2023
@github-actions github-actions Bot locked and limited conversation to collaborators Jan 8, 2023
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.

2 participants