From d842dacfd6d9da4d34e8bf9ba16c6135deb51c61 Mon Sep 17 00:00:00 2001 From: springstan <46536646+springstan@users.noreply.github.com> Date: Wed, 15 Apr 2020 14:10:07 +0200 Subject: [PATCH] Clean up access to config in various integrations v5 (#34206) --- homeassistant/components/daikin/__init__.py | 2 +- homeassistant/components/datadog/__init__.py | 8 ++++---- homeassistant/components/decora_wifi/light.py | 4 ++-- homeassistant/components/deluge/sensor.py | 10 +++++----- homeassistant/components/deluge/switch.py | 10 +++++----- homeassistant/components/denon/media_player.py | 2 +- homeassistant/components/denonavr/media_player.py | 4 ++-- homeassistant/components/deutsche_bahn/sensor.py | 6 +++--- .../components/device_sun_light_trigger/__init__.py | 4 ++-- homeassistant/components/dht/sensor.py | 10 +++++----- homeassistant/components/digital_ocean/__init__.py | 2 +- .../components/digital_ocean/binary_sensor.py | 2 +- homeassistant/components/digital_ocean/switch.py | 2 +- homeassistant/components/digitalloggers/switch.py | 12 ++++++------ homeassistant/components/discogs/sensor.py | 2 +- homeassistant/components/discord/notify.py | 2 +- homeassistant/components/dlink/switch.py | 10 +++++----- homeassistant/components/dnsip/sensor.py | 8 ++++---- homeassistant/components/dovado/__init__.py | 4 ++-- homeassistant/components/dte_energy_bridge/sensor.py | 6 +++--- .../components/dublin_bus_transport/sensor.py | 6 +++--- 21 files changed, 58 insertions(+), 58 deletions(-) diff --git a/homeassistant/components/daikin/__init__.py b/homeassistant/components/daikin/__init__.py index 209bf71e594..144836bc571 100644 --- a/homeassistant/components/daikin/__init__.py +++ b/homeassistant/components/daikin/__init__.py @@ -42,7 +42,7 @@ async def async_setup(hass, config): if DOMAIN not in config: return True - hosts = config[DOMAIN].get(CONF_HOSTS) + hosts = config[DOMAIN][CONF_HOSTS] if not hosts: hass.async_create_task( hass.config_entries.flow.async_init( diff --git a/homeassistant/components/datadog/__init__.py b/homeassistant/components/datadog/__init__.py index 52cbe906402..36b4037f70a 100644 --- a/homeassistant/components/datadog/__init__.py +++ b/homeassistant/components/datadog/__init__.py @@ -45,10 +45,10 @@ def setup(hass, config): """Set up the Datadog component.""" conf = config[DOMAIN] - host = conf.get(CONF_HOST) - port = conf.get(CONF_PORT) - sample_rate = conf.get(CONF_RATE) - prefix = conf.get(CONF_PREFIX) + host = conf[CONF_HOST] + port = conf[CONF_PORT] + sample_rate = conf[CONF_RATE] + prefix = conf[CONF_PREFIX] initialize(statsd_host=host, statsd_port=port) diff --git a/homeassistant/components/decora_wifi/light.py b/homeassistant/components/decora_wifi/light.py index 7d8aa104bb0..9071da9707d 100644 --- a/homeassistant/components/decora_wifi/light.py +++ b/homeassistant/components/decora_wifi/light.py @@ -34,8 +34,8 @@ NOTIFICATION_TITLE = "myLeviton Decora Setup" def setup_platform(hass, config, add_entities, discovery_info=None): """Set up the Decora WiFi platform.""" - email = config.get(CONF_USERNAME) - password = config.get(CONF_PASSWORD) + email = config[CONF_USERNAME] + password = config[CONF_PASSWORD] session = DecoraWiFiSession() try: diff --git a/homeassistant/components/deluge/sensor.py b/homeassistant/components/deluge/sensor.py index 55309ea8b31..4a24e979607 100644 --- a/homeassistant/components/deluge/sensor.py +++ b/homeassistant/components/deluge/sensor.py @@ -49,11 +49,11 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend( def setup_platform(hass, config, add_entities, discovery_info=None): """Set up the Deluge sensors.""" - name = config.get(CONF_NAME) - host = config.get(CONF_HOST) - username = config.get(CONF_USERNAME) - password = config.get(CONF_PASSWORD) - port = config.get(CONF_PORT) + name = config[CONF_NAME] + host = config[CONF_HOST] + username = config[CONF_USERNAME] + password = config[CONF_PASSWORD] + port = config[CONF_PORT] deluge_api = DelugeRPCClient(host, port, username, password) try: diff --git a/homeassistant/components/deluge/switch.py b/homeassistant/components/deluge/switch.py index 7ac98f284c8..04acf6a9dd9 100644 --- a/homeassistant/components/deluge/switch.py +++ b/homeassistant/components/deluge/switch.py @@ -37,11 +37,11 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend( def setup_platform(hass, config, add_entities, discovery_info=None): """Set up the Deluge switch.""" - name = config.get(CONF_NAME) - host = config.get(CONF_HOST) - username = config.get(CONF_USERNAME) - password = config.get(CONF_PASSWORD) - port = config.get(CONF_PORT) + name = config[CONF_NAME] + host = config[CONF_HOST] + username = config[CONF_USERNAME] + password = config[CONF_PASSWORD] + port = config[CONF_PORT] deluge_api = DelugeRPCClient(host, port, username, password) try: diff --git a/homeassistant/components/denon/media_player.py b/homeassistant/components/denon/media_player.py index 11c31107ef6..1fbd4885f43 100644 --- a/homeassistant/components/denon/media_player.py +++ b/homeassistant/components/denon/media_player.py @@ -80,7 +80,7 @@ MEDIA_MODES = { def setup_platform(hass, config, add_entities, discovery_info=None): """Set up the Denon platform.""" - denon = DenonDevice(config.get(CONF_NAME), config.get(CONF_HOST)) + denon = DenonDevice(config[CONF_NAME], config[CONF_HOST]) if denon.update(): add_entities([denon]) diff --git a/homeassistant/components/denonavr/media_player.py b/homeassistant/components/denonavr/media_player.py index 67dc07f68df..7713354b14a 100644 --- a/homeassistant/components/denonavr/media_player.py +++ b/homeassistant/components/denonavr/media_player.py @@ -103,8 +103,8 @@ def setup_platform(hass, config, add_entities, discovery_info=None): cache = hass.data[KEY_DENON_CACHE] = set() # Get config option for show_all_sources and timeout - show_all_sources = config.get(CONF_SHOW_ALL_SOURCES) - timeout = config.get(CONF_TIMEOUT) + show_all_sources = config[CONF_SHOW_ALL_SOURCES] + timeout = config[CONF_TIMEOUT] # Get config option for additional zones zones = config.get(CONF_ZONES) diff --git a/homeassistant/components/deutsche_bahn/sensor.py b/homeassistant/components/deutsche_bahn/sensor.py index fd7496b1316..bb5adb943e9 100644 --- a/homeassistant/components/deutsche_bahn/sensor.py +++ b/homeassistant/components/deutsche_bahn/sensor.py @@ -36,9 +36,9 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend( def setup_platform(hass, config, add_entities, discovery_info=None): """Set up the Deutsche Bahn Sensor.""" start = config.get(CONF_START) - destination = config.get(CONF_DESTINATION) - offset = config.get(CONF_OFFSET) - only_direct = config.get(CONF_ONLY_DIRECT) + destination = config[CONF_DESTINATION] + offset = config[CONF_OFFSET] + only_direct = config[CONF_ONLY_DIRECT] add_entities([DeutscheBahnSensor(start, destination, offset, only_direct)], True) diff --git a/homeassistant/components/device_sun_light_trigger/__init__.py b/homeassistant/components/device_sun_light_trigger/__init__.py index d7986fbb5b4..fcf61dfe097 100644 --- a/homeassistant/components/device_sun_light_trigger/__init__.py +++ b/homeassistant/components/device_sun_light_trigger/__init__.py @@ -65,9 +65,9 @@ async def async_setup(hass, config): light = hass.components.light person = hass.components.person conf = config[DOMAIN] - disable_turn_off = conf.get(CONF_DISABLE_TURN_OFF) + disable_turn_off = conf[CONF_DISABLE_TURN_OFF] light_group = conf.get(CONF_LIGHT_GROUP) - light_profile = conf.get(CONF_LIGHT_PROFILE) + light_profile = conf[CONF_LIGHT_PROFILE] device_group = conf.get(CONF_DEVICE_GROUP) diff --git a/homeassistant/components/dht/sensor.py b/homeassistant/components/dht/sensor.py index cfd1cf2a197..6f3e58d4ad4 100644 --- a/homeassistant/components/dht/sensor.py +++ b/homeassistant/components/dht/sensor.py @@ -63,10 +63,10 @@ def setup_platform(hass, config, add_entities, discovery_info=None): "DHT11": Adafruit_DHT.DHT11, "DHT22": Adafruit_DHT.DHT22, } - sensor = available_sensors.get(config.get(CONF_SENSOR)) - pin = config.get(CONF_PIN) - temperature_offset = config.get(CONF_TEMPERATURE_OFFSET) - humidity_offset = config.get(CONF_HUMIDITY_OFFSET) + sensor = available_sensors.get(config[CONF_SENSOR]) + pin = config[CONF_PIN] + temperature_offset = config[CONF_TEMPERATURE_OFFSET] + humidity_offset = config[CONF_HUMIDITY_OFFSET] if not sensor: _LOGGER.error("DHT sensor type is not supported") @@ -74,7 +74,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None): data = DHTClient(Adafruit_DHT, sensor, pin) dev = [] - name = config.get(CONF_NAME) + name = config[CONF_NAME] try: for variable in config[CONF_MONITORED_CONDITIONS]: diff --git a/homeassistant/components/digital_ocean/__init__.py b/homeassistant/components/digital_ocean/__init__.py index 33663f121d1..9ae61ed9b84 100644 --- a/homeassistant/components/digital_ocean/__init__.py +++ b/homeassistant/components/digital_ocean/__init__.py @@ -41,7 +41,7 @@ def setup(hass, config): """Set up the Digital Ocean component.""" conf = config[DOMAIN] - access_token = conf.get(CONF_ACCESS_TOKEN) + access_token = conf[CONF_ACCESS_TOKEN] digital = DigitalOcean(access_token) diff --git a/homeassistant/components/digital_ocean/binary_sensor.py b/homeassistant/components/digital_ocean/binary_sensor.py index 50c87907774..c3515177535 100644 --- a/homeassistant/components/digital_ocean/binary_sensor.py +++ b/homeassistant/components/digital_ocean/binary_sensor.py @@ -37,7 +37,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None): if not digital: return False - droplets = config.get(CONF_DROPLETS) + droplets = config[CONF_DROPLETS] dev = [] for droplet in droplets: diff --git a/homeassistant/components/digital_ocean/switch.py b/homeassistant/components/digital_ocean/switch.py index 95d2e15a510..9b9b8157bce 100644 --- a/homeassistant/components/digital_ocean/switch.py +++ b/homeassistant/components/digital_ocean/switch.py @@ -37,7 +37,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None): if not digital: return False - droplets = config.get(CONF_DROPLETS) + droplets = config[CONF_DROPLETS] dev = [] for droplet in droplets: diff --git a/homeassistant/components/digitalloggers/switch.py b/homeassistant/components/digitalloggers/switch.py index 824af441688..268ec581c00 100644 --- a/homeassistant/components/digitalloggers/switch.py +++ b/homeassistant/components/digitalloggers/switch.py @@ -47,12 +47,12 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend( def setup_platform(hass, config, add_entities, discovery_info=None): """Find and return DIN III Relay switch.""" - host = config.get(CONF_HOST) - controller_name = config.get(CONF_NAME) - user = config.get(CONF_USERNAME) - pswd = config.get(CONF_PASSWORD) - tout = config.get(CONF_TIMEOUT) - cycl = config.get(CONF_CYCLETIME) + host = config[CONF_HOST] + controller_name = config[CONF_NAME] + user = config[CONF_USERNAME] + pswd = config[CONF_PASSWORD] + tout = config[CONF_TIMEOUT] + cycl = config[CONF_CYCLETIME] power_switch = dlipower.PowerSwitch( hostname=host, userid=user, password=pswd, timeout=tout, cycletime=cycl diff --git a/homeassistant/components/discogs/sensor.py b/homeassistant/components/discogs/sensor.py index b5e488cc19c..40f27135be1 100644 --- a/homeassistant/components/discogs/sensor.py +++ b/homeassistant/components/discogs/sensor.py @@ -83,7 +83,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None): return sensors = [] - for sensor_type in config.get(CONF_MONITORED_CONDITIONS): + for sensor_type in config[CONF_MONITORED_CONDITIONS]: sensors.append(DiscogsSensor(discogs_data, name, sensor_type)) add_entities(sensors, True) diff --git a/homeassistant/components/discord/notify.py b/homeassistant/components/discord/notify.py index e4558b103bd..fb36a60eecc 100644 --- a/homeassistant/components/discord/notify.py +++ b/homeassistant/components/discord/notify.py @@ -23,7 +23,7 @@ ATTR_IMAGES = "images" def get_service(hass, config, discovery_info=None): """Get the Discord notification service.""" - token = config.get(CONF_TOKEN) + token = config[CONF_TOKEN] return DiscordNotificationService(hass, token) diff --git a/homeassistant/components/dlink/switch.py b/homeassistant/components/dlink/switch.py index 7fa391e8060..1cc0e16f30f 100644 --- a/homeassistant/components/dlink/switch.py +++ b/homeassistant/components/dlink/switch.py @@ -44,11 +44,11 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend( def setup_platform(hass, config, add_entities, discovery_info=None): """Set up a D-Link Smart Plug.""" - host = config.get(CONF_HOST) - username = config.get(CONF_USERNAME) - password = config.get(CONF_PASSWORD) - use_legacy_protocol = config.get(CONF_USE_LEGACY_PROTOCOL) - name = config.get(CONF_NAME) + host = config[CONF_HOST] + username = config[CONF_USERNAME] + password = config[CONF_PASSWORD] + use_legacy_protocol = config[CONF_USE_LEGACY_PROTOCOL] + name = config[CONF_NAME] smartplug = SmartPlug(host, password, username, use_legacy_protocol) data = SmartPlugData(smartplug) diff --git a/homeassistant/components/dnsip/sensor.py b/homeassistant/components/dnsip/sensor.py index fb57040f2c2..b202ff8485c 100644 --- a/homeassistant/components/dnsip/sensor.py +++ b/homeassistant/components/dnsip/sensor.py @@ -39,18 +39,18 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend( async def async_setup_platform(hass, config, async_add_devices, discovery_info=None): """Set up the DNS IP sensor.""" - hostname = config.get(CONF_HOSTNAME) + hostname = config[CONF_HOSTNAME] name = config.get(CONF_NAME) if not name: if hostname == DEFAULT_HOSTNAME: name = DEFAULT_NAME else: name = hostname - ipv6 = config.get(CONF_IPV6) + ipv6 = config[CONF_IPV6] if ipv6: - resolver = config.get(CONF_RESOLVER_IPV6) + resolver = config[CONF_RESOLVER_IPV6] else: - resolver = config.get(CONF_RESOLVER) + resolver = config[CONF_RESOLVER] async_add_devices([WanIpSensor(hass, name, hostname, resolver, ipv6)], True) diff --git a/homeassistant/components/dovado/__init__.py b/homeassistant/components/dovado/__init__.py index b8d18d90833..8e4c712e8b4 100644 --- a/homeassistant/components/dovado/__init__.py +++ b/homeassistant/components/dovado/__init__.py @@ -41,8 +41,8 @@ def setup(hass, config): hass.data[DOMAIN] = DovadoData( dovado.Dovado( - config[DOMAIN].get(CONF_USERNAME), - config[DOMAIN].get(CONF_PASSWORD), + config[DOMAIN][CONF_USERNAME], + config[DOMAIN][CONF_PASSWORD], config[DOMAIN].get(CONF_HOST), config[DOMAIN].get(CONF_PORT), ) diff --git a/homeassistant/components/dte_energy_bridge/sensor.py b/homeassistant/components/dte_energy_bridge/sensor.py index c0725219a9a..efd00b3da1e 100644 --- a/homeassistant/components/dte_energy_bridge/sensor.py +++ b/homeassistant/components/dte_energy_bridge/sensor.py @@ -32,9 +32,9 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend( def setup_platform(hass, config, add_entities, discovery_info=None): """Set up the DTE energy bridge sensor.""" - name = config.get(CONF_NAME) - ip_address = config.get(CONF_IP_ADDRESS) - version = config.get(CONF_VERSION, 1) + name = config[CONF_NAME] + ip_address = config[CONF_IP_ADDRESS] + version = config[CONF_VERSION] add_entities([DteEnergyBridgeSensor(ip_address, name, version)], True) diff --git a/homeassistant/components/dublin_bus_transport/sensor.py b/homeassistant/components/dublin_bus_transport/sensor.py index 41c7df7889e..0c0d6c53ed1 100644 --- a/homeassistant/components/dublin_bus_transport/sensor.py +++ b/homeassistant/components/dublin_bus_transport/sensor.py @@ -59,9 +59,9 @@ def due_in_minutes(timestamp): def setup_platform(hass, config, add_entities, discovery_info=None): """Set up the Dublin public transport sensor.""" - name = config.get(CONF_NAME) - stop = config.get(CONF_STOP_ID) - route = config.get(CONF_ROUTE) + name = config[CONF_NAME] + stop = config[CONF_STOP_ID] + route = config[CONF_ROUTE] data = PublicTransportData(stop, route) add_entities([DublinPublicTransportSensor(data, stop, route, name)], True)