Fixed comments from @fabaff

Fxied issues raides
pull/9118/head
J.J.Barrancos 2017-10-18 09:58:32 +02:00
parent fad9e607c3
commit 02f8779de8
1 changed files with 6 additions and 12 deletions

View File

@ -9,19 +9,19 @@ 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)
from homeassistant.helpers import config_validation as cv from homeassistant.helpers import config_validation as cv
from homeassistant.exceptions import PlatformNotReady from homeassistant.exceptions import PlatformNotReady
REQUIREMENTS = ['pyrainbird==0.1.0'] REQUIREMENTS = ['pyrainbird==0.1.0','pycrypto==2.6.1']
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,8 @@ 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, "Sprinker {}".format(self._zone))
self._state = self.get_device_status() 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 +81,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."""