-
-
Notifications
You must be signed in to change notification settings - Fork 37.5k
Centralize rainbird config and add binary sensor platform #26393
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
Merged
Merged
Changes from all commits
Commits
Show all changes
60 commits
Select commit
Hold shift + click to select a range
ec79e0c
Update pyrainbird to version 0.2.0 to fix zone number issue:
konikvranik d747c58
requirements_all.txt regenerated
konikvranik fa2a54f
code formatting
konikvranik b18237d
pyrainbird version 0.3.0
konikvranik b84a89c
zone id
konikvranik 22dad98
rainsensor return state
konikvranik f2c96bb
updating rainsensor
konikvranik ea1595d
new version of pyrainbird
konikvranik d74495b
binary sensor state
konikvranik 1ebf820
quiet in check format
konikvranik 967c3e9
is_on instead of state for binary_sensor
konikvranik 6f513b2
no unit of measurement for binary sensor
konikvranik e8af86a
no monitored conditions config
konikvranik 59db275
get keys of dict directly
konikvranik 3cd2b04
removed redundant update of state
konikvranik d1758c1
simplified switch
konikvranik 54df464
right states for switch
konikvranik 7375f46
raindelay sensor
konikvranik 9a6821e
raindelay sensor
konikvranik d8e95f6
binary sensor state
konikvranik de5ba57
binary sensor state
konikvranik f7b670b
reorganized imports
konikvranik 5586685
doc on public method
konikvranik cfc61c8
reformatted
konikvranik 80756ef
add irrigation service to rain bird, which allows you to set the dura…
peternijssen 3813223
rebased on konikvranik and solved some feedback
peternijssen 36fb700
add irrigation service to rain bird
konikvranik 0c72ebd
sensor types to constants
konikvranik d265f2f
synchronized register service
konikvranik d4cc15a
patform discovery
konikvranik 547d17f
binary sensor as wrapper to sensor
konikvranik 457c8a5
version 0.4.0
konikvranik f6ccdf0
new config approach
konikvranik 05127ec
sensors cleanup
konikvranik 7d0e9e7
bypass if no zones found
konikvranik a3e12fb
platform schema removed
konikvranik a9b90bc
Change config schema to list of controllers
konikvranik b5bbce5
some small code improvements as suggested in CR:
konikvranik 49d4bd2
No single controller configuration
konikvranik 11153f6
pyrainbird 0.4.1
konikvranik f1efbd7
individual switch configuration
konikvranik 15a218d
imports order
konikvranik 0b4ad97
generate default name out of entity
konikvranik 96974c4
trigger time required for controller
konikvranik 322dba1
incorporated CR remarks:
konikvranik 2343c6c
import of library on top
konikvranik f1c4df4
refactored
konikvranik b26f5cd
Update homeassistant/components/rainbird/__init__.py
konikvranik 4abc751
validate time and set defaults
konikvranik 390298b
set defaults on right place
konikvranik 9881d3e
pylint bypass
konikvranik b1f589c
iterate over values
konikvranik 1053aba
codeowner
konikvranik 60ae83a
reverted changes:
konikvranik e0dc5e9
codeowners updated
konikvranik 7745ac9
accept timedelta in irrigation time
konikvranik 8d5c117
simplified time calculation
konikvranik 2489566
call total_seconds
konikvranik da40302
irrigation time as seconds.
konikvranik 292a238
simplified schema
konikvranik 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 hidden or 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
This file contains hidden or 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 |
|---|---|---|
| @@ -1,42 +1,91 @@ | ||
| """Support for Rain Bird Irrigation system LNK WiFi Module.""" | ||
| import logging | ||
|
|
||
| from pyrainbird import RainbirdController | ||
| import voluptuous as vol | ||
|
|
||
| from homeassistant.components import binary_sensor, sensor, switch | ||
| from homeassistant.const import ( | ||
| CONF_FRIENDLY_NAME, | ||
| CONF_HOST, | ||
| CONF_PASSWORD, | ||
| CONF_TRIGGER_TIME, | ||
| ) | ||
| from homeassistant.helpers import discovery | ||
| import homeassistant.helpers.config_validation as cv | ||
| from homeassistant.const import CONF_HOST, CONF_PASSWORD | ||
|
|
||
| CONF_ZONES = "zones" | ||
|
|
||
| SUPPORTED_PLATFORMS = [switch.DOMAIN, sensor.DOMAIN, binary_sensor.DOMAIN] | ||
|
|
||
| _LOGGER = logging.getLogger(__name__) | ||
|
|
||
| RAINBIRD_CONTROLLER = "controller" | ||
| DATA_RAINBIRD = "rainbird" | ||
| DOMAIN = "rainbird" | ||
|
|
||
| CONFIG_SCHEMA = vol.Schema( | ||
| SENSOR_TYPE_RAINDELAY = "raindelay" | ||
| SENSOR_TYPE_RAINSENSOR = "rainsensor" | ||
| # sensor_type [ description, unit, icon ] | ||
| SENSOR_TYPES = { | ||
| SENSOR_TYPE_RAINSENSOR: ["Rainsensor", None, "mdi:water"], | ||
| SENSOR_TYPE_RAINDELAY: ["Raindelay", None, "mdi:water-off"], | ||
| } | ||
|
|
||
| TRIGGER_TIME_SCHEMA = vol.All( | ||
| cv.time_period, cv.positive_timedelta, lambda td: (td.total_seconds() // 60) | ||
| ) | ||
|
|
||
| ZONE_SCHEMA = vol.Schema( | ||
| { | ||
| DOMAIN: vol.Schema( | ||
| {vol.Required(CONF_HOST): cv.string, vol.Required(CONF_PASSWORD): cv.string} | ||
| ) | ||
| }, | ||
| vol.Optional(CONF_FRIENDLY_NAME): cv.string, | ||
| vol.Optional(CONF_TRIGGER_TIME): TRIGGER_TIME_SCHEMA, | ||
| } | ||
| ) | ||
| CONTROLLER_SCHEMA = vol.Schema( | ||
| { | ||
| vol.Required(CONF_HOST): cv.string, | ||
| vol.Required(CONF_PASSWORD): cv.string, | ||
| vol.Required(CONF_TRIGGER_TIME): TRIGGER_TIME_SCHEMA, | ||
| vol.Optional(CONF_ZONES): vol.Schema({cv.positive_int: ZONE_SCHEMA}), | ||
| } | ||
| ) | ||
| CONFIG_SCHEMA = vol.Schema( | ||
| {DOMAIN: vol.Schema(vol.All(cv.ensure_list, [CONTROLLER_SCHEMA]))}, | ||
| extra=vol.ALLOW_EXTRA, | ||
| ) | ||
|
|
||
|
|
||
| def setup(hass, config): | ||
| """Set up the Rain Bird component.""" | ||
| conf = config[DOMAIN] | ||
| server = conf.get(CONF_HOST) | ||
| password = conf.get(CONF_PASSWORD) | ||
|
|
||
| from pyrainbird import RainbirdController | ||
| hass.data[DATA_RAINBIRD] = [] | ||
| success = False | ||
| for controller_config in config[DOMAIN]: | ||
| success = success or _setup_controller(hass, controller_config, config) | ||
|
|
||
| controller = RainbirdController(server, password) | ||
| return success | ||
|
|
||
| _LOGGER.debug("Rain Bird Controller set to: %s", server) | ||
|
|
||
| initial_status = controller.currentIrrigation() | ||
| if initial_status and initial_status["type"] != "CurrentStationsActiveResponse": | ||
| _LOGGER.error("Error getting state. Possible configuration issues") | ||
| def _setup_controller(hass, controller_config, config): | ||
| """Set up a controller.""" | ||
| server = controller_config[CONF_HOST] | ||
| password = controller_config[CONF_PASSWORD] | ||
| controller = RainbirdController(server, password) | ||
| position = len(hass.data[DATA_RAINBIRD]) | ||
| try: | ||
| controller.get_serial_number() | ||
| except Exception as exc: # pylint: disable=W0703 | ||
| _LOGGER.error("Unable to setup controller: %s", exc) | ||
| return False | ||
|
|
||
| hass.data[DATA_RAINBIRD] = controller | ||
| hass.data[DATA_RAINBIRD].append(controller) | ||
| _LOGGER.debug("Rain Bird Controller %d set to: %s", position, server) | ||
| for platform in SUPPORTED_PLATFORMS: | ||
| discovery.load_platform( | ||
| hass, | ||
| platform, | ||
| DOMAIN, | ||
| {RAINBIRD_CONTROLLER: position, **controller_config}, | ||
| config, | ||
| ) | ||
| return True | ||
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| """Support for Rain Bird Irrigation system LNK WiFi Module.""" | ||
| import logging | ||
|
|
||
| from pyrainbird import RainbirdController | ||
|
konikvranik marked this conversation as resolved.
|
||
|
|
||
| from homeassistant.components.binary_sensor import BinarySensorDevice | ||
|
|
||
| from . import ( | ||
| DATA_RAINBIRD, | ||
| RAINBIRD_CONTROLLER, | ||
| SENSOR_TYPE_RAINDELAY, | ||
| SENSOR_TYPE_RAINSENSOR, | ||
| SENSOR_TYPES, | ||
| ) | ||
|
|
||
| _LOGGER = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| def setup_platform(hass, config, add_entities, discovery_info=None): | ||
| """Set up a Rain Bird sensor.""" | ||
| if discovery_info is None: | ||
| return | ||
|
|
||
| controller = hass.data[DATA_RAINBIRD][discovery_info[RAINBIRD_CONTROLLER]] | ||
| add_entities( | ||
| [RainBirdSensor(controller, sensor_type) for sensor_type in SENSOR_TYPES], True | ||
| ) | ||
|
|
||
|
|
||
| class RainBirdSensor(BinarySensorDevice): | ||
| """A sensor implementation for Rain Bird device.""" | ||
|
|
||
| def __init__(self, controller: RainbirdController, sensor_type): | ||
| """Initialize the Rain Bird sensor.""" | ||
| self._sensor_type = sensor_type | ||
| self._controller = controller | ||
| self._name = SENSOR_TYPES[self._sensor_type][0] | ||
| self._icon = SENSOR_TYPES[self._sensor_type][2] | ||
| self._state = None | ||
|
|
||
| @property | ||
| def is_on(self): | ||
| """Return true if the binary sensor is on.""" | ||
| return None if self._state is None else bool(self._state) | ||
|
|
||
| def update(self): | ||
| """Get the latest data and updates the states.""" | ||
| _LOGGER.debug("Updating sensor: %s", self._name) | ||
| state = None | ||
| if self._sensor_type == SENSOR_TYPE_RAINSENSOR: | ||
| state = self._controller.get_rain_sensor_state() | ||
| elif self._sensor_type == SENSOR_TYPE_RAINDELAY: | ||
| state = self._controller.get_rain_delay() | ||
| self._state = None if state is None else bool(state) | ||
|
|
||
| @property | ||
| def name(self): | ||
| """Return the name of this camera.""" | ||
| return self._name | ||
|
|
||
| @property | ||
| def icon(self): | ||
| """Return icon.""" | ||
| return self._icon | ||
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| start_irrigation: | ||
| description: Start the irrigation | ||
| fields: | ||
| entity_id: | ||
| description: Name of a single irrigation to turn on | ||
| example: 'switch.sprinkler_1' | ||
| duration: | ||
| description: Duration for this sprinkler to be turned on | ||
| example: 1 |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.