diff --git a/homeassistant/components/binary_sensor/apcupsd.py b/homeassistant/components/binary_sensor/apcupsd.py index 620b7fcc5de..412656a3b56 100644 --- a/homeassistant/components/binary_sensor/apcupsd.py +++ b/homeassistant/components/binary_sensor/apcupsd.py @@ -20,9 +20,9 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({ }) -def setup_platform(hass, config, add_entities, discovery_info=None): - """Set up an Online Status binary sensor.""" - add_entities((OnlineStatus(config, apcupsd.DATA),)) +def setup_platform(hass, config, add_devices, discovery_info=None): + """Set up an APCUPSd Online Status binary sensor.""" + add_devices([OnlineStatus(config, apcupsd.DATA)], True) class OnlineStatus(BinarySensorDevice): @@ -33,7 +33,6 @@ class OnlineStatus(BinarySensorDevice): self._config = config self._data = data self._state = None - self.update() @property def name(self): diff --git a/homeassistant/components/binary_sensor/bloomsky.py b/homeassistant/components/binary_sensor/bloomsky.py index 38f362fb1bb..5e69dcc9109 100644 --- a/homeassistant/components/binary_sensor/bloomsky.py +++ b/homeassistant/components/binary_sensor/bloomsky.py @@ -37,7 +37,8 @@ def setup_platform(hass, config, add_devices, discovery_info=None): for device in bloomsky.BLOOMSKY.devices.values(): for variable in sensors: - add_devices([BloomSkySensor(bloomsky.BLOOMSKY, device, variable)]) + add_devices( + [BloomSkySensor(bloomsky.BLOOMSKY, device, variable)], True) class BloomSkySensor(BinarySensorDevice): @@ -50,7 +51,7 @@ class BloomSkySensor(BinarySensorDevice): self._sensor_name = sensor_name self._name = '{} {}'.format(device['DeviceName'], sensor_name) self._unique_id = 'bloomsky_binary_sensor {}'.format(self._name) - self.update() + self._state = None @property def name(self): diff --git a/homeassistant/components/binary_sensor/concord232.py b/homeassistant/components/binary_sensor/concord232.py index fc8c0b81edf..7ba88f76611 100755 --- a/homeassistant/components/binary_sensor/concord232.py +++ b/homeassistant/components/binary_sensor/concord232.py @@ -72,9 +72,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None): ) ) - add_devices(sensors) - - return True + add_devices(sensors, True) def get_opening_type(zone): @@ -100,7 +98,6 @@ class Concord232ZoneSensor(BinarySensorDevice): self._zone = zone self._number = zone['number'] self._zone_type = zone_type - self.update() @property def device_class(self): @@ -130,7 +127,7 @@ class Concord232ZoneSensor(BinarySensorDevice): if last_update > datetime.timedelta(seconds=1): self._client.zones = self._client.list_zones() self._client.last_zone_update = datetime.datetime.now() - _LOGGER.debug("Updated from Zone: %s", self._zone['name']) + _LOGGER.debug("Updated from zone: %s", self._zone['name']) if hasattr(self._client, 'zones'): self._zone = next((x for x in self._client.zones diff --git a/homeassistant/components/binary_sensor/ecobee.py b/homeassistant/components/binary_sensor/ecobee.py index d14a1124390..214efb870b9 100644 --- a/homeassistant/components/binary_sensor/ecobee.py +++ b/homeassistant/components/binary_sensor/ecobee.py @@ -26,7 +26,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None): dev.append(EcobeeBinarySensor(sensor['name'], index)) - add_devices(dev) + add_devices(dev, True) class EcobeeBinarySensor(BinarySensorDevice): @@ -39,7 +39,6 @@ class EcobeeBinarySensor(BinarySensorDevice): self.index = sensor_index self._state = None self._device_class = 'occupancy' - self.update() @property def name(self): diff --git a/homeassistant/components/binary_sensor/iss.py b/homeassistant/components/binary_sensor/iss.py index 44d2b16fcc9..3b927853c00 100644 --- a/homeassistant/components/binary_sensor/iss.py +++ b/homeassistant/components/binary_sensor/iss.py @@ -64,7 +64,6 @@ class IssBinarySensor(BinarySensorDevice): self._state = None self._name = name self._show_on_map = show - self.update() @property def name(self): diff --git a/homeassistant/components/binary_sensor/netatmo.py b/homeassistant/components/binary_sensor/netatmo.py index ac479ef4277..13b9fc1f005 100644 --- a/homeassistant/components/binary_sensor/netatmo.py +++ b/homeassistant/components/binary_sensor/netatmo.py @@ -44,18 +44,19 @@ CONF_WELCOME_SENSORS = 'welcome_sensors' CONF_PRESENCE_SENSORS = 'presence_sensors' CONF_TAG_SENSORS = 'tag_sensors' +DEFAULT_TIMEOUT = 15 +DEFAULT_OFFSET = 90 + PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({ - vol.Optional(CONF_HOME): cv.string, - vol.Optional(CONF_TIMEOUT): cv.positive_int, - vol.Optional(CONF_OFFSET): cv.positive_int, vol.Optional(CONF_CAMERAS, default=[]): vol.All(cv.ensure_list, [cv.string]), - vol.Optional( - CONF_WELCOME_SENSORS, default=WELCOME_SENSOR_TYPES.keys()): - vol.All(cv.ensure_list, [vol.In(WELCOME_SENSOR_TYPES)]), - vol.Optional( - CONF_PRESENCE_SENSORS, default=PRESENCE_SENSOR_TYPES.keys()): + vol.Optional(CONF_HOME): cv.string, + vol.Optional(CONF_OFFSET, default=DEFAULT_OFFSET): cv.positive_int, + vol.Optional(CONF_PRESENCE_SENSORS, default=PRESENCE_SENSOR_TYPES): vol.All(cv.ensure_list, [vol.In(PRESENCE_SENSOR_TYPES)]), + vol.Optional(CONF_TIMEOUT, default=DEFAULT_TIMEOUT): cv.positive_int, + vol.Optional(CONF_WELCOME_SENSORS, default=WELCOME_SENSOR_TYPES): + vol.All(cv.ensure_list, [vol.In(WELCOME_SENSOR_TYPES)]), }) @@ -63,16 +64,16 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({ def setup_platform(hass, config, add_devices, discovery_info=None): """Set up the access to Netatmo binary sensor.""" netatmo = get_component('netatmo') - home = config.get(CONF_HOME, None) - timeout = config.get(CONF_TIMEOUT, 15) - offset = config.get(CONF_OFFSET, 90) + home = config.get(CONF_HOME) + timeout = config.get(CONF_TIMEOUT) + offset = config.get(CONF_OFFSET) module_name = None import lnetatmo try: data = CameraData(netatmo.NETATMO_AUTH, home) - if data.get_camera_names() == []: + if not data.get_camera_names(): return None except lnetatmo.NoDevice: return None @@ -93,7 +94,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None): for variable in welcome_sensors: add_devices([NetatmoBinarySensor( data, camera_name, module_name, home, timeout, - offset, camera_type, variable)]) + offset, camera_type, variable)], True) if camera_type == 'NOC': if CONF_CAMERAS in config: if config[CONF_CAMERAS] != [] and \ @@ -102,14 +103,14 @@ def setup_platform(hass, config, add_devices, discovery_info=None): for variable in presence_sensors: add_devices([NetatmoBinarySensor( data, camera_name, module_name, home, timeout, offset, - camera_type, variable)]) + camera_type, variable)], True) for module_name in data.get_module_names(camera_name): for variable in tag_sensors: camera_type = None add_devices([NetatmoBinarySensor( data, camera_name, module_name, home, timeout, offset, - camera_type, variable)]) + camera_type, variable)], True) class NetatmoBinarySensor(BinarySensorDevice): @@ -137,7 +138,7 @@ class NetatmoBinarySensor(BinarySensorDevice): self._unique_id = "Netatmo_binary_sensor {0} - {1}".format( self._name, camera_id) self._cameratype = camera_type - self.update() + self._state = None @property def name(self): diff --git a/homeassistant/components/binary_sensor/octoprint.py b/homeassistant/components/binary_sensor/octoprint.py index f4e4e04717d..129b5250431 100644 --- a/homeassistant/components/binary_sensor/octoprint.py +++ b/homeassistant/components/binary_sensor/octoprint.py @@ -48,7 +48,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None): name, SENSOR_TYPES[octo_type][3], SENSOR_TYPES[octo_type][0], SENSOR_TYPES[octo_type][1], 'flags') devices.append(new_sensor) - add_devices(devices) + add_devices(devices, True) class OctoPrintBinarySensor(BinarySensorDevice): @@ -69,8 +69,6 @@ class OctoPrintBinarySensor(BinarySensorDevice): self.api_endpoint = endpoint self.api_group = group self.api_tool = tool - # Set initial state - self.update() _LOGGER.debug("Created OctoPrint binary sensor %r", self) @property diff --git a/homeassistant/components/climate/netatmo.py b/homeassistant/components/climate/netatmo.py index 3706a24bb52..369b01e53de 100755 --- a/homeassistant/components/climate/netatmo.py +++ b/homeassistant/components/climate/netatmo.py @@ -36,7 +36,7 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({ }) -def setup_platform(hass, config, add_callback_devices, discovery_info=None): +def setup_platform(hass, config, add_devices, discovery_info=None): """Set up the NetAtmo Thermostat.""" netatmo = get_component('netatmo') device = config.get(CONF_RELAY) @@ -49,7 +49,7 @@ def setup_platform(hass, config, add_callback_devices, discovery_info=None): if config[CONF_THERMOSTAT] != [] and \ module_name not in config[CONF_THERMOSTAT]: continue - add_callback_devices([NetatmoThermostat(data, module_name)]) + add_devices([NetatmoThermostat(data, module_name)], True) except lnetatmo.NoDevice: return None @@ -64,7 +64,6 @@ class NetatmoThermostat(ClimateDevice): self._name = module_name self._target_temperature = None self._away = None - self.update() @property def name(self): diff --git a/homeassistant/components/climate/radiotherm.py b/homeassistant/components/climate/radiotherm.py index 22e09ad0161..6daeebf9f55 100644 --- a/homeassistant/components/climate/radiotherm.py +++ b/homeassistant/components/climate/radiotherm.py @@ -68,7 +68,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None): _LOGGER.exception("Unable to connect to Radio Thermostat: %s", host) - add_devices(tstats) + add_devices(tstats, True) class RadioThermostat(ClimateDevice): @@ -89,7 +89,6 @@ class RadioThermostat(ClimateDevice): self._away = False self._away_temps = away_temps self._prev_temp = None - self.update() self._operation_list = [STATE_AUTO, STATE_COOL, STATE_HEAT, STATE_OFF] @property diff --git a/homeassistant/components/cover/garadget.py b/homeassistant/components/cover/garadget.py index 02e970a0d0b..22f5fd889a2 100644 --- a/homeassistant/components/cover/garadget.py +++ b/homeassistant/components/cover/garadget.py @@ -18,10 +18,10 @@ from homeassistant.const import ( _LOGGER = logging.getLogger(__name__) -ATTR_AVAILABLE = "available" -ATTR_SENSOR_STRENGTH = "sensor reflection rate" -ATTR_SIGNAL_STRENGTH = "wifi signal strength (dB)" -ATTR_TIME_IN_STATE = "time in state" +ATTR_AVAILABLE = 'available' +ATTR_SENSOR_STRENGTH = 'sensor_reflection_rate' +ATTR_SIGNAL_STRENGTH = 'wifi_signal_strength' +ATTR_TIME_IN_STATE = 'time_in_state' DEFAULT_NAME = 'Garadget' diff --git a/homeassistant/components/light/litejet.py b/homeassistant/components/light/litejet.py index 15f16d56a68..2ebe766c8c5 100644 --- a/homeassistant/components/light/litejet.py +++ b/homeassistant/components/light/litejet.py @@ -10,12 +10,12 @@ import homeassistant.components.litejet as litejet from homeassistant.components.light import ( ATTR_BRIGHTNESS, SUPPORT_BRIGHTNESS, Light) +_LOGGER = logging.getLogger(__name__) + DEPENDENCIES = ['litejet'] ATTR_NUMBER = 'number' -_LOGGER = logging.getLogger(__name__) - def setup_platform(hass, config, add_devices, discovery_info=None): """Set up lights for the LiteJet platform.""" @@ -26,7 +26,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None): name = litejet_.get_load_name(i) if not litejet.is_ignored(hass, name): devices.append(LiteJetLight(hass, litejet_, i, name)) - add_devices(devices) + add_devices(devices, True) class LiteJetLight(Light): @@ -43,8 +43,6 @@ class LiteJetLight(Light): lj.on_load_activated(i, self._on_load_changed) lj.on_load_deactivated(i, self._on_load_changed) - self.update() - def _on_load_changed(self): """Handle state changes.""" _LOGGER.debug("Updating due to notification for %s", self._name) diff --git a/homeassistant/components/light/zengge.py b/homeassistant/components/light/zengge.py index 74992a9d633..b453218c7c9 100644 --- a/homeassistant/components/light/zengge.py +++ b/homeassistant/components/light/zengge.py @@ -41,7 +41,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None): if light.is_valid: lights.append(light) - add_devices(lights) + add_devices(lights, True) class ZenggeLight(Light): @@ -63,7 +63,6 @@ class ZenggeLight(Light): _LOGGER.error( "Failed to connect to bulb %s, %s", self._address, self._name) return - self.update() @property def unique_id(self): diff --git a/homeassistant/components/media_player/cmus.py b/homeassistant/components/media_player/cmus.py index 949965200aa..fe25422360c 100644 --- a/homeassistant/components/media_player/cmus.py +++ b/homeassistant/components/media_player/cmus.py @@ -52,7 +52,7 @@ def setup_platform(hass, config, add_devices, discover_info=None): except exceptions.InvalidPassword: _LOGGER.error("The provided password was rejected by cmus") return False - add_devices([cmus_remote]) + add_devices([cmus_remote], True) class CmusDevice(MediaPlayerDevice): @@ -72,7 +72,6 @@ class CmusDevice(MediaPlayerDevice): auto_name = 'cmus-local' self._name = name or auto_name self.status = {} - self.update() def update(self): """Get the latest data and update the state.""" diff --git a/homeassistant/components/media_player/dunehd.py b/homeassistant/components/media_player/dunehd.py index 80f4795ccbe..76c15e97824 100644 --- a/homeassistant/components/media_player/dunehd.py +++ b/homeassistant/components/media_player/dunehd.py @@ -35,13 +35,13 @@ DUNEHD_PLAYER_SUPPORT = \ # pylint: disable=unused-argument def setup_platform(hass, config, add_devices, discovery_info=None): """Set up the DuneHD media player platform.""" - sources = config.get(CONF_SOURCES, {}) - from pdunehd import DuneHDPlayer - add_devices([DuneHDPlayerEntity( - DuneHDPlayer(config[CONF_HOST]), - config[CONF_NAME], - sources)]) + + sources = config.get(CONF_SOURCES, {}) + host = config.get(CONF_HOST) + name = config.get(CONF_NAME) + + add_devices([DuneHDPlayerEntity(DuneHDPlayer(host), name, sources)], True) class DuneHDPlayerEntity(MediaPlayerDevice): @@ -54,7 +54,6 @@ class DuneHDPlayerEntity(MediaPlayerDevice): self._sources = sources self._media_title = None self._state = None - self.update() def update(self): """Update internal status of the entity.""" diff --git a/homeassistant/components/media_player/gpmdp.py b/homeassistant/components/media_player/gpmdp.py index 88a8a949ca4..269964ea6c7 100644 --- a/homeassistant/components/media_player/gpmdp.py +++ b/homeassistant/components/media_player/gpmdp.py @@ -120,7 +120,7 @@ def setup_gpmdp(hass, config, code, add_devices): configurator = get_component('configurator') configurator.request_done(_CONFIGURING.pop('gpmdp')) - add_devices([GPMDP(name, url, code)]) + add_devices([GPMDP(name, url, code)], True) def _load_config(filename): @@ -153,7 +153,7 @@ def _save_config(filename, config): return True -def setup_platform(hass, config, add_devices_callback, discovery_info=None): +def setup_platform(hass, config, add_devices, discovery_info=None): """Set up the GPMDP platform.""" codeconfig = _load_config(hass.config.path(GPMDP_CONFIG_FILE)) if codeconfig: @@ -164,7 +164,7 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None): code = None else: code = None - setup_gpmdp(hass, config, code, add_devices_callback) + setup_gpmdp(hass, config, code, add_devices) class GPMDP(MediaPlayerDevice): @@ -186,7 +186,6 @@ class GPMDP(MediaPlayerDevice): self._duration = None self._volume = None self._request_id = 0 - self.update() def get_ws(self): """Check if the websocket is setup and connected.""" diff --git a/homeassistant/components/media_player/lg_netcast.py b/homeassistant/components/media_player/lg_netcast.py index 9e8fcbf2462..e657e1ce80d 100644 --- a/homeassistant/components/media_player/lg_netcast.py +++ b/homeassistant/components/media_player/lg_netcast.py @@ -47,10 +47,13 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({ def setup_platform(hass, config, add_devices, discovery_info=None): """Set up the LG TV platform.""" from pylgnetcast import LgNetCastClient - client = LgNetCastClient( - config.get(CONF_HOST), config.get(CONF_ACCESS_TOKEN)) + host = config.get(CONF_HOST) + access_token = config.get(CONF_ACCESS_TOKEN) + name = config.get(CONF_NAME) - add_devices([LgTVDevice(client, config[CONF_NAME])]) + client = LgNetCastClient(host, access_token) + + add_devices([LgTVDevice(client, name)], True) class LgTVDevice(MediaPlayerDevice): @@ -70,8 +73,6 @@ class LgTVDevice(MediaPlayerDevice): self._sources = {} self._source_names = [] - self.update() - def send_command(self, command): """Send remote control commands to the TV.""" from pylgnetcast import LgNetCastError diff --git a/homeassistant/components/media_player/mpchc.py b/homeassistant/components/media_player/mpchc.py index 3f7ab5a6e5e..cc195db2590 100644 --- a/homeassistant/components/media_player/mpchc.py +++ b/homeassistant/components/media_player/mpchc.py @@ -39,9 +39,12 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({ def setup_platform(hass, config, add_devices, discovery_info=None): """Set up the MPC-HC platform.""" name = config.get(CONF_NAME) - url = '{}:{}'.format(config.get(CONF_HOST), config.get(CONF_PORT)) + host = config.get(CONF_HOST) + port = config.get(CONF_PORT) - add_devices([MpcHcDevice(name, url)]) + url = '{}:{}'.format(host, port) + + add_devices([MpcHcDevice(name, url)], True) class MpcHcDevice(MediaPlayerDevice): @@ -51,21 +54,17 @@ class MpcHcDevice(MediaPlayerDevice): """Initialize the MPC-HC device.""" self._name = name self._url = url - - self.update() + self._player_variables = dict() def update(self): """Get the latest details.""" - self._player_variables = dict() - try: response = requests.get( '{}/variables.html'.format(self._url), data=None, timeout=3) - mpchc_variables = re.findall(r'
(.+?)
', - response.text) + mpchc_variables = re.findall( + r'(.+?)
', response.text) - self._player_variables = dict() for var in mpchc_variables: self._player_variables[var[0]] = var[1].lower() except requests.exceptions.RequestException: diff --git a/homeassistant/components/media_player/nad.py b/homeassistant/components/media_player/nad.py index 6f2b9ac4a71..43355782d29 100644 --- a/homeassistant/components/media_player/nad.py +++ b/homeassistant/components/media_player/nad.py @@ -56,7 +56,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None): config.get(CONF_MIN_VOLUME), config.get(CONF_MAX_VOLUME), config.get(CONF_SOURCE_DICT) - )]) + )], True) class NAD(MediaPlayerDevice): @@ -73,12 +73,7 @@ class NAD(MediaPlayerDevice): self._reverse_mapping = {value: key for key, value in self._source_dict.items()} - self._volume = None - self._state = None - self._mute = None - self._source = None - - self.update() + self._volume = self._state = self._mute = self._source = None def calc_volume(self, decibel): """ diff --git a/homeassistant/components/media_player/nadtcp.py b/homeassistant/components/media_player/nadtcp.py index 0b04f173c48..a59a032f624 100644 --- a/homeassistant/components/media_player/nadtcp.py +++ b/homeassistant/components/media_player/nadtcp.py @@ -50,7 +50,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None): config.get(CONF_MIN_VOLUME), config.get(CONF_MAX_VOLUME), config.get(CONF_VOLUME_STEP), - )]) + )], True) class NADtcp(MediaPlayerDevice): @@ -70,8 +70,6 @@ class NADtcp(MediaPlayerDevice): self._source = None self._source_list = self.nad_device.available_sources() - self.update() - @property def name(self): """Return the name of the device.""" diff --git a/homeassistant/components/media_player/onkyo.py b/homeassistant/components/media_player/onkyo.py index 19c46b811f7..927de799ae9 100644 --- a/homeassistant/components/media_player/onkyo.py +++ b/homeassistant/components/media_player/onkyo.py @@ -61,7 +61,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None): if receiver.host not in KNOWN_HOSTS: hosts.append(OnkyoDevice(receiver, config.get(CONF_SOURCES))) KNOWN_HOSTS.append(receiver.host) - add_devices(hosts) + add_devices(hosts, True) class OnkyoDevice(MediaPlayerDevice): @@ -79,7 +79,6 @@ class OnkyoDevice(MediaPlayerDevice): self._source_list = list(sources.values()) self._source_mapping = sources self._reverse_mapping = {value: key for key, value in sources.items()} - self.update() def command(self, command): """Run an eiscp command and catch connection errors.""" diff --git a/homeassistant/components/media_player/yamaha.py b/homeassistant/components/media_player/yamaha.py index 4d10c722800..f2e64b1fb25 100644 --- a/homeassistant/components/media_player/yamaha.py +++ b/homeassistant/components/media_player/yamaha.py @@ -67,9 +67,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None): _LOGGER.info("%s already manually configured", ctrl_url) return receivers = rxv.RXV( - ctrl_url, - model_name=model, - friendly_name=name, + ctrl_url, model_name=model, friendly_name=name, unit_desc_url=desc_url).zone_controllers() _LOGGER.info("Receivers: %s", receivers) # when we are dynamically discovered config is empty @@ -86,7 +84,8 @@ def setup_platform(hass, config, add_devices, discovery_info=None): if receiver.zone not in zone_ignore: hass.data[KNOWN].add(receiver.ctrl_url) add_devices([ - YamahaDevice(name, receiver, source_ignore, source_names)]) + YamahaDevice(name, receiver, source_ignore, source_names) + ], True) class YamahaDevice(MediaPlayerDevice): @@ -106,7 +105,6 @@ class YamahaDevice(MediaPlayerDevice): self._playback_support = None self._is_playback_supported = False self._play_status = None - self.update() self._name = name self._zone = receiver.zone diff --git a/homeassistant/components/sensor/apcupsd.py b/homeassistant/components/sensor/apcupsd.py index 0ddf6f160ae..897f0626b7c 100644 --- a/homeassistant/components/sensor/apcupsd.py +++ b/homeassistant/components/sensor/apcupsd.py @@ -123,7 +123,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None): entities.append(APCUPSdSensor(apcupsd.DATA, sensor_type)) - add_entities(entities) + add_entities(entities, True) def infer_unit(value): @@ -149,7 +149,7 @@ class APCUPSdSensor(Entity): self._name = SENSOR_PREFIX + SENSOR_TYPES[sensor_type][0] self._unit = SENSOR_TYPES[sensor_type][1] self._inferred_unit = None - self.update() + self._state = None @property def name(self): diff --git a/homeassistant/components/sensor/fritzbox_netmonitor.py b/homeassistant/components/sensor/fritzbox_netmonitor.py index 003307fbd83..1b7d2398efc 100644 --- a/homeassistant/components/sensor/fritzbox_netmonitor.py +++ b/homeassistant/components/sensor/fritzbox_netmonitor.py @@ -46,12 +46,12 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({ def setup_platform(hass, config, add_devices, discovery_info=None): - """Set up the fritzbox monitor sensors.""" + """Set up the FRITZ!Box monitor sensors.""" # pylint: disable=import-error import fritzconnection as fc from fritzconnection.fritzconnection import FritzConnectionException - host = config[CONF_HOST] + host = config.get(CONF_HOST) try: fstatus = fc.FritzStatus(address=host) @@ -59,15 +59,12 @@ def setup_platform(hass, config, add_devices, discovery_info=None): fstatus = None if fstatus is None: - _LOGGER.error('Failed to establish connection to FRITZ!Box ' - 'with IP: %s', host) + _LOGGER.error("Failed to establish connection to FRITZ!Box: %s", host) return 1 else: - _LOGGER.info('Successfully connected to FRITZ!Box') + _LOGGER.info("Successfully connected to FRITZ!Box") - sensor = FritzboxMonitorSensor(fstatus) - devices = [sensor] - add_devices(devices) + add_devices([FritzboxMonitorSensor(fstatus)], True) class FritzboxMonitorSensor(Entity): @@ -78,7 +75,10 @@ class FritzboxMonitorSensor(Entity): self._name = 'fritz_netmonitor' self._fstatus = fstatus self._state = STATE_UNAVAILABLE - self.update() + self._is_linked = self._is_connected = self._wan_access_type = None + self._external_ip = self._uptime = None + self._bytes_sent = self._bytes_received = None + self._max_byte_rate_up = self._max_byte_rate_down = None @property def name(self): @@ -130,4 +130,4 @@ class FritzboxMonitorSensor(Entity): self._state = STATE_ONLINE if self._is_connected else STATE_OFFLINE except RequestException as err: self._state = STATE_UNAVAILABLE - _LOGGER.warning('Could not reach Fritzbox: %s', err) + _LOGGER.warning("Could not reach FRITZ!Box: %s", err) diff --git a/homeassistant/components/sensor/google_travel_time.py b/homeassistant/components/sensor/google_travel_time.py index 0e495c67817..07c46b1a3d2 100644 --- a/homeassistant/components/sensor/google_travel_time.py +++ b/homeassistant/components/sensor/google_travel_time.py @@ -109,8 +109,8 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None): origin = config.get(CONF_ORIGIN) destination = config.get(CONF_DESTINATION) - sensor = GoogleTravelTimeSensor(hass, name, api_key, origin, - destination, options) + sensor = GoogleTravelTimeSensor( + hass, name, api_key, origin, destination, options) if sensor.valid_api_connection: add_devices_callback([sensor]) diff --git a/homeassistant/components/sensor/influxdb.py b/homeassistant/components/sensor/influxdb.py index 5aad96965c9..7c7ce3ec3da 100644 --- a/homeassistant/components/sensor/influxdb.py +++ b/homeassistant/components/sensor/influxdb.py @@ -67,12 +67,14 @@ MIN_TIME_BETWEEN_UPDATES = timedelta(seconds=60) def setup_platform(hass, config, add_devices, discovery_info=None): """Set up the InfluxDB component.""" - influx_conf = {'host': config[CONF_HOST], - 'port': config.get(CONF_PORT), - 'username': config.get(CONF_USERNAME), - 'password': config.get(CONF_PASSWORD), - 'ssl': config.get(CONF_SSL), - 'verify_ssl': config.get(CONF_VERIFY_SSL)} + influx_conf = { + 'host': config[CONF_HOST], + 'password': config.get(CONF_PASSWORD), + 'port': config.get(CONF_PORT), + 'ssl': config.get(CONF_SSL), + 'username': config.get(CONF_USERNAME), + 'verify_ssl': config.get(CONF_VERIFY_SSL), + } dev = [] @@ -81,7 +83,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None): if sensor.connected: dev.append(sensor) - add_devices(dev) + add_devices(dev, True) class InfluxSensor(Entity): @@ -113,12 +115,9 @@ class InfluxSensor(Entity): try: influx.query("select * from /.*/ LIMIT 1;") self.connected = True - self.data = InfluxSensorData(influx, - query.get(CONF_GROUP_FUNCTION), - query.get(CONF_FIELD), - query.get(CONF_MEASUREMENT_NAME), - where_clause) - self.update() + self.data = InfluxSensorData( + influx, query.get(CONF_GROUP_FUNCTION), query.get(CONF_FIELD), + query.get(CONF_MEASUREMENT_NAME), where_clause) except exceptions.InfluxDBClientError as exc: _LOGGER.error("Database host is not accessible due to '%s', please" " check your entries in the configuration file and" @@ -146,7 +145,7 @@ class InfluxSensor(Entity): return True def update(self): - """Get the latest data from influxdb and updates the states.""" + """Get the latest data from Influxdb and updates the states.""" self.data.update() value = self.data.value if value is None: @@ -178,14 +177,11 @@ class InfluxSensorData(object): try: where_clause = self.where.render() except TemplateError as ex: - _LOGGER.error('Could not render where clause template: %s', ex) + _LOGGER.error("Could not render where clause template: %s", ex) return - self.query = "select {}({}) as value from {} where {}"\ - .format(self.group, - self.field, - self.measurement, - where_clause) + self.query = "select {}({}) as value from {} where {}".format( + self.group, self.field, self.measurement, where_clause) _LOGGER.info("Running query: %s", self.query) diff --git a/homeassistant/components/sensor/onewire.py b/homeassistant/components/sensor/onewire.py index a06573fe97f..5cbbe6ed0aa 100644 --- a/homeassistant/components/sensor/onewire.py +++ b/homeassistant/components/sensor/onewire.py @@ -8,10 +8,12 @@ import os import time import logging from glob import glob + import voluptuous as vol -from homeassistant.helpers.entity import Entity + import homeassistant.helpers.config_validation as cv -from homeassistant.const import STATE_UNKNOWN, TEMP_CELSIUS +from homeassistant.helpers.entity import Entity +from homeassistant.const import TEMP_CELSIUS from homeassistant.components.sensor import PLATFORM_SCHEMA _LOGGER = logging.getLogger(__name__) @@ -61,21 +63,21 @@ def setup_platform(hass, config, add_devices, discovery_info=None): names = sensor_ids for key in config.keys(): - if key == "names": - # only one name given + if key == 'names': + # Only one name given if isinstance(config['names'], str): names = [config['names']] - # map names and sensors in given order + # Map names and sensors in given order elif isinstance(config['names'], list): names = config['names'] - # map names to ids. + # Map names to ids. elif isinstance(config['names'], dict): names = [] for sensor_id in sensor_ids: names.append(config['names'].get(sensor_id, sensor_id)) for device_file, name in zip(device_files, names): devs.append(OneWire(name, device_file)) - add_devices(devs) + add_devices(devs, True) class OneWire(Entity): @@ -85,8 +87,7 @@ class OneWire(Entity): """Initialize the sensor.""" self._name = name self._device_file = device_file - self._state = STATE_UNKNOWN - self.update() + self._state = None def _read_temp_raw(self): """Read the temperature as it is returned by the sensor.""" diff --git a/homeassistant/components/sensor/plex.py b/homeassistant/components/sensor/plex.py index eb6b5f49f6a..1077c7462d2 100644 --- a/homeassistant/components/sensor/plex.py +++ b/homeassistant/components/sensor/plex.py @@ -49,7 +49,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None): plex_url = 'http://{}:{}'.format(plex_host, plex_port) add_devices([PlexSensor( - name, plex_url, plex_user, plex_password, plex_server)]) + name, plex_url, plex_user, plex_password, plex_server)], True) class PlexSensor(Entity): @@ -73,8 +73,6 @@ class PlexSensor(Entity): else: self._server = PlexServer(plex_url) - self.update() - @property def name(self): """Return the name of the sensor.""" diff --git a/homeassistant/components/sensor/sensehat.py b/homeassistant/components/sensor/sensehat.py index 7a759351b35..db6d931d1b2 100644 --- a/homeassistant/components/sensor/sensehat.py +++ b/homeassistant/components/sensor/sensehat.py @@ -65,7 +65,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None): for variable in config[CONF_DISPLAY_OPTIONS]: dev.append(SenseHatSensor(data, variable)) - add_devices(dev) + add_devices(dev, True) class SenseHatSensor(Entity): @@ -78,7 +78,6 @@ class SenseHatSensor(Entity): self._unit_of_measurement = SENSOR_TYPES[sensor_types][1] self.type = sensor_types self._state = None - self.update() @property def name(self): diff --git a/homeassistant/components/sensor/steam_online.py b/homeassistant/components/sensor/steam_online.py index 9fd5ab7dd7d..27dd2fad56f 100644 --- a/homeassistant/components/sensor/steam_online.py +++ b/homeassistant/components/sensor/steam_online.py @@ -21,12 +21,6 @@ CONF_ACCOUNTS = 'accounts' ICON = 'mdi:steam' -PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({ - vol.Required(CONF_API_KEY): cv.string, - vol.Required(CONF_ACCOUNTS, default=[]): - vol.All(cv.ensure_list, [cv.string]), -}) - STATE_ONLINE = 'Online' STATE_BUSY = 'Busy' STATE_AWAY = 'Away' @@ -34,6 +28,12 @@ STATE_SNOOZE = 'Snooze' STATE_TRADE = 'Trade' STATE_PLAY = 'Play' +PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({ + vol.Required(CONF_API_KEY): cv.string, + vol.Required(CONF_ACCOUNTS, default=[]): + vol.All(cv.ensure_list, [cv.string]), +}) + # pylint: disable=unused-argument def setup_platform(hass, config, add_devices, discovery_info=None): @@ -42,7 +42,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None): steamod.api.key.set(config.get(CONF_API_KEY)) add_devices( [SteamSensor(account, - steamod) for account in config.get(CONF_ACCOUNTS)]) + steamod) for account in config.get(CONF_ACCOUNTS)], True) class SteamSensor(Entity): @@ -52,7 +52,8 @@ class SteamSensor(Entity): """Initialize the sensor.""" self._steamod = steamod self._account = account - self.update() + self._profile = None + self._game = self._state = self._name = self._avatar = None @property def name(self): @@ -90,10 +91,7 @@ class SteamSensor(Entity): self._avatar = self._profile.avatar_medium except self._steamod.api.HTTPTimeoutError as error: _LOGGER.warning(error) - self._game = 'Unknown' - self._state = 'Unknown' - self._name = 'Unknown' - self._avatar = None + self._game = self._state = self._name = self._avatar = None @property def device_state_attributes(self): diff --git a/homeassistant/components/sensor/swiss_hydrological_data.py b/homeassistant/components/sensor/swiss_hydrological_data.py index 3e2f228423b..63d500e2373 100644 --- a/homeassistant/components/sensor/swiss_hydrological_data.py +++ b/homeassistant/components/sensor/swiss_hydrological_data.py @@ -67,7 +67,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None): return False data = HydrologicalData(station) - add_devices([SwissHydrologicalDataSensor(name, data)]) + add_devices([SwissHydrologicalDataSensor(name, data)], True) class SwissHydrologicalDataSensor(Entity): @@ -78,7 +78,7 @@ class SwissHydrologicalDataSensor(Entity): self.data = data self._name = name self._unit_of_measurement = TEMP_CELSIUS - self.update() + self._state = None @property def name(self): diff --git a/homeassistant/components/sensor/ups.py b/homeassistant/components/sensor/ups.py index 2b2ae6172d0..40d84fe2618 100644 --- a/homeassistant/components/sensor/ups.py +++ b/homeassistant/components/sensor/ups.py @@ -52,7 +52,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None): return False add_devices([UPSSensor(session, config.get(CONF_NAME), - config.get(CONF_UPDATE_INTERVAL))]) + config.get(CONF_UPDATE_INTERVAL))], True) class UPSSensor(Entity): @@ -65,7 +65,6 @@ class UPSSensor(Entity): self._attributes = None self._state = None self.update = Throttle(interval)(self._update) - self.update() @property def name(self): diff --git a/homeassistant/components/switch/acer_projector.py b/homeassistant/components/switch/acer_projector.py index 416f6431ba5..f32829b0633 100644 --- a/homeassistant/components/switch/acer_projector.py +++ b/homeassistant/components/switch/acer_projector.py @@ -37,13 +37,15 @@ LAMP_HOURS = 'Lamp Hours' MODEL = 'Model' # Commands known to the projector -CMD_DICT = {LAMP: '* 0 Lamp ?\r', - LAMP_HOURS: '* 0 Lamp\r', - INPUT_SOURCE: '* 0 Src ?\r', - ECO_MODE: '* 0 IR 052\r', - MODEL: '* 0 IR 035\r', - STATE_ON: '* 0 IR 001\r', - STATE_OFF: '* 0 IR 002\r'} +CMD_DICT = { + LAMP: '* 0 Lamp ?\r', + LAMP_HOURS: '* 0 Lamp\r', + INPUT_SOURCE: '* 0 Src ?\r', + ECO_MODE: '* 0 IR 052\r', + MODEL: '* 0 IR 035\r', + STATE_ON: '* 0 IR 001\r', + STATE_OFF: '* 0 IR 002\r', +} PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({ @@ -62,7 +64,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None): timeout = config.get(CONF_TIMEOUT) write_timeout = config.get(CONF_WRITE_TIMEOUT) - add_devices([AcerSwitch(serial_port, name, timeout, write_timeout)]) + add_devices([AcerSwitch(serial_port, name, timeout, write_timeout)], True) class AcerSwitch(SwitchDevice): @@ -83,7 +85,6 @@ class AcerSwitch(SwitchDevice): INPUT_SOURCE: STATE_UNKNOWN, ECO_MODE: STATE_UNKNOWN, } - self.update() def _write_read(self, msg): """Write to the projector and read the return.""" diff --git a/homeassistant/components/switch/digitalloggers.py b/homeassistant/components/switch/digitalloggers.py index dabd8ea1d2d..26493122184 100755 --- a/homeassistant/components/switch/digitalloggers.py +++ b/homeassistant/components/switch/digitalloggers.py @@ -19,7 +19,6 @@ REQUIREMENTS = ['dlipower==0.7.165'] _LOGGER = logging.getLogger(__name__) - CONF_CYCLETIME = 'cycletime' DEFAULT_NAME = 'DINRelay' @@ -59,7 +58,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None): ) if not power_switch.verify(): - _LOGGER.error('Could not connect to DIN III Relay') + _LOGGER.error("Could not connect to DIN III Relay") return False devices = [] @@ -70,7 +69,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None): for device in power_switch ) - add_devices(devices) + add_devices(devices, True) class DINRelay(SwitchDevice): @@ -81,7 +80,8 @@ class DINRelay(SwitchDevice): self._parent_device = parent_device self.controllername = name self.outletnumber = outletnumber - self.update() + self._outletname = '' + self._is_on = False @property def name(self): @@ -112,7 +112,7 @@ class DINRelay(SwitchDevice): self._is_on = ( self._parent_device.statuslocal[self.outletnumber - 1][2] == 'ON' ) - self._outletname = "{}_{}".format( + self._outletname = '{}_{}'.format( self.controllername, self._parent_device.statuslocal[self.outletnumber - 1][1] ) @@ -124,7 +124,7 @@ class DINRelayDevice(object): def __init__(self, device): """Initialize the DINRelay device.""" self._device = device - self.update() + self.statuslocal = None def turn_on(self, **kwargs): """Instruct the relay to turn on.""" diff --git a/homeassistant/components/switch/litejet.py b/homeassistant/components/switch/litejet.py index 87a82ed67f2..1e7c46733ad 100644 --- a/homeassistant/components/switch/litejet.py +++ b/homeassistant/components/switch/litejet.py @@ -25,7 +25,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None): name = litejet_.get_switch_name(i) if not litejet.is_ignored(hass, name): devices.append(LiteJetSwitch(hass, litejet_, i, name)) - add_devices(devices) + add_devices(devices, True) class LiteJetSwitch(SwitchDevice): @@ -42,8 +42,6 @@ class LiteJetSwitch(SwitchDevice): lj.on_switch_pressed(i, self._on_switch_pressed) lj.on_switch_released(i, self._on_switch_released) - self.update() - def _on_switch_pressed(self): _LOGGER.debug("Updating pressed for %s", self._name) self._state = True diff --git a/homeassistant/components/switch/wake_on_lan.py b/homeassistant/components/switch/wake_on_lan.py index c5928ab1809..d94ff8c268b 100644 --- a/homeassistant/components/switch/wake_on_lan.py +++ b/homeassistant/components/switch/wake_on_lan.py @@ -44,7 +44,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None): off_action = config.get(CONF_OFF_ACTION) add_devices([WOLSwitch(hass, name, host, mac_address, - off_action, broadcast_address)]) + off_action, broadcast_address)], True) class WOLSwitch(SwitchDevice): @@ -62,7 +62,6 @@ class WOLSwitch(SwitchDevice): self._off_script = Script(hass, off_action) if off_action else None self._state = False self._wol = wol - self.update() @property def should_poll(self):