Merge pull request #7 from jbarrancos/rainbird

Fixed comments from @fabaff
This commit is contained in:
jbarrancos 2017-10-18 12:58:04 +02:00 committed by GitHub
commit a1d5daee53

View File

@ -9,7 +9,7 @@ import logging
import voluptuous as vol import voluptuous as vol
from homeassistant.components.switch import SwitchDevice from homeassistant.components.switch import (SwitchDevice, PLATFORM_SCHEMA)
from homeassistant.const import (CONF_PLATFORM, CONF_SWITCHES, CONF_ZONE, from homeassistant.const import (CONF_PLATFORM, CONF_SWITCHES, CONF_ZONE,
CONF_FRIENDLY_NAME, CONF_TRIGGER_TIME, CONF_FRIENDLY_NAME, CONF_TRIGGER_TIME,
CONF_SCAN_INTERVAL, CONF_HOST, CONF_PASSWORD) CONF_SCAN_INTERVAL, CONF_HOST, CONF_PASSWORD)
@ -21,7 +21,7 @@ REQUIREMENTS = ['pyrainbird==0.1.0']
DOMAIN = 'rainbird' DOMAIN = 'rainbird'
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
PLATFORM_SCHEMA = vol.Schema({ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
vol.Required(CONF_PLATFORM): DOMAIN, vol.Required(CONF_PLATFORM): DOMAIN,
vol.Required(CONF_HOST): cv.string, vol.Required(CONF_HOST): cv.string,
vol.Required(CONF_PASSWORD): cv.string, vol.Required(CONF_PASSWORD): cv.string,
@ -57,8 +57,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
devices = [] devices = []
for dev_id, switch in config.get(CONF_SWITCHES).items(): for dev_id, switch in config.get(CONF_SWITCHES).items():
devices.append(RainBirdSwitch(controller, switch, dev_id)) devices.append(RainBirdSwitch(controller, switch, dev_id))
add_devices(devices) add_devices(devices, True)
return True
class RainBirdSwitch(SwitchDevice): class RainBirdSwitch(SwitchDevice):
@ -69,8 +68,9 @@ class RainBirdSwitch(SwitchDevice):
self._rainbird = rb self._rainbird = rb
self._devid = dev_id self._devid = dev_id
self._zone = int(dev.get(CONF_ZONE)) self._zone = int(dev.get(CONF_ZONE))
self._name = dev.get(CONF_FRIENDLY_NAME, "Sprinker %s" % self._zone) self._name = dev.get(CONF_FRIENDLY_NAME,
self._state = self.get_device_status() "Sprinker {}".format(self._zone))
self._state = None
self._duration = dev.get(CONF_TRIGGER_TIME) self._duration = dev.get(CONF_TRIGGER_TIME)
self._attributes = { self._attributes = {
"duration": self._duration, "duration": self._duration,
@ -82,11 +82,6 @@ class RainBirdSwitch(SwitchDevice):
"""Return state attributes.""" """Return state attributes."""
return self._attributes return self._attributes
@property
def should_poll(self):
"""Return the polling state."""
return True
@property @property
def name(self): def name(self):
"""Get the name of the switch.""" """Get the name of the switch."""