From ee5f2283092c3ba0c5bb1292cff58883472059d7 Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Thu, 3 Nov 2016 18:32:14 -0700 Subject: [PATCH] Make services yield (#4187) * Make services yield * Disable pylint abstract-method check * add input_select * add input_slider * change to async vers. * fix lint * yield on add_entities as other components does --- .../alarm_control_panel/alarmdotcom.py | 1 - .../components/alarm_control_panel/manual.py | 1 - .../components/alarm_control_panel/mqtt.py | 1 - .../alarm_control_panel/simplisafe.py | 1 - .../alarm_control_panel/verisure.py | 1 - .../components/automation/__init__.py | 11 +++---- homeassistant/components/camera/__init__.py | 2 +- homeassistant/components/camera/ffmpeg.py | 2 +- homeassistant/components/camera/generic.py | 2 +- homeassistant/components/camera/mjpeg.py | 2 +- homeassistant/components/camera/synology.py | 2 +- homeassistant/components/climate/ecobee.py | 1 - .../components/climate/eq3btsmart.py | 2 +- .../components/climate/generic_thermostat.py | 1 - homeassistant/components/climate/heatmiser.py | 1 - homeassistant/components/climate/homematic.py | 1 - homeassistant/components/climate/honeywell.py | 2 -- homeassistant/components/climate/nest.py | 1 - homeassistant/components/climate/netatmo.py | 1 - homeassistant/components/climate/proliphix.py | 1 - .../components/climate/radiotherm.py | 1 - homeassistant/components/climate/vera.py | 1 - homeassistant/components/climate/zwave.py | 1 - homeassistant/components/cover/homematic.py | 1 - homeassistant/components/cover/rfxtrx.py | 1 - homeassistant/components/cover/rpi_gpio.py | 1 - homeassistant/components/cover/vera.py | 1 - homeassistant/components/emulated_hue.py | 8 ++--- homeassistant/components/fan/__init__.py | 2 +- homeassistant/components/group.py | 15 +++++---- homeassistant/components/http.py | 10 +++--- homeassistant/components/input_boolean.py | 29 +++++++++-------- homeassistant/components/input_select.py | 32 +++++++++++-------- homeassistant/components/input_slider.py | 13 ++++---- homeassistant/components/light/__init__.py | 2 +- .../components/light/limitlessled.py | 2 +- homeassistant/components/light/mysensors.py | 2 +- homeassistant/components/lock/verisure.py | 1 - .../components/media_player/__init__.py | 2 +- .../components/media_player/braviatv.py | 1 - homeassistant/components/media_player/cast.py | 1 - homeassistant/components/media_player/cmus.py | 2 +- homeassistant/components/media_player/demo.py | 8 ++--- .../components/media_player/denon.py | 1 - .../components/media_player/directv.py | 1 - homeassistant/components/media_player/emby.py | 2 +- .../components/media_player/firetv.py | 1 - .../components/media_player/gpmdp.py | 1 - .../components/media_player/itunes.py | 1 - homeassistant/components/media_player/kodi.py | 1 - .../components/media_player/lg_netcast.py | 1 - .../components/media_player/mpchc.py | 1 - homeassistant/components/media_player/mpd.py | 2 +- .../components/media_player/onkyo.py | 1 - .../media_player/panasonic_viera.py | 1 - .../components/media_player/pandora.py | 1 - .../components/media_player/philips_js.py | 1 - .../components/media_player/pioneer.py | 1 - homeassistant/components/media_player/plex.py | 1 - homeassistant/components/media_player/roku.py | 2 -- .../components/media_player/russound_rnet.py | 1 - .../components/media_player/samsungtv.py | 1 - .../components/media_player/snapcast.py | 1 - .../components/media_player/sonos.py | 1 - .../components/media_player/squeezebox.py | 1 - .../components/media_player/webostv.py | 1 - .../components/media_player/yamaha.py | 1 - homeassistant/components/sensor/lastfm.py | 1 - .../components/sensor/steam_online.py | 1 - .../components/sensor/supervisord.py | 1 - homeassistant/components/sensor/twitch.py | 1 - homeassistant/components/switch/__init__.py | 2 +- homeassistant/components/switch/arest.py | 2 +- homeassistant/helpers/entity.py | 28 +++++++++++++--- pylintrc | 2 ++ 75 files changed, 108 insertions(+), 131 deletions(-) diff --git a/homeassistant/components/alarm_control_panel/alarmdotcom.py b/homeassistant/components/alarm_control_panel/alarmdotcom.py index 714741d7e1e..8bf36e176e5 100644 --- a/homeassistant/components/alarm_control_panel/alarmdotcom.py +++ b/homeassistant/components/alarm_control_panel/alarmdotcom.py @@ -42,7 +42,6 @@ def setup_platform(hass, config, add_devices, discovery_info=None): add_devices([AlarmDotCom(hass, name, code, username, password)]) -# pylint: disable=abstract-method class AlarmDotCom(alarm.AlarmControlPanel): """Represent an Alarm.com status.""" diff --git a/homeassistant/components/alarm_control_panel/manual.py b/homeassistant/components/alarm_control_panel/manual.py index 2af0c1499f6..9a7efbeaf5a 100644 --- a/homeassistant/components/alarm_control_panel/manual.py +++ b/homeassistant/components/alarm_control_panel/manual.py @@ -50,7 +50,6 @@ def setup_platform(hass, config, add_devices, discovery_info=None): )]) -# pylint: disable=abstract-method class ManualAlarm(alarm.AlarmControlPanel): """ Represents an alarm status. diff --git a/homeassistant/components/alarm_control_panel/mqtt.py b/homeassistant/components/alarm_control_panel/mqtt.py index 558653aa6a6..26e2a2f1f77 100644 --- a/homeassistant/components/alarm_control_panel/mqtt.py +++ b/homeassistant/components/alarm_control_panel/mqtt.py @@ -55,7 +55,6 @@ def setup_platform(hass, config, add_devices, discovery_info=None): config.get(CONF_CODE))]) -# pylint: disable=abstract-method class MqttAlarm(alarm.AlarmControlPanel): """Representation of a MQTT alarm status.""" diff --git a/homeassistant/components/alarm_control_panel/simplisafe.py b/homeassistant/components/alarm_control_panel/simplisafe.py index 38128489ba0..40ebfb2f39f 100644 --- a/homeassistant/components/alarm_control_panel/simplisafe.py +++ b/homeassistant/components/alarm_control_panel/simplisafe.py @@ -41,7 +41,6 @@ def setup_platform(hass, config, add_devices, discovery_info=None): add_devices([SimpliSafeAlarm(name, username, password, code)]) -# pylint: disable=abstract-method class SimpliSafeAlarm(alarm.AlarmControlPanel): """Representation a SimpliSafe alarm.""" diff --git a/homeassistant/components/alarm_control_panel/verisure.py b/homeassistant/components/alarm_control_panel/verisure.py index 248d575baf7..4ef07c68f59 100644 --- a/homeassistant/components/alarm_control_panel/verisure.py +++ b/homeassistant/components/alarm_control_panel/verisure.py @@ -28,7 +28,6 @@ def setup_platform(hass, config, add_devices, discovery_info=None): add_devices(alarms) -# pylint: disable=abstract-method class VerisureAlarm(alarm.AlarmControlPanel): """Represent a Verisure alarm status.""" diff --git a/homeassistant/components/automation/__init__.py b/homeassistant/components/automation/__init__.py index 27b1fa9cd13..e88caab6824 100644 --- a/homeassistant/components/automation/__init__.py +++ b/homeassistant/components/automation/__init__.py @@ -218,7 +218,6 @@ def async_setup(hass, config): class AutomationEntity(ToggleEntity): """Entity to show status of entity.""" - # pylint: disable=abstract-method def __init__(self, name, async_attach_triggers, cond_func, async_action, hidden): """Initialize an automation entity.""" @@ -265,7 +264,7 @@ class AutomationEntity(ToggleEntity): return yield from self.async_enable() - self.hass.loop.create_task(self.async_update_ha_state()) + yield from self.async_update_ha_state() @asyncio.coroutine def async_turn_off(self, **kwargs) -> None: @@ -276,8 +275,6 @@ class AutomationEntity(ToggleEntity): self._async_detach_triggers() self._async_detach_triggers = None self._enabled = False - # It's important that the update is finished before this method - # ends because async_remove depends on it. yield from self.async_update_ha_state() @asyncio.coroutine @@ -289,7 +286,7 @@ class AutomationEntity(ToggleEntity): if skip_condition or self._cond_func(variables): yield from self._async_action(self.entity_id, variables) self._last_triggered = utcnow() - self.hass.loop.create_task(self.async_update_ha_state()) + yield from self.async_update_ha_state() @asyncio.coroutine def async_remove(self): @@ -352,7 +349,7 @@ def _async_process_config(hass, config, component): entities.append(entity) yield from asyncio.gather(*tasks, loop=hass.loop) - hass.loop.create_task(component.async_add_entities(entities)) + yield from component.async_add_entities(entities) return len(entities) > 0 @@ -367,7 +364,7 @@ def _async_get_action(hass, config, name): _LOGGER.info('Executing %s', name) logbook.async_log_entry( hass, name, 'has been triggered', DOMAIN, entity_id) - hass.loop.create_task(script_obj.async_run(variables)) + yield from script_obj.async_run(variables) return action diff --git a/homeassistant/components/camera/__init__.py b/homeassistant/components/camera/__init__.py index d2ca0b50801..d02e7954349 100644 --- a/homeassistant/components/camera/__init__.py +++ b/homeassistant/components/camera/__init__.py @@ -133,7 +133,7 @@ class Camera(Entity): yield from asyncio.sleep(.5) finally: - self.hass.loop.create_task(response.write_eof()) + yield from response.write_eof() @property def state(self): diff --git a/homeassistant/components/camera/ffmpeg.py b/homeassistant/components/camera/ffmpeg.py index 9bcb0c735a9..8e238bfdea7 100644 --- a/homeassistant/components/camera/ffmpeg.py +++ b/homeassistant/components/camera/ffmpeg.py @@ -87,7 +87,7 @@ class FFmpegCamera(Camera): response.write(data) finally: self.hass.loop.create_task(stream.close()) - self.hass.loop.create_task(response.write_eof()) + yield from response.write_eof() @property def name(self): diff --git a/homeassistant/components/camera/generic.py b/homeassistant/components/camera/generic.py index b1502778878..c6664ed70b2 100644 --- a/homeassistant/components/camera/generic.py +++ b/homeassistant/components/camera/generic.py @@ -114,7 +114,7 @@ class GenericCamera(Camera): auth=self._auth ) self._last_image = yield from respone.read() - self.hass.loop.create_task(respone.release()) + yield from respone.release() except asyncio.TimeoutError: _LOGGER.error('Timeout getting camera image') return self._last_image diff --git a/homeassistant/components/camera/mjpeg.py b/homeassistant/components/camera/mjpeg.py index ea83ded4371..81759fa86df 100644 --- a/homeassistant/components/camera/mjpeg.py +++ b/homeassistant/components/camera/mjpeg.py @@ -124,7 +124,7 @@ class MjpegCamera(Camera): response.write(data) finally: self.hass.loop.create_task(stream.release()) - self.hass.loop.create_task(response.write_eof()) + yield from response.write_eof() @property def name(self): diff --git a/homeassistant/components/camera/synology.py b/homeassistant/components/camera/synology.py index 77e1b3ee4d0..4d5020ec075 100644 --- a/homeassistant/components/camera/synology.py +++ b/homeassistant/components/camera/synology.py @@ -284,7 +284,7 @@ class SynologyCamera(Camera): response.write(data) finally: self.hass.loop.create_task(stream.release()) - self.hass.loop.create_task(response.write_eof()) + yield from response.write_eof() @property def name(self): diff --git a/homeassistant/components/climate/ecobee.py b/homeassistant/components/climate/ecobee.py index 6193b955a61..c98ac6d0106 100644 --- a/homeassistant/components/climate/ecobee.py +++ b/homeassistant/components/climate/ecobee.py @@ -72,7 +72,6 @@ def setup_platform(hass, config, add_devices, discovery_info=None): schema=SET_FAN_MIN_ON_TIME_SCHEMA) -# pylint: disable=abstract-method class Thermostat(ClimateDevice): """A thermostat class for Ecobee.""" diff --git a/homeassistant/components/climate/eq3btsmart.py b/homeassistant/components/climate/eq3btsmart.py index f6f0497c4af..72bd0b22522 100644 --- a/homeassistant/components/climate/eq3btsmart.py +++ b/homeassistant/components/climate/eq3btsmart.py @@ -42,7 +42,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None): add_devices(devices) -# pylint: disable=import-error, abstract-method +# pylint: disable=import-error class EQ3BTSmartThermostat(ClimateDevice): """Representation of a eQ-3 Bluetooth Smart thermostat.""" diff --git a/homeassistant/components/climate/generic_thermostat.py b/homeassistant/components/climate/generic_thermostat.py index 64448e9677c..3030ea9090e 100644 --- a/homeassistant/components/climate/generic_thermostat.py +++ b/homeassistant/components/climate/generic_thermostat.py @@ -62,7 +62,6 @@ def setup_platform(hass, config, add_devices, discovery_info=None): target_temp, ac_mode, min_cycle_duration)]) -# pylint: disable=abstract-method class GenericThermostat(ClimateDevice): """Representation of a GenericThermostat device.""" diff --git a/homeassistant/components/climate/heatmiser.py b/homeassistant/components/climate/heatmiser.py index 9f589b4c015..28d419597d3 100644 --- a/homeassistant/components/climate/heatmiser.py +++ b/homeassistant/components/climate/heatmiser.py @@ -56,7 +56,6 @@ def setup_platform(hass, config, add_devices, discovery_info=None): class HeatmiserV3Thermostat(ClimateDevice): """Representation of a HeatmiserV3 thermostat.""" - # pylint: disable=abstract-method def __init__(self, heatmiser, device, name, serport): """Initialize the thermostat.""" self.heatmiser = heatmiser diff --git a/homeassistant/components/climate/homematic.py b/homeassistant/components/climate/homematic.py index 7113779eb57..9be4e7a4886 100644 --- a/homeassistant/components/climate/homematic.py +++ b/homeassistant/components/climate/homematic.py @@ -36,7 +36,6 @@ def setup_platform(hass, config, add_callback_devices, discovery_info=None): ) -# pylint: disable=abstract-method class HMThermostat(homematic.HMDevice, ClimateDevice): """Representation of a Homematic thermostat.""" diff --git a/homeassistant/components/climate/honeywell.py b/homeassistant/components/climate/honeywell.py index 09b5d92b9b6..540a9a941d1 100644 --- a/homeassistant/components/climate/honeywell.py +++ b/homeassistant/components/climate/honeywell.py @@ -100,7 +100,6 @@ def _setup_us(username, password, config, add_devices): class RoundThermostat(ClimateDevice): """Representation of a Honeywell Round Connected thermostat.""" - # pylint: disable=abstract-method def __init__(self, device, zone_id, master, away_temp): """Initialize the thermostat.""" self.device = device @@ -197,7 +196,6 @@ class RoundThermostat(ClimateDevice): self._is_dhw = False -# pylint: disable=abstract-method class HoneywellUSThermostat(ClimateDevice): """Representation of a Honeywell US Thermostat.""" diff --git a/homeassistant/components/climate/nest.py b/homeassistant/components/climate/nest.py index f9ac15e7d80..5020bb441d5 100644 --- a/homeassistant/components/climate/nest.py +++ b/homeassistant/components/climate/nest.py @@ -30,7 +30,6 @@ def setup_platform(hass, config, add_devices, discovery_info=None): for structure, device in nest.devices()]) -# pylint: disable=abstract-method class NestThermostat(ClimateDevice): """Representation of a Nest thermostat.""" diff --git a/homeassistant/components/climate/netatmo.py b/homeassistant/components/climate/netatmo.py index b0a5059ef44..163054cd121 100755 --- a/homeassistant/components/climate/netatmo.py +++ b/homeassistant/components/climate/netatmo.py @@ -54,7 +54,6 @@ def setup_platform(hass, config, add_callback_devices, discovery_info=None): return None -# pylint: disable=abstract-method class NetatmoThermostat(ClimateDevice): """Representation a Netatmo thermostat.""" diff --git a/homeassistant/components/climate/proliphix.py b/homeassistant/components/climate/proliphix.py index 6aeee6e537c..515c43f7eba 100644 --- a/homeassistant/components/climate/proliphix.py +++ b/homeassistant/components/climate/proliphix.py @@ -36,7 +36,6 @@ def setup_platform(hass, config, add_devices, discovery_info=None): add_devices([ProliphixThermostat(pdp)]) -# pylint: disable=abstract-method class ProliphixThermostat(ClimateDevice): """Representation a Proliphix thermostat.""" diff --git a/homeassistant/components/climate/radiotherm.py b/homeassistant/components/climate/radiotherm.py index 90a1701536c..c2d712e19bd 100644 --- a/homeassistant/components/climate/radiotherm.py +++ b/homeassistant/components/climate/radiotherm.py @@ -58,7 +58,6 @@ def setup_platform(hass, config, add_devices, discovery_info=None): add_devices(tstats) -# pylint: disable=abstract-method class RadioThermostat(ClimateDevice): """Representation of a Radio Thermostat.""" diff --git a/homeassistant/components/climate/vera.py b/homeassistant/components/climate/vera.py index b8b03f8dda9..fa4244497e6 100644 --- a/homeassistant/components/climate/vera.py +++ b/homeassistant/components/climate/vera.py @@ -31,7 +31,6 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None): device in VERA_DEVICES['climate']) -# pylint: disable=abstract-method class VeraThermostat(VeraDevice, ClimateDevice): """Representation of a Vera Thermostat.""" diff --git a/homeassistant/components/climate/zwave.py b/homeassistant/components/climate/zwave.py index 7dcd72cd37c..d94c4f1b94b 100755 --- a/homeassistant/components/climate/zwave.py +++ b/homeassistant/components/climate/zwave.py @@ -69,7 +69,6 @@ def setup_platform(hass, config, add_devices, discovery_info=None): discovery_info, zwave.NETWORK) -# pylint: disable=abstract-method class ZWaveClimate(ZWaveDeviceEntity, ClimateDevice): """Represents a ZWave Climate device.""" diff --git a/homeassistant/components/cover/homematic.py b/homeassistant/components/cover/homematic.py index aea05a9160a..189c501aad5 100644 --- a/homeassistant/components/cover/homematic.py +++ b/homeassistant/components/cover/homematic.py @@ -31,7 +31,6 @@ def setup_platform(hass, config, add_callback_devices, discovery_info=None): ) -# pylint: disable=abstract-method class HMCover(homematic.HMDevice, CoverDevice): """Represents a Homematic Cover in Home Assistant.""" diff --git a/homeassistant/components/cover/rfxtrx.py b/homeassistant/components/cover/rfxtrx.py index d7ca03f5762..a016103a8fd 100644 --- a/homeassistant/components/cover/rfxtrx.py +++ b/homeassistant/components/cover/rfxtrx.py @@ -40,7 +40,6 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None): rfxtrx.RECEIVED_EVT_SUBSCRIBERS.append(cover_update) -# pylint: disable=abstract-method class RfxtrxCover(rfxtrx.RfxtrxDevice, CoverDevice): """Representation of an rfxtrx cover.""" diff --git a/homeassistant/components/cover/rpi_gpio.py b/homeassistant/components/cover/rpi_gpio.py index 39a82b5b3fc..4cd4e74be06 100644 --- a/homeassistant/components/cover/rpi_gpio.py +++ b/homeassistant/components/cover/rpi_gpio.py @@ -63,7 +63,6 @@ def setup_platform(hass, config, add_devices, discovery_info=None): add_devices(covers) -# pylint: disable=abstract-method class RPiGPIOCover(CoverDevice): """Representation of a Raspberry GPIO cover.""" diff --git a/homeassistant/components/cover/vera.py b/homeassistant/components/cover/vera.py index 57b85eca981..2c26fbf1723 100644 --- a/homeassistant/components/cover/vera.py +++ b/homeassistant/components/cover/vera.py @@ -22,7 +22,6 @@ def setup_platform(hass, config, add_devices, discovery_info=None): device in VERA_DEVICES['cover']) -# pylint: disable=abstract-method class VeraCover(VeraDevice, CoverDevice): """Represents a Vera Cover in Home Assistant.""" diff --git a/homeassistant/components/emulated_hue.py b/homeassistant/components/emulated_hue.py index 6aebb91f72f..187ee0de603 100644 --- a/homeassistant/components/emulated_hue.py +++ b/homeassistant/components/emulated_hue.py @@ -86,19 +86,19 @@ def setup(hass, yaml_config): upnp_listener = UPNPResponderThread( config.host_ip_addr, config.listen_port) - @core.callback + @asyncio.coroutine def stop_emulated_hue_bridge(event): """Stop the emulated hue bridge.""" upnp_listener.stop() - hass.loop.create_task(server.stop()) + yield from server.stop() - @core.callback + @asyncio.coroutine def start_emulated_hue_bridge(event): """Start the emulated hue bridge.""" - hass.loop.create_task(server.start()) upnp_listener.start() hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, stop_emulated_hue_bridge) + yield from server.start() hass.bus.listen_once(EVENT_HOMEASSISTANT_START, start_emulated_hue_bridge) diff --git a/homeassistant/components/fan/__init__.py b/homeassistant/components/fan/__init__.py index b3c210285e8..79793435625 100644 --- a/homeassistant/components/fan/__init__.py +++ b/homeassistant/components/fan/__init__.py @@ -196,7 +196,7 @@ def setup(hass, config: dict) -> None: class FanEntity(ToggleEntity): """Representation of a fan.""" - # pylint: disable=no-self-use, abstract-method + # pylint: disable=no-self-use def set_speed(self: ToggleEntity, speed: str) -> None: """Set the speed of the fan.""" diff --git a/homeassistant/components/group.py b/homeassistant/components/group.py index 3843c1b4854..f57c56f17db 100644 --- a/homeassistant/components/group.py +++ b/homeassistant/components/group.py @@ -175,15 +175,16 @@ def async_setup(hass, config): conf = yield from component.async_prepare_reload() if conf is None: return - hass.loop.create_task(_async_process_config(hass, conf, component)) + yield from _async_process_config(hass, conf, component) - @callback + @asyncio.coroutine def visibility_service_handler(service): """Change visibility of a group.""" visible = service.data.get(ATTR_VISIBLE) - for group in component.async_extract_from_service( - service, expand_group=False): - group.async_set_visible(visible) + tasks = [group.async_set_visible(visible) for group + in component.async_extract_from_service(service, + expand_group=False)] + yield from asyncio.gather(*tasks, loop=hass.loop) hass.services.async_register( DOMAIN, SERVICE_SET_VISIBILITY, visibility_service_handler, @@ -291,12 +292,12 @@ class Group(Entity): """Return the icon of the group.""" return self._icon - @callback + @asyncio.coroutine def async_set_visible(self, visible): """Change visibility of the group.""" if self._visible != visible: self._visible = visible - self.hass.loop.create_task(self.async_update_ha_state()) + yield from self.async_update_ha_state() @property def hidden(self): diff --git a/homeassistant/components/http.py b/homeassistant/components/http.py index da2f0ac06f0..89e15d50a5b 100644 --- a/homeassistant/components/http.py +++ b/homeassistant/components/http.py @@ -22,7 +22,7 @@ from aiohttp.web_exceptions import ( HTTPUnauthorized, HTTPMovedPermanently, HTTPNotModified) from aiohttp.web_urldispatcher import StaticRoute -from homeassistant.core import callback, is_callback +from homeassistant.core import is_callback import homeassistant.remote as rem from homeassistant import util from homeassistant.const import ( @@ -141,16 +141,16 @@ def setup(hass, config): trusted_networks=trusted_networks ) - @callback + @asyncio.coroutine def stop_server(event): """Callback to stop the server.""" - hass.loop.create_task(server.stop()) + yield from server.stop() - @callback + @asyncio.coroutine def start_server(event): """Callback to start the server.""" - hass.loop.create_task(server.start()) hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, stop_server) + yield from server.start() hass.bus.listen_once(EVENT_HOMEASSISTANT_START, start_server) diff --git a/homeassistant/components/input_boolean.py b/homeassistant/components/input_boolean.py index fdc514f957f..1a510fbf6ec 100644 --- a/homeassistant/components/input_boolean.py +++ b/homeassistant/components/input_boolean.py @@ -9,7 +9,6 @@ import logging import voluptuous as vol -from homeassistant.core import callback from homeassistant.const import ( ATTR_ENTITY_ID, CONF_ICON, CONF_NAME, SERVICE_TURN_OFF, SERVICE_TURN_ON, SERVICE_TOGGLE, STATE_ON) @@ -77,18 +76,20 @@ def async_setup(hass, config): if not entities: return False - @callback + @asyncio.coroutine def async_handler_service(service): """Handle a calls to the input boolean services.""" target_inputs = component.async_extract_from_service(service) - for input_b in target_inputs: - if service.service == SERVICE_TURN_ON: - input_b.turn_on() - elif service.service == SERVICE_TURN_OFF: - input_b.turn_off() - else: - input_b.toggle() + if service.service == SERVICE_TURN_ON: + attr = 'async_turn_on' + elif service.service == SERVICE_TURN_OFF: + attr = 'async_turn_off' + else: + attr = 'async_toggle' + + tasks = [getattr(input_b, attr)() for input_b in target_inputs] + yield from asyncio.gather(*tasks, loop=hass.loop) hass.services.async_register( DOMAIN, SERVICE_TURN_OFF, async_handler_service, schema=SERVICE_SCHEMA) @@ -131,12 +132,14 @@ class InputBoolean(ToggleEntity): """Return true if entity is on.""" return self._state - def turn_on(self, **kwargs): + @asyncio.coroutine + def async_turn_on(self, **kwargs): """Turn the entity on.""" self._state = True - self.hass.loop.create_task(self.async_update_ha_state()) + yield from self.async_update_ha_state() - def turn_off(self, **kwargs): + @asyncio.coroutine + def async_turn_off(self, **kwargs): """Turn the entity off.""" self._state = False - self.hass.loop.create_task(self.async_update_ha_state()) + yield from self.async_update_ha_state() diff --git a/homeassistant/components/input_select.py b/homeassistant/components/input_select.py index d725a1129cf..61385c46cd6 100644 --- a/homeassistant/components/input_select.py +++ b/homeassistant/components/input_select.py @@ -9,7 +9,6 @@ import logging import voluptuous as vol -from homeassistant.core import callback from homeassistant.const import ATTR_ENTITY_ID, CONF_ICON, CONF_NAME import homeassistant.helpers.config_validation as cv from homeassistant.helpers.entity import Entity @@ -105,37 +104,40 @@ def async_setup(hass, config): if not entities: return False - @callback + @asyncio.coroutine def async_select_option_service(call): """Handle a calls to the input select option service.""" target_inputs = component.async_extract_from_service(call) - for input_select in target_inputs: - input_select.select_option(call.data[ATTR_OPTION]) + tasks = [input_select.async_select_option(call.data[ATTR_OPTION]) + for input_select in target_inputs] + yield from asyncio.gather(*tasks, loop=hass.loop) hass.services.async_register( DOMAIN, SERVICE_SELECT_OPTION, async_select_option_service, schema=SERVICE_SELECT_OPTION_SCHEMA) - @callback + @asyncio.coroutine def async_select_next_service(call): """Handle a calls to the input select next service.""" target_inputs = component.async_extract_from_service(call) - for input_select in target_inputs: - input_select.offset_index(1) + tasks = [input_select.async_offset_index(1) + for input_select in target_inputs] + yield from asyncio.gather(*tasks, loop=hass.loop) hass.services.async_register( DOMAIN, SERVICE_SELECT_NEXT, async_select_next_service, schema=SERVICE_SELECT_NEXT_SCHEMA) - @callback + @asyncio.coroutine def async_select_previous_service(call): """Handle a calls to the input select previous service.""" target_inputs = component.async_extract_from_service(call) - for input_select in target_inputs: - input_select.offset_index(-1) + tasks = [input_select.async_offset_index(-1) + for input_select in target_inputs] + yield from asyncio.gather(*tasks, loop=hass.loop) hass.services.async_register( DOMAIN, SERVICE_SELECT_PREVIOUS, async_select_previous_service, @@ -183,18 +185,20 @@ class InputSelect(Entity): ATTR_OPTIONS: self._options, } - def select_option(self, option): + @asyncio.coroutine + def async_select_option(self, option): """Select new option.""" if option not in self._options: _LOGGER.warning('Invalid option: %s (possible options: %s)', option, ', '.join(self._options)) return self._current_option = option - self.hass.loop.create_task(self.async_update_ha_state()) + yield from self.async_update_ha_state() - def offset_index(self, offset): + @asyncio.coroutine + def async_offset_index(self, offset): """Offset current index.""" current_index = self._options.index(self._current_option) new_index = (current_index + offset) % len(self._options) self._current_option = self._options[new_index] - self.hass.loop.create_task(self.async_update_ha_state()) + yield from self.async_update_ha_state() diff --git a/homeassistant/components/input_slider.py b/homeassistant/components/input_slider.py index f5ac8ead91c..2a942829517 100644 --- a/homeassistant/components/input_slider.py +++ b/homeassistant/components/input_slider.py @@ -9,7 +9,6 @@ import logging import voluptuous as vol -from homeassistant.core import callback from homeassistant.const import ( ATTR_ENTITY_ID, ATTR_UNIT_OF_MEASUREMENT, CONF_ICON, CONF_NAME) import homeassistant.helpers.config_validation as cv @@ -95,13 +94,14 @@ def async_setup(hass, config): if not entities: return False - @callback + @asyncio.coroutine def async_select_value_service(call): """Handle a calls to the input slider services.""" target_inputs = component.async_extract_from_service(call) - for input_slider in target_inputs: - input_slider.select_value(call.data[ATTR_VALUE]) + tasks = [input_slider.async_select_value(call.data[ATTR_VALUE]) + for input_slider in target_inputs] + yield from asyncio.gather(*tasks, loop=hass.loop) hass.services.async_register( DOMAIN, SERVICE_SELECT_VALUE, async_select_value_service, @@ -160,7 +160,8 @@ class InputSlider(Entity): ATTR_STEP: self._step } - def select_value(self, value): + @asyncio.coroutine + def async_select_value(self, value): """Select new value.""" num_value = float(value) if num_value < self._minimum or num_value > self._maximum: @@ -168,4 +169,4 @@ class InputSlider(Entity): num_value, self._minimum, self._maximum) return self._current_value = num_value - self.hass.loop.create_task(self.async_update_ha_state()) + yield from self.async_update_ha_state() diff --git a/homeassistant/components/light/__init__.py b/homeassistant/components/light/__init__.py index 8cd4292908a..e3437d89e72 100644 --- a/homeassistant/components/light/__init__.py +++ b/homeassistant/components/light/__init__.py @@ -265,7 +265,7 @@ def setup(hass, config): class Light(ToggleEntity): """Representation of a light.""" - # pylint: disable=no-self-use, abstract-method + # pylint: disable=no-self-use @property def brightness(self): diff --git a/homeassistant/components/light/limitlessled.py b/homeassistant/components/light/limitlessled.py index 421696d22ba..8e0ea5cee83 100644 --- a/homeassistant/components/light/limitlessled.py +++ b/homeassistant/components/light/limitlessled.py @@ -4,7 +4,7 @@ Support for LimitlessLED bulbs. For more details about this platform, please refer to the documentation at https://home-assistant.io/components/light.limitlessled/ """ -# pylint: disable=abstract-method + import logging import voluptuous as vol diff --git a/homeassistant/components/light/mysensors.py b/homeassistant/components/light/mysensors.py index 479fb717213..3bd53ff9064 100644 --- a/homeassistant/components/light/mysensors.py +++ b/homeassistant/components/light/mysensors.py @@ -4,7 +4,7 @@ Support for MySensors lights. For more details about this platform, please refer to the documentation at https://home-assistant.io/components/light.mysensors/ """ -# pylint: disable=abstract-method + import logging from homeassistant.components import mysensors diff --git a/homeassistant/components/lock/verisure.py b/homeassistant/components/lock/verisure.py index d758f4dc91d..7e73ceb680e 100644 --- a/homeassistant/components/lock/verisure.py +++ b/homeassistant/components/lock/verisure.py @@ -27,7 +27,6 @@ def setup_platform(hass, config, add_devices, discovery_info=None): add_devices(locks) -# pylint: disable=abstract-method class VerisureDoorlock(LockDevice): """Representation of a Verisure doorlock.""" diff --git a/homeassistant/components/media_player/__init__.py b/homeassistant/components/media_player/__init__.py index 7988064183a..c689cdbccc4 100644 --- a/homeassistant/components/media_player/__init__.py +++ b/homeassistant/components/media_player/__init__.py @@ -710,7 +710,7 @@ def _async_fetch_image(hass, url): if response.status == 200: content = yield from response.read() content_type = response.headers.get(CONTENT_TYPE_HEADER) - hass.loop.create_task(response.release()) + yield from response.release() except asyncio.TimeoutError: pass diff --git a/homeassistant/components/media_player/braviatv.py b/homeassistant/components/media_player/braviatv.py index f55f1e6021c..d1c60bf2ec1 100644 --- a/homeassistant/components/media_player/braviatv.py +++ b/homeassistant/components/media_player/braviatv.py @@ -180,7 +180,6 @@ def request_configuration(config, hass, add_devices): ) -# pylint: disable=abstract-method class BraviaTVDevice(MediaPlayerDevice): """Representation of a Sony Bravia TV.""" diff --git a/homeassistant/components/media_player/cast.py b/homeassistant/components/media_player/cast.py index 9ee259a54ab..5d6289587be 100644 --- a/homeassistant/components/media_player/cast.py +++ b/homeassistant/components/media_player/cast.py @@ -88,7 +88,6 @@ def setup_platform(hass, config, add_devices, discovery_info=None): class CastDevice(MediaPlayerDevice): """Representation of a Cast device on the network.""" - # pylint: disable=abstract-method def __init__(self, chromecast): """Initialize the Cast device.""" self.cast = chromecast diff --git a/homeassistant/components/media_player/cmus.py b/homeassistant/components/media_player/cmus.py index dc623a274b5..16f3360a2ad 100644 --- a/homeassistant/components/media_player/cmus.py +++ b/homeassistant/components/media_player/cmus.py @@ -58,7 +58,7 @@ def setup_platform(hass, config, add_devices, discover_info=None): class CmusDevice(MediaPlayerDevice): """Representation of a running cmus.""" - # pylint: disable=no-member, abstract-method + # pylint: disable=no-member def __init__(self, server, password, port, name): """Initialize the CMUS device.""" from pycmus import remote diff --git a/homeassistant/components/media_player/demo.py b/homeassistant/components/media_player/demo.py index d59e6ef77d8..1c1687de319 100644 --- a/homeassistant/components/media_player/demo.py +++ b/homeassistant/components/media_player/demo.py @@ -42,7 +42,7 @@ class AbstractDemoPlayer(MediaPlayerDevice): """A demo media players.""" # We only implement the methods that we support - # pylint: disable=abstract-method + def __init__(self, name): """Initialize the demo device.""" self._name = name @@ -110,7 +110,7 @@ class DemoYoutubePlayer(AbstractDemoPlayer): """A Demo media player that only supports YouTube.""" # We only implement the methods that we support - # pylint: disable=abstract-method + def __init__(self, name, youtube_id=None, media_title=None): """Initialize the demo device.""" super().__init__(name) @@ -162,7 +162,7 @@ class DemoMusicPlayer(AbstractDemoPlayer): """A Demo media player that only supports YouTube.""" # We only implement the methods that we support - # pylint: disable=abstract-method + tracks = [ ('Technohead', 'I Wanna Be A Hippy (Flamman & Abraxas Radio Mix)'), ('Paul Elstak', 'Luv U More'), @@ -269,7 +269,7 @@ class DemoTVShowPlayer(AbstractDemoPlayer): """A Demo media player that only supports YouTube.""" # We only implement the methods that we support - # pylint: disable=abstract-method + def __init__(self): """Initialize the demo device.""" super().__init__('Lounge room') diff --git a/homeassistant/components/media_player/denon.py b/homeassistant/components/media_player/denon.py index e04b9ee3931..96cf0b99462 100644 --- a/homeassistant/components/media_player/denon.py +++ b/homeassistant/components/media_player/denon.py @@ -45,7 +45,6 @@ def setup_platform(hass, config, add_devices, discovery_info=None): class DenonDevice(MediaPlayerDevice): """Representation of a Denon device.""" - # pylint: disable=abstract-method def __init__(self, name, host): """Initialize the Denon device.""" self._name = name diff --git a/homeassistant/components/media_player/directv.py b/homeassistant/components/media_player/directv.py index f1f22693e6b..397014992ea 100644 --- a/homeassistant/components/media_player/directv.py +++ b/homeassistant/components/media_player/directv.py @@ -65,7 +65,6 @@ def setup_platform(hass, config, add_devices, discovery_info=None): class DirecTvDevice(MediaPlayerDevice): """Representation of a DirecTV reciever on the network.""" - # pylint: disable=abstract-method def __init__(self, name, host, port): """Initialize the device.""" from DirectPy import DIRECTV diff --git a/homeassistant/components/media_player/emby.py b/homeassistant/components/media_player/emby.py index 3422fadbc10..5349e74ed40 100644 --- a/homeassistant/components/media_player/emby.py +++ b/homeassistant/components/media_player/emby.py @@ -110,7 +110,7 @@ class EmbyClient(MediaPlayerDevice): """Representation of a Emby device.""" # pylint: disable=too-many-arguments, too-many-public-methods, - # pylint: disable=abstract-method + def __init__(self, client, device, emby_sessions, update_devices, update_sessions): """Initialize the Emby device.""" diff --git a/homeassistant/components/media_player/firetv.py b/homeassistant/components/media_player/firetv.py index 518982a7038..c8cdc9e7422 100644 --- a/homeassistant/components/media_player/firetv.py +++ b/homeassistant/components/media_player/firetv.py @@ -104,7 +104,6 @@ class FireTV(object): class FireTVDevice(MediaPlayerDevice): """Representation of an Amazon Fire TV device on the network.""" - # pylint: disable=abstract-method def __init__(self, host, port, device, name): """Initialize the FireTV device.""" self._firetv = FireTV(host, port, device) diff --git a/homeassistant/components/media_player/gpmdp.py b/homeassistant/components/media_player/gpmdp.py index db1732f4288..f81c63e71a1 100644 --- a/homeassistant/components/media_player/gpmdp.py +++ b/homeassistant/components/media_player/gpmdp.py @@ -170,7 +170,6 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None): class GPMDP(MediaPlayerDevice): """Representation of a GPMDP.""" - # pylint: disable=abstract-method def __init__(self, name, url, code): """Initialize the media player.""" from websocket import create_connection diff --git a/homeassistant/components/media_player/itunes.py b/homeassistant/components/media_player/itunes.py index 2ccc95c3243..7b869e14267 100644 --- a/homeassistant/components/media_player/itunes.py +++ b/homeassistant/components/media_player/itunes.py @@ -153,7 +153,6 @@ class Itunes(object): return self._request('PUT', path, {'level': level}) -# pylint: disable=unused-argument, abstract-method def setup_platform(hass, config, add_devices, discovery_info=None): """Setup the iTunes platform.""" add_devices([ diff --git a/homeassistant/components/media_player/kodi.py b/homeassistant/components/media_player/kodi.py index e88770a22e7..1b2bc4f7fc7 100644 --- a/homeassistant/components/media_player/kodi.py +++ b/homeassistant/components/media_player/kodi.py @@ -63,7 +63,6 @@ def setup_platform(hass, config, add_devices, discovery_info=None): class KodiDevice(MediaPlayerDevice): """Representation of a XBMC/Kodi device.""" - # pylint: disable=abstract-method def __init__(self, name, url, auth=None, turn_off_action=None): """Initialize the Kodi device.""" import jsonrpc_requests diff --git a/homeassistant/components/media_player/lg_netcast.py b/homeassistant/components/media_player/lg_netcast.py index 0def17a7dca..1f15153dbe8 100644 --- a/homeassistant/components/media_player/lg_netcast.py +++ b/homeassistant/components/media_player/lg_netcast.py @@ -52,7 +52,6 @@ def setup_platform(hass, config, add_devices, discovery_info=None): add_devices([LgTVDevice(client, config[CONF_NAME])]) -# pylint: disable=abstract-method class LgTVDevice(MediaPlayerDevice): """Representation of a LG TV.""" diff --git a/homeassistant/components/media_player/mpchc.py b/homeassistant/components/media_player/mpchc.py index 8563b551a09..0cbd548f23f 100644 --- a/homeassistant/components/media_player/mpchc.py +++ b/homeassistant/components/media_player/mpchc.py @@ -43,7 +43,6 @@ def setup_platform(hass, config, add_devices, discovery_info=None): add_devices([MpcHcDevice(name, url)]) -# pylint: disable=abstract-method class MpcHcDevice(MediaPlayerDevice): """Representation of a MPC-HC server.""" diff --git a/homeassistant/components/media_player/mpd.py b/homeassistant/components/media_player/mpd.py index 844be4a7a08..9967a26a3a0 100644 --- a/homeassistant/components/media_player/mpd.py +++ b/homeassistant/components/media_player/mpd.py @@ -77,7 +77,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None): class MpdDevice(MediaPlayerDevice): """Representation of a MPD server.""" - # pylint: disable=no-member, abstract-method + # pylint: disable=no-member def __init__(self, server, port, location, password): """Initialize the MPD device.""" import mpd diff --git a/homeassistant/components/media_player/onkyo.py b/homeassistant/components/media_player/onkyo.py index 44afc0f8ad2..5829d119f95 100644 --- a/homeassistant/components/media_player/onkyo.py +++ b/homeassistant/components/media_player/onkyo.py @@ -68,7 +68,6 @@ def setup_platform(hass, config, add_devices, discovery_info=None): class OnkyoDevice(MediaPlayerDevice): """Representation of an Onkyo device.""" - # pylint: disable=abstract-method def __init__(self, receiver, sources, name=None): """Initialize the Onkyo Receiver.""" self._receiver = receiver diff --git a/homeassistant/components/media_player/panasonic_viera.py b/homeassistant/components/media_player/panasonic_viera.py index a98e54fd6c9..d1a971eb91e 100644 --- a/homeassistant/components/media_player/panasonic_viera.py +++ b/homeassistant/components/media_player/panasonic_viera.py @@ -68,7 +68,6 @@ def setup_platform(hass, config, add_devices, discovery_info=None): return True -# pylint: disable=abstract-method class PanasonicVieraTVDevice(MediaPlayerDevice): """Representation of a Panasonic Viera TV.""" diff --git a/homeassistant/components/media_player/pandora.py b/homeassistant/components/media_player/pandora.py index d10b9f685b5..c97b20ee4bd 100644 --- a/homeassistant/components/media_player/pandora.py +++ b/homeassistant/components/media_player/pandora.py @@ -63,7 +63,6 @@ def setup_platform(hass, config, add_devices, discovery_info=None): class PandoraMediaPlayer(MediaPlayerDevice): """A media player that uses the Pianobar interface to Pandora.""" - # pylint: disable=abstract-method def __init__(self, name): """Initialize the demo device.""" MediaPlayerDevice.__init__(self) diff --git a/homeassistant/components/media_player/philips_js.py b/homeassistant/components/media_player/philips_js.py index af438d7dbec..02e520bb549 100644 --- a/homeassistant/components/media_player/philips_js.py +++ b/homeassistant/components/media_player/philips_js.py @@ -50,7 +50,6 @@ def setup_platform(hass, config, add_devices, discovery_info=None): add_devices([PhilipsTV(tvapi, name)]) -# pylint: disable=abstract-method class PhilipsTV(MediaPlayerDevice): """Representation of a Philips TV exposing the JointSpace API.""" diff --git a/homeassistant/components/media_player/pioneer.py b/homeassistant/components/media_player/pioneer.py index 524c2c4520e..14e4c753765 100644 --- a/homeassistant/components/media_player/pioneer.py +++ b/homeassistant/components/media_player/pioneer.py @@ -54,7 +54,6 @@ def setup_platform(hass, config, add_devices, discovery_info=None): class PioneerDevice(MediaPlayerDevice): """Representation of a Pioneer device.""" - # pylint: disable=abstract-method def __init__(self, name, host, port, timeout): """Initialize the Pioneer device.""" self._name = name diff --git a/homeassistant/components/media_player/plex.py b/homeassistant/components/media_player/plex.py index 827665929c5..76278722291 100644 --- a/homeassistant/components/media_player/plex.py +++ b/homeassistant/components/media_player/plex.py @@ -60,7 +60,6 @@ def config_from_file(filename, config=None): return {} -# pylint: disable=abstract-method def setup_platform(hass, config, add_devices_callback, discovery_info=None): """Setup the Plex platform.""" config = config_from_file(hass.config.path(PLEX_CONFIG_FILE)) diff --git a/homeassistant/components/media_player/roku.py b/homeassistant/components/media_player/roku.py index aff49d0a5be..dfeb6196750 100644 --- a/homeassistant/components/media_player/roku.py +++ b/homeassistant/components/media_player/roku.py @@ -34,7 +34,6 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({ }) -# pylint: disable=abstract-method def setup_platform(hass, config, add_devices, discovery_info=None): """Setup the Roku platform.""" hosts = [] @@ -65,7 +64,6 @@ def setup_platform(hass, config, add_devices, discovery_info=None): class RokuDevice(MediaPlayerDevice): """Representation of a Roku device on the network.""" - # pylint: disable=abstract-method def __init__(self, host): """Initialize the Roku device.""" from roku import Roku diff --git a/homeassistant/components/media_player/russound_rnet.py b/homeassistant/components/media_player/russound_rnet.py index df8e66457c5..3128aebe04f 100644 --- a/homeassistant/components/media_player/russound_rnet.py +++ b/homeassistant/components/media_player/russound_rnet.py @@ -72,7 +72,6 @@ def setup_platform(hass, config, add_devices, discovery_info=None): _LOGGER.error('Not connected to %s:%s', host, port) -# pylint: disable=abstract-method class RussoundRNETDevice(MediaPlayerDevice): """Representation of a Russound RNET device.""" diff --git a/homeassistant/components/media_player/samsungtv.py b/homeassistant/components/media_player/samsungtv.py index a680b32b9b0..e384fd4bd3f 100644 --- a/homeassistant/components/media_player/samsungtv.py +++ b/homeassistant/components/media_player/samsungtv.py @@ -56,7 +56,6 @@ def setup_platform(hass, config, add_devices, discovery_info=None): add_devices([SamsungTVDevice(name, remote_config)]) -# pylint: disable=abstract-method class SamsungTVDevice(MediaPlayerDevice): """Representation of a Samsung TV.""" diff --git a/homeassistant/components/media_player/snapcast.py b/homeassistant/components/media_player/snapcast.py index 2be3c36816c..37e9c4d3109 100644 --- a/homeassistant/components/media_player/snapcast.py +++ b/homeassistant/components/media_player/snapcast.py @@ -52,7 +52,6 @@ def setup_platform(hass, config, add_devices, discovery_info=None): class SnapcastDevice(MediaPlayerDevice): """Representation of a Snapcast client device.""" - # pylint: disable=abstract-method def __init__(self, client): """Initialize the Snapcast device.""" self._client = client diff --git a/homeassistant/components/media_player/sonos.py b/homeassistant/components/media_player/sonos.py index 1b8a0160e56..f40058ef883 100644 --- a/homeassistant/components/media_player/sonos.py +++ b/homeassistant/components/media_player/sonos.py @@ -248,7 +248,6 @@ class _ProcessSonosEventQueue(): self._sonos_device.process_sonos_event(item) -# pylint: disable=abstract-method class SonosDevice(MediaPlayerDevice): """Representation of a Sonos device.""" diff --git a/homeassistant/components/media_player/squeezebox.py b/homeassistant/components/media_player/squeezebox.py index 2e09087f012..ee21e67bf49 100644 --- a/homeassistant/components/media_player/squeezebox.py +++ b/homeassistant/components/media_player/squeezebox.py @@ -174,7 +174,6 @@ class LogitechMediaServer(object): class SqueezeBoxDevice(MediaPlayerDevice): """Representation of a SqueezeBox device.""" - # pylint: disable=abstract-method def __init__(self, lms, player_id): """Initialize the SqeezeBox device.""" super(SqueezeBoxDevice, self).__init__() diff --git a/homeassistant/components/media_player/webostv.py b/homeassistant/components/media_player/webostv.py index bc3133d0564..e131cad97cd 100644 --- a/homeassistant/components/media_player/webostv.py +++ b/homeassistant/components/media_player/webostv.py @@ -141,7 +141,6 @@ def request_configuration(host, name, customize, hass, add_devices): ) -# pylint: disable=abstract-method class LgWebOSDevice(MediaPlayerDevice): """Representation of a LG WebOS TV.""" diff --git a/homeassistant/components/media_player/yamaha.py b/homeassistant/components/media_player/yamaha.py index c3b5b83ec9a..94191862f44 100644 --- a/homeassistant/components/media_player/yamaha.py +++ b/homeassistant/components/media_player/yamaha.py @@ -85,7 +85,6 @@ def setup_platform(hass, config, add_devices, discovery_info=None): class YamahaDevice(MediaPlayerDevice): """Representation of a Yamaha device.""" - # pylint: disable=abstract-method def __init__(self, name, receiver, source_ignore, source_names): """Initialize the Yamaha Receiver.""" self._receiver = receiver diff --git a/homeassistant/components/sensor/lastfm.py b/homeassistant/components/sensor/lastfm.py index 038e8389d47..5d660f20217 100644 --- a/homeassistant/components/sensor/lastfm.py +++ b/homeassistant/components/sensor/lastfm.py @@ -40,7 +40,6 @@ def setup_platform(hass, config, add_devices, discovery_info=None): class LastfmSensor(Entity): """A class for the Last.fm account.""" - # pylint: disable=abstract-method def __init__(self, user, lastfm): """Initialize the sensor.""" self._user = lastfm.get_user(user) diff --git a/homeassistant/components/sensor/steam_online.py b/homeassistant/components/sensor/steam_online.py index ed12d4f7844..c5427e7b8ba 100644 --- a/homeassistant/components/sensor/steam_online.py +++ b/homeassistant/components/sensor/steam_online.py @@ -37,7 +37,6 @@ def setup_platform(hass, config, add_devices, discovery_info=None): class SteamSensor(Entity): """A class for the Steam account.""" - # pylint: disable=abstract-method def __init__(self, account, steamod): """Initialize the sensor.""" self._steamod = steamod diff --git a/homeassistant/components/sensor/supervisord.py b/homeassistant/components/sensor/supervisord.py index 22c1285a547..fae7032ea58 100644 --- a/homeassistant/components/sensor/supervisord.py +++ b/homeassistant/components/sensor/supervisord.py @@ -43,7 +43,6 @@ def setup_platform(hass, config, add_devices, discovery_info=None): class SupervisorProcessSensor(Entity): """Representation of a supervisor-monitored process.""" - # pylint: disable=abstract-method def __init__(self, info, server): """Initialize the sensor.""" self._info = info diff --git a/homeassistant/components/sensor/twitch.py b/homeassistant/components/sensor/twitch.py index 73e2d221cb1..249d18ce6cb 100644 --- a/homeassistant/components/sensor/twitch.py +++ b/homeassistant/components/sensor/twitch.py @@ -42,7 +42,6 @@ def setup_platform(hass, config, add_devices, discovery_info=None): class TwitchSensor(Entity): """Representation of an Twitch channel.""" - # pylint: disable=abstract-method def __init__(self, channel): """Initialize the sensor.""" self._channel = channel diff --git a/homeassistant/components/switch/__init__.py b/homeassistant/components/switch/__init__.py index 60b9c9fdcd8..1f92b458d53 100644 --- a/homeassistant/components/switch/__init__.py +++ b/homeassistant/components/switch/__init__.py @@ -108,7 +108,7 @@ def setup(hass, config): class SwitchDevice(ToggleEntity): """Representation of a switch.""" - # pylint: disable=no-self-use, abstract-method + # pylint: disable=no-self-use @property def current_power_mwh(self): """Return the current power usage in mWh.""" diff --git a/homeassistant/components/switch/arest.py b/homeassistant/components/switch/arest.py index 76f5bc7b580..9ae33698fa4 100644 --- a/homeassistant/components/switch/arest.py +++ b/homeassistant/components/switch/arest.py @@ -4,7 +4,7 @@ Support for an exposed aREST RESTful API of a device. For more details about this platform, please refer to the documentation at https://home-assistant.io/components/switch.arest/ """ -# pylint: disable=abstract-method + import logging import requests diff --git a/homeassistant/helpers/entity.py b/homeassistant/helpers/entity.py index 27f180a72ca..95ac50770cf 100644 --- a/homeassistant/helpers/entity.py +++ b/homeassistant/helpers/entity.py @@ -306,16 +306,36 @@ class ToggleEntity(Entity): raise NotImplementedError() def turn_on(self, **kwargs) -> None: + """Turn the entity on.""" + run_coroutine_threadsafe(self.async_turn_on(**kwargs), + self.hass.loop).result() + + @asyncio.coroutine + def async_turn_on(self, **kwargs): """Turn the entity on.""" raise NotImplementedError() def turn_off(self, **kwargs) -> None: + """Turn the entity off.""" + run_coroutine_threadsafe(self.async_turn_off(**kwargs), + self.hass.loop).result() + + @asyncio.coroutine + def async_turn_off(self, **kwargs): """Turn the entity off.""" raise NotImplementedError() - def toggle(self, **kwargs) -> None: - """Toggle the entity off.""" + def toggle(self) -> None: + """Toggle the entity.""" if self.is_on: - self.turn_off(**kwargs) + self.turn_off() else: - self.turn_on(**kwargs) + self.turn_on() + + @asyncio.coroutine + def async_toggle(self): + """Toggle the entity.""" + if self.is_on: + yield from self.async_turn_off() + else: + yield from self.async_turn_on() diff --git a/pylintrc b/pylintrc index 710f392e95f..9a46acc6a56 100644 --- a/pylintrc +++ b/pylintrc @@ -12,6 +12,7 @@ reports=no # redefined-variable-type - this is Python, we're duck typing! # too-many-* - are not enforced for the sake of readability # too-few-* - same as too-many-* +# abstract-method - with intro of async there are always methods missing disable= locally-disabled, @@ -30,6 +31,7 @@ disable= too-many-return-statements, too-many-statements, too-few-public-methods, + abstract-method [EXCEPTIONS] overgeneral-exceptions=Exception,HomeAssistantError