Skip to content
Merged
Show file tree
Hide file tree
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 Aug 19, 2019
d747c58
requirements_all.txt regenerated
konikvranik Aug 19, 2019
fa2a54f
code formatting
konikvranik Aug 19, 2019
b18237d
pyrainbird version 0.3.0
konikvranik Sep 1, 2019
b84a89c
zone id
konikvranik Sep 1, 2019
22dad98
rainsensor return state
konikvranik Sep 1, 2019
f2c96bb
updating rainsensor
konikvranik Sep 1, 2019
ea1595d
new version of pyrainbird
konikvranik Sep 3, 2019
d74495b
binary sensor state
konikvranik Sep 3, 2019
1ebf820
quiet in check format
konikvranik Sep 3, 2019
967c3e9
is_on instead of state for binary_sensor
konikvranik Sep 3, 2019
6f513b2
no unit of measurement for binary sensor
konikvranik Sep 3, 2019
e8af86a
no monitored conditions config
konikvranik Sep 3, 2019
59db275
get keys of dict directly
konikvranik Sep 3, 2019
3cd2b04
removed redundant update of state
konikvranik Sep 3, 2019
d1758c1
simplified switch
konikvranik Sep 3, 2019
54df464
right states for switch
konikvranik Sep 3, 2019
7375f46
raindelay sensor
konikvranik Sep 3, 2019
9a6821e
raindelay sensor
konikvranik Sep 3, 2019
d8e95f6
binary sensor state
konikvranik Sep 3, 2019
de5ba57
binary sensor state
konikvranik Sep 3, 2019
f7b670b
reorganized imports
konikvranik Sep 3, 2019
5586685
doc on public method
konikvranik Sep 3, 2019
cfc61c8
reformatted
konikvranik Sep 3, 2019
80756ef
add irrigation service to rain bird, which allows you to set the dura…
peternijssen Sep 3, 2019
3813223
rebased on konikvranik and solved some feedback
peternijssen Sep 5, 2019
36fb700
add irrigation service to rain bird
konikvranik Sep 7, 2019
0c72ebd
sensor types to constants
konikvranik Sep 8, 2019
d265f2f
synchronized register service
konikvranik Sep 8, 2019
d4cc15a
patform discovery
konikvranik Sep 9, 2019
547d17f
binary sensor as wrapper to sensor
konikvranik Sep 9, 2019
457c8a5
version 0.4.0
konikvranik Sep 9, 2019
f6ccdf0
new config approach
konikvranik Sep 9, 2019
05127ec
sensors cleanup
konikvranik Sep 9, 2019
7d0e9e7
bypass if no zones found
konikvranik Sep 9, 2019
a3e12fb
platform schema removed
konikvranik Sep 9, 2019
a9b90bc
Change config schema to list of controllers
konikvranik Sep 9, 2019
b5bbce5
some small code improvements as suggested in CR:
konikvranik Sep 9, 2019
49d4bd2
No single controller configuration
konikvranik Sep 9, 2019
11153f6
pyrainbird 0.4.1
konikvranik Sep 10, 2019
f1efbd7
individual switch configuration
konikvranik Sep 10, 2019
15a218d
imports order
konikvranik Sep 10, 2019
0b4ad97
generate default name out of entity
konikvranik Sep 10, 2019
96974c4
trigger time required for controller
konikvranik Sep 12, 2019
322dba1
incorporated CR remarks:
konikvranik Sep 18, 2019
2343c6c
import of library on top
konikvranik Sep 18, 2019
f1c4df4
refactored
konikvranik Sep 19, 2019
b26f5cd
Update homeassistant/components/rainbird/__init__.py
konikvranik Sep 19, 2019
4abc751
validate time and set defaults
konikvranik Sep 19, 2019
390298b
set defaults on right place
konikvranik Sep 19, 2019
9881d3e
pylint bypass
konikvranik Sep 19, 2019
b1f589c
iterate over values
konikvranik Sep 19, 2019
1053aba
codeowner
konikvranik Sep 19, 2019
60ae83a
reverted changes:
konikvranik Sep 19, 2019
e0dc5e9
codeowners updated
konikvranik Sep 19, 2019
7745ac9
accept timedelta in irrigation time
konikvranik Sep 21, 2019
8d5c117
simplified time calculation
konikvranik Sep 21, 2019
2489566
call total_seconds
konikvranik Sep 21, 2019
da40302
irrigation time as seconds.
konikvranik Sep 23, 2019
292a238
simplified schema
konikvranik Sep 25, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ homeassistant/components/qld_bushfire/* @exxamalte
homeassistant/components/qnap/* @colinodell
homeassistant/components/quantum_gateway/* @cisasteelersfan
homeassistant/components/qwikswitch/* @kellerza
homeassistant/components/rainbird/* @konikvranik
homeassistant/components/raincloud/* @vanstinator
homeassistant/components/rainforest_eagle/* @gtdiehl
homeassistant/components/rainmachine/* @bachya
Expand Down
83 changes: 66 additions & 17 deletions homeassistant/components/rainbird/__init__.py
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)
Comment thread
konikvranik marked this conversation as resolved.
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
64 changes: 64 additions & 0 deletions homeassistant/components/rainbird/binary_sensor.py
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
Comment thread
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
6 changes: 4 additions & 2 deletions homeassistant/components/rainbird/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
"name": "Rainbird",
"documentation": "https://www.home-assistant.io/components/rainbird",
"requirements": [
"pyrainbird==0.2.1"
"pyrainbird==0.4.1"
],
"dependencies": [],
"codeowners": []
"codeowners": [
"@konikvranik"
]
}
47 changes: 19 additions & 28 deletions homeassistant/components/rainbird/sensor.py
Original file line number Diff line number Diff line change
@@ -1,44 +1,37 @@
"""Support for Rain Bird Irrigation system LNK WiFi Module."""
import logging

import voluptuous as vol
from pyrainbird import RainbirdController

from homeassistant.components.sensor import PLATFORM_SCHEMA
from homeassistant.const import CONF_MONITORED_CONDITIONS
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.entity import Entity

from . import DATA_RAINBIRD
from . import (
DATA_RAINBIRD,
RAINBIRD_CONTROLLER,
SENSOR_TYPE_RAINDELAY,
SENSOR_TYPE_RAINSENSOR,
SENSOR_TYPES,
)

_LOGGER = logging.getLogger(__name__)

# sensor_type [ description, unit, icon ]
SENSOR_TYPES = {"rainsensor": ["Rainsensor", None, "mdi:water"]}

PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
{
vol.Optional(CONF_MONITORED_CONDITIONS, default=list(SENSOR_TYPES)): vol.All(
cv.ensure_list, [vol.In(SENSOR_TYPES)]
)
}
)


def setup_platform(hass, config, add_entities, discovery_info=None):
"""Set up a Rain Bird sensor."""
controller = hass.data[DATA_RAINBIRD]

sensors = []
for sensor_type in config.get(CONF_MONITORED_CONDITIONS):
sensors.append(RainBirdSensor(controller, sensor_type))
if discovery_info is None:
return

add_entities(sensors, True)
controller = hass.data[DATA_RAINBIRD][discovery_info[RAINBIRD_CONTROLLER]]
add_entities(
[RainBirdSensor(controller, sensor_type) for sensor_type in SENSOR_TYPES], True
)


class RainBirdSensor(Entity):
"""A sensor implementation for Rain Bird device."""

def __init__(self, controller, sensor_type):
def __init__(self, controller: RainbirdController, sensor_type):
"""Initialize the Rain Bird sensor."""
self._sensor_type = sensor_type
self._controller = controller
Expand All @@ -55,12 +48,10 @@ def state(self):
def update(self):
"""Get the latest data and updates the states."""
_LOGGER.debug("Updating sensor: %s", self._name)
if self._sensor_type == "rainsensor":
result = self._controller.currentRainSensorState()
if result and result["type"] == "CurrentRainSensorStateResponse":
self._state = result["sensorState"]
else:
self._state = None
if self._sensor_type == SENSOR_TYPE_RAINSENSOR:
self._state = self._controller.get_rain_sensor_state()
elif self._sensor_type == SENSOR_TYPE_RAINDELAY:
self._state = self._controller.get_rain_delay()

@property
def name(self):
Expand Down
9 changes: 9 additions & 0 deletions homeassistant/components/rainbird/services.yaml
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
Loading