mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
Clean up access to config in various integrations v5 (#34206)
This commit is contained in:
parent
1ea7229f32
commit
d842dacfd6
@ -42,7 +42,7 @@ async def async_setup(hass, config):
|
|||||||
if DOMAIN not in config:
|
if DOMAIN not in config:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
hosts = config[DOMAIN].get(CONF_HOSTS)
|
hosts = config[DOMAIN][CONF_HOSTS]
|
||||||
if not hosts:
|
if not hosts:
|
||||||
hass.async_create_task(
|
hass.async_create_task(
|
||||||
hass.config_entries.flow.async_init(
|
hass.config_entries.flow.async_init(
|
||||||
|
@ -45,10 +45,10 @@ def setup(hass, config):
|
|||||||
"""Set up the Datadog component."""
|
"""Set up the Datadog component."""
|
||||||
|
|
||||||
conf = config[DOMAIN]
|
conf = config[DOMAIN]
|
||||||
host = conf.get(CONF_HOST)
|
host = conf[CONF_HOST]
|
||||||
port = conf.get(CONF_PORT)
|
port = conf[CONF_PORT]
|
||||||
sample_rate = conf.get(CONF_RATE)
|
sample_rate = conf[CONF_RATE]
|
||||||
prefix = conf.get(CONF_PREFIX)
|
prefix = conf[CONF_PREFIX]
|
||||||
|
|
||||||
initialize(statsd_host=host, statsd_port=port)
|
initialize(statsd_host=host, statsd_port=port)
|
||||||
|
|
||||||
|
@ -34,8 +34,8 @@ NOTIFICATION_TITLE = "myLeviton Decora Setup"
|
|||||||
def setup_platform(hass, config, add_entities, discovery_info=None):
|
def setup_platform(hass, config, add_entities, discovery_info=None):
|
||||||
"""Set up the Decora WiFi platform."""
|
"""Set up the Decora WiFi platform."""
|
||||||
|
|
||||||
email = config.get(CONF_USERNAME)
|
email = config[CONF_USERNAME]
|
||||||
password = config.get(CONF_PASSWORD)
|
password = config[CONF_PASSWORD]
|
||||||
session = DecoraWiFiSession()
|
session = DecoraWiFiSession()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -49,11 +49,11 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
|||||||
def setup_platform(hass, config, add_entities, discovery_info=None):
|
def setup_platform(hass, config, add_entities, discovery_info=None):
|
||||||
"""Set up the Deluge sensors."""
|
"""Set up the Deluge sensors."""
|
||||||
|
|
||||||
name = config.get(CONF_NAME)
|
name = config[CONF_NAME]
|
||||||
host = config.get(CONF_HOST)
|
host = config[CONF_HOST]
|
||||||
username = config.get(CONF_USERNAME)
|
username = config[CONF_USERNAME]
|
||||||
password = config.get(CONF_PASSWORD)
|
password = config[CONF_PASSWORD]
|
||||||
port = config.get(CONF_PORT)
|
port = config[CONF_PORT]
|
||||||
|
|
||||||
deluge_api = DelugeRPCClient(host, port, username, password)
|
deluge_api = DelugeRPCClient(host, port, username, password)
|
||||||
try:
|
try:
|
||||||
|
@ -37,11 +37,11 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
|||||||
def setup_platform(hass, config, add_entities, discovery_info=None):
|
def setup_platform(hass, config, add_entities, discovery_info=None):
|
||||||
"""Set up the Deluge switch."""
|
"""Set up the Deluge switch."""
|
||||||
|
|
||||||
name = config.get(CONF_NAME)
|
name = config[CONF_NAME]
|
||||||
host = config.get(CONF_HOST)
|
host = config[CONF_HOST]
|
||||||
username = config.get(CONF_USERNAME)
|
username = config[CONF_USERNAME]
|
||||||
password = config.get(CONF_PASSWORD)
|
password = config[CONF_PASSWORD]
|
||||||
port = config.get(CONF_PORT)
|
port = config[CONF_PORT]
|
||||||
|
|
||||||
deluge_api = DelugeRPCClient(host, port, username, password)
|
deluge_api = DelugeRPCClient(host, port, username, password)
|
||||||
try:
|
try:
|
||||||
|
@ -80,7 +80,7 @@ MEDIA_MODES = {
|
|||||||
|
|
||||||
def setup_platform(hass, config, add_entities, discovery_info=None):
|
def setup_platform(hass, config, add_entities, discovery_info=None):
|
||||||
"""Set up the Denon platform."""
|
"""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():
|
if denon.update():
|
||||||
add_entities([denon])
|
add_entities([denon])
|
||||||
|
@ -103,8 +103,8 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
|||||||
cache = hass.data[KEY_DENON_CACHE] = set()
|
cache = hass.data[KEY_DENON_CACHE] = set()
|
||||||
|
|
||||||
# Get config option for show_all_sources and timeout
|
# Get config option for show_all_sources and timeout
|
||||||
show_all_sources = config.get(CONF_SHOW_ALL_SOURCES)
|
show_all_sources = config[CONF_SHOW_ALL_SOURCES]
|
||||||
timeout = config.get(CONF_TIMEOUT)
|
timeout = config[CONF_TIMEOUT]
|
||||||
|
|
||||||
# Get config option for additional zones
|
# Get config option for additional zones
|
||||||
zones = config.get(CONF_ZONES)
|
zones = config.get(CONF_ZONES)
|
||||||
|
@ -36,9 +36,9 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
|||||||
def setup_platform(hass, config, add_entities, discovery_info=None):
|
def setup_platform(hass, config, add_entities, discovery_info=None):
|
||||||
"""Set up the Deutsche Bahn Sensor."""
|
"""Set up the Deutsche Bahn Sensor."""
|
||||||
start = config.get(CONF_START)
|
start = config.get(CONF_START)
|
||||||
destination = config.get(CONF_DESTINATION)
|
destination = config[CONF_DESTINATION]
|
||||||
offset = config.get(CONF_OFFSET)
|
offset = config[CONF_OFFSET]
|
||||||
only_direct = config.get(CONF_ONLY_DIRECT)
|
only_direct = config[CONF_ONLY_DIRECT]
|
||||||
|
|
||||||
add_entities([DeutscheBahnSensor(start, destination, offset, only_direct)], True)
|
add_entities([DeutscheBahnSensor(start, destination, offset, only_direct)], True)
|
||||||
|
|
||||||
|
@ -65,9 +65,9 @@ async def async_setup(hass, config):
|
|||||||
light = hass.components.light
|
light = hass.components.light
|
||||||
person = hass.components.person
|
person = hass.components.person
|
||||||
conf = config[DOMAIN]
|
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_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)
|
device_group = conf.get(CONF_DEVICE_GROUP)
|
||||||
|
|
||||||
|
@ -63,10 +63,10 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
|||||||
"DHT11": Adafruit_DHT.DHT11,
|
"DHT11": Adafruit_DHT.DHT11,
|
||||||
"DHT22": Adafruit_DHT.DHT22,
|
"DHT22": Adafruit_DHT.DHT22,
|
||||||
}
|
}
|
||||||
sensor = available_sensors.get(config.get(CONF_SENSOR))
|
sensor = available_sensors.get(config[CONF_SENSOR])
|
||||||
pin = config.get(CONF_PIN)
|
pin = config[CONF_PIN]
|
||||||
temperature_offset = config.get(CONF_TEMPERATURE_OFFSET)
|
temperature_offset = config[CONF_TEMPERATURE_OFFSET]
|
||||||
humidity_offset = config.get(CONF_HUMIDITY_OFFSET)
|
humidity_offset = config[CONF_HUMIDITY_OFFSET]
|
||||||
|
|
||||||
if not sensor:
|
if not sensor:
|
||||||
_LOGGER.error("DHT sensor type is not supported")
|
_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)
|
data = DHTClient(Adafruit_DHT, sensor, pin)
|
||||||
dev = []
|
dev = []
|
||||||
name = config.get(CONF_NAME)
|
name = config[CONF_NAME]
|
||||||
|
|
||||||
try:
|
try:
|
||||||
for variable in config[CONF_MONITORED_CONDITIONS]:
|
for variable in config[CONF_MONITORED_CONDITIONS]:
|
||||||
|
@ -41,7 +41,7 @@ def setup(hass, config):
|
|||||||
"""Set up the Digital Ocean component."""
|
"""Set up the Digital Ocean component."""
|
||||||
|
|
||||||
conf = config[DOMAIN]
|
conf = config[DOMAIN]
|
||||||
access_token = conf.get(CONF_ACCESS_TOKEN)
|
access_token = conf[CONF_ACCESS_TOKEN]
|
||||||
|
|
||||||
digital = DigitalOcean(access_token)
|
digital = DigitalOcean(access_token)
|
||||||
|
|
||||||
|
@ -37,7 +37,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
|||||||
if not digital:
|
if not digital:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
droplets = config.get(CONF_DROPLETS)
|
droplets = config[CONF_DROPLETS]
|
||||||
|
|
||||||
dev = []
|
dev = []
|
||||||
for droplet in droplets:
|
for droplet in droplets:
|
||||||
|
@ -37,7 +37,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
|||||||
if not digital:
|
if not digital:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
droplets = config.get(CONF_DROPLETS)
|
droplets = config[CONF_DROPLETS]
|
||||||
|
|
||||||
dev = []
|
dev = []
|
||||||
for droplet in droplets:
|
for droplet in droplets:
|
||||||
|
@ -47,12 +47,12 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
|||||||
def setup_platform(hass, config, add_entities, discovery_info=None):
|
def setup_platform(hass, config, add_entities, discovery_info=None):
|
||||||
"""Find and return DIN III Relay switch."""
|
"""Find and return DIN III Relay switch."""
|
||||||
|
|
||||||
host = config.get(CONF_HOST)
|
host = config[CONF_HOST]
|
||||||
controller_name = config.get(CONF_NAME)
|
controller_name = config[CONF_NAME]
|
||||||
user = config.get(CONF_USERNAME)
|
user = config[CONF_USERNAME]
|
||||||
pswd = config.get(CONF_PASSWORD)
|
pswd = config[CONF_PASSWORD]
|
||||||
tout = config.get(CONF_TIMEOUT)
|
tout = config[CONF_TIMEOUT]
|
||||||
cycl = config.get(CONF_CYCLETIME)
|
cycl = config[CONF_CYCLETIME]
|
||||||
|
|
||||||
power_switch = dlipower.PowerSwitch(
|
power_switch = dlipower.PowerSwitch(
|
||||||
hostname=host, userid=user, password=pswd, timeout=tout, cycletime=cycl
|
hostname=host, userid=user, password=pswd, timeout=tout, cycletime=cycl
|
||||||
|
@ -83,7 +83,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
|||||||
return
|
return
|
||||||
|
|
||||||
sensors = []
|
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))
|
sensors.append(DiscogsSensor(discogs_data, name, sensor_type))
|
||||||
|
|
||||||
add_entities(sensors, True)
|
add_entities(sensors, True)
|
||||||
|
@ -23,7 +23,7 @@ ATTR_IMAGES = "images"
|
|||||||
|
|
||||||
def get_service(hass, config, discovery_info=None):
|
def get_service(hass, config, discovery_info=None):
|
||||||
"""Get the Discord notification service."""
|
"""Get the Discord notification service."""
|
||||||
token = config.get(CONF_TOKEN)
|
token = config[CONF_TOKEN]
|
||||||
return DiscordNotificationService(hass, token)
|
return DiscordNotificationService(hass, token)
|
||||||
|
|
||||||
|
|
||||||
|
@ -44,11 +44,11 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
|||||||
def setup_platform(hass, config, add_entities, discovery_info=None):
|
def setup_platform(hass, config, add_entities, discovery_info=None):
|
||||||
"""Set up a D-Link Smart Plug."""
|
"""Set up a D-Link Smart Plug."""
|
||||||
|
|
||||||
host = config.get(CONF_HOST)
|
host = config[CONF_HOST]
|
||||||
username = config.get(CONF_USERNAME)
|
username = config[CONF_USERNAME]
|
||||||
password = config.get(CONF_PASSWORD)
|
password = config[CONF_PASSWORD]
|
||||||
use_legacy_protocol = config.get(CONF_USE_LEGACY_PROTOCOL)
|
use_legacy_protocol = config[CONF_USE_LEGACY_PROTOCOL]
|
||||||
name = config.get(CONF_NAME)
|
name = config[CONF_NAME]
|
||||||
|
|
||||||
smartplug = SmartPlug(host, password, username, use_legacy_protocol)
|
smartplug = SmartPlug(host, password, username, use_legacy_protocol)
|
||||||
data = SmartPlugData(smartplug)
|
data = SmartPlugData(smartplug)
|
||||||
|
@ -39,18 +39,18 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
|||||||
|
|
||||||
async def async_setup_platform(hass, config, async_add_devices, discovery_info=None):
|
async def async_setup_platform(hass, config, async_add_devices, discovery_info=None):
|
||||||
"""Set up the DNS IP sensor."""
|
"""Set up the DNS IP sensor."""
|
||||||
hostname = config.get(CONF_HOSTNAME)
|
hostname = config[CONF_HOSTNAME]
|
||||||
name = config.get(CONF_NAME)
|
name = config.get(CONF_NAME)
|
||||||
if not name:
|
if not name:
|
||||||
if hostname == DEFAULT_HOSTNAME:
|
if hostname == DEFAULT_HOSTNAME:
|
||||||
name = DEFAULT_NAME
|
name = DEFAULT_NAME
|
||||||
else:
|
else:
|
||||||
name = hostname
|
name = hostname
|
||||||
ipv6 = config.get(CONF_IPV6)
|
ipv6 = config[CONF_IPV6]
|
||||||
if ipv6:
|
if ipv6:
|
||||||
resolver = config.get(CONF_RESOLVER_IPV6)
|
resolver = config[CONF_RESOLVER_IPV6]
|
||||||
else:
|
else:
|
||||||
resolver = config.get(CONF_RESOLVER)
|
resolver = config[CONF_RESOLVER]
|
||||||
|
|
||||||
async_add_devices([WanIpSensor(hass, name, hostname, resolver, ipv6)], True)
|
async_add_devices([WanIpSensor(hass, name, hostname, resolver, ipv6)], True)
|
||||||
|
|
||||||
|
@ -41,8 +41,8 @@ def setup(hass, config):
|
|||||||
|
|
||||||
hass.data[DOMAIN] = DovadoData(
|
hass.data[DOMAIN] = DovadoData(
|
||||||
dovado.Dovado(
|
dovado.Dovado(
|
||||||
config[DOMAIN].get(CONF_USERNAME),
|
config[DOMAIN][CONF_USERNAME],
|
||||||
config[DOMAIN].get(CONF_PASSWORD),
|
config[DOMAIN][CONF_PASSWORD],
|
||||||
config[DOMAIN].get(CONF_HOST),
|
config[DOMAIN].get(CONF_HOST),
|
||||||
config[DOMAIN].get(CONF_PORT),
|
config[DOMAIN].get(CONF_PORT),
|
||||||
)
|
)
|
||||||
|
@ -32,9 +32,9 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
|||||||
|
|
||||||
def setup_platform(hass, config, add_entities, discovery_info=None):
|
def setup_platform(hass, config, add_entities, discovery_info=None):
|
||||||
"""Set up the DTE energy bridge sensor."""
|
"""Set up the DTE energy bridge sensor."""
|
||||||
name = config.get(CONF_NAME)
|
name = config[CONF_NAME]
|
||||||
ip_address = config.get(CONF_IP_ADDRESS)
|
ip_address = config[CONF_IP_ADDRESS]
|
||||||
version = config.get(CONF_VERSION, 1)
|
version = config[CONF_VERSION]
|
||||||
|
|
||||||
add_entities([DteEnergyBridgeSensor(ip_address, name, version)], True)
|
add_entities([DteEnergyBridgeSensor(ip_address, name, version)], True)
|
||||||
|
|
||||||
|
@ -59,9 +59,9 @@ def due_in_minutes(timestamp):
|
|||||||
|
|
||||||
def setup_platform(hass, config, add_entities, discovery_info=None):
|
def setup_platform(hass, config, add_entities, discovery_info=None):
|
||||||
"""Set up the Dublin public transport sensor."""
|
"""Set up the Dublin public transport sensor."""
|
||||||
name = config.get(CONF_NAME)
|
name = config[CONF_NAME]
|
||||||
stop = config.get(CONF_STOP_ID)
|
stop = config[CONF_STOP_ID]
|
||||||
route = config.get(CONF_ROUTE)
|
route = config[CONF_ROUTE]
|
||||||
|
|
||||||
data = PublicTransportData(stop, route)
|
data = PublicTransportData(stop, route)
|
||||||
add_entities([DublinPublicTransportSensor(data, stop, route, name)], True)
|
add_entities([DublinPublicTransportSensor(data, stop, route, name)], True)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user