Clean up access to config in various integrations ()

pull/33815/head
springstan 2020-04-08 12:59:38 +02:00 committed by GitHub
parent ba8ae17487
commit c6c7dd10f5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 38 additions and 35 deletions
homeassistant/components
acer_projector
aladdin_connect
alarmdecoder
alpha_vantage
amazon_polly

View File

@ -61,10 +61,10 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
def setup_platform(hass, config, add_entities, discovery_info=None):
"""Connect with serial port and return Acer Projector."""
serial_port = config.get(CONF_FILENAME)
name = config.get(CONF_NAME)
timeout = config.get(CONF_TIMEOUT)
write_timeout = config.get(CONF_WRITE_TIMEOUT)
serial_port = config[CONF_FILENAME]
name = config[CONF_NAME]
timeout = config[CONF_TIMEOUT]
write_timeout = config[CONF_WRITE_TIMEOUT]
add_entities([AcerSwitch(serial_port, name, timeout, write_timeout)], True)

View File

@ -82,9 +82,9 @@ def setup(hass, config):
conf = config[DOMAIN]
net_id = conf.get(CONF_DEVICE)
net_id = conf[CONF_DEVICE]
ip_address = conf.get(CONF_IP_ADDRESS)
port = conf.get(CONF_PORT)
port = conf[CONF_PORT]
client = pyads.Connection(net_id, port, ip_address)

View File

@ -29,8 +29,8 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
"""Set up the Binary Sensor platform for ADS."""
ads_hub = hass.data.get(DATA_ADS)
ads_var = config.get(CONF_ADS_VAR)
name = config.get(CONF_NAME)
ads_var = config[CONF_ADS_VAR]
name = config[CONF_NAME]
device_class = config.get(CONF_DEVICE_CLASS)
ads_sensor = AdsBinarySensor(ads_hub, name, ads_var, device_class)

View File

@ -36,9 +36,9 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
"""Set up the light platform for ADS."""
ads_hub = hass.data.get(DATA_ADS)
ads_var_enable = config.get(CONF_ADS_VAR)
ads_var_enable = config[CONF_ADS_VAR]
ads_var_brightness = config.get(CONF_ADS_VAR_BRIGHTNESS)
name = config.get(CONF_NAME)
name = config[CONF_NAME]
add_entities([AdsLight(ads_hub, ads_var_enable, ads_var_brightness, name)])

View File

@ -36,9 +36,9 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
"""Set up an ADS sensor device."""
ads_hub = hass.data.get(ads.DATA_ADS)
ads_var = config.get(CONF_ADS_VAR)
ads_type = config.get(CONF_ADS_TYPE)
name = config.get(CONF_NAME)
ads_var = config[CONF_ADS_VAR]
ads_type = config[CONF_ADS_TYPE]
name = config[CONF_NAME]
unit_of_measurement = config.get(CONF_UNIT_OF_MEASUREMENT)
factor = config.get(CONF_ADS_FACTOR)

View File

@ -14,7 +14,10 @@ _LOGGER = logging.getLogger(__name__)
DEFAULT_NAME = "ADS Switch"
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
{vol.Required(CONF_ADS_VAR): cv.string, vol.Optional(CONF_NAME): cv.string}
{
vol.Required(CONF_ADS_VAR): cv.string,
vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
}
)
@ -22,8 +25,8 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
"""Set up switch platform for ADS."""
ads_hub = hass.data.get(DATA_ADS)
name = config.get(CONF_NAME)
ads_var = config.get(CONF_ADS_VAR)
name = config[CONF_NAME]
ads_var = config[CONF_ADS_VAR]
add_entities([AdsSwitch(ads_hub, name, ads_var)])

View File

@ -42,8 +42,8 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
def setup_platform(hass, config, add_entities, discovery_info=None):
"""Set up the Aladdin Connect platform."""
username = config.get(CONF_USERNAME)
password = config.get(CONF_PASSWORD)
username = config[CONF_USERNAME]
password = config[CONF_PASSWORD]
acc = AladdinConnectClient(username, password)
try:

View File

@ -187,12 +187,12 @@ def setup(hass, config):
controller = False
if device_type == "socket":
host = device.get(CONF_HOST)
port = device.get(CONF_DEVICE_PORT)
host = device[CONF_HOST]
port = device[CONF_DEVICE_PORT]
controller = AlarmDecoder(SocketDevice(interface=(host, port)))
elif device_type == "serial":
path = device.get(CONF_DEVICE_PATH)
baud = device.get(CONF_DEVICE_BAUD)
path = device[CONF_DEVICE_PATH]
baud = device[CONF_DEVICE_BAUD]
controller = AlarmDecoder(SerialDevice(interface=path))
elif device_type == "usb":
AlarmDecoder(USBDevice.find())

View File

@ -79,15 +79,15 @@ async def async_setup(hass, config):
if not cfg:
cfg = {}
name = cfg.get(CONF_NAME)
watched_entity_id = cfg.get(CONF_ENTITY_ID)
alert_state = cfg.get(CONF_STATE)
repeat = cfg.get(CONF_REPEAT)
skip_first = cfg.get(CONF_SKIP_FIRST)
name = cfg[CONF_NAME]
watched_entity_id = cfg[CONF_ENTITY_ID]
alert_state = cfg[CONF_STATE]
repeat = cfg[CONF_REPEAT]
skip_first = cfg[CONF_SKIP_FIRST]
message_template = cfg.get(CONF_ALERT_MESSAGE)
done_message_template = cfg.get(CONF_DONE_MESSAGE)
notifiers = cfg.get(CONF_NOTIFIERS)
can_ack = cfg.get(CONF_CAN_ACK)
notifiers = cfg[CONF_NOTIFIERS]
can_ack = cfg[CONF_CAN_ACK]
title_template = cfg.get(CONF_TITLE)
data = cfg.get(CONF_DATA)

View File

@ -64,7 +64,7 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
def setup_platform(hass, config, add_entities, discovery_info=None):
"""Set up the Alpha Vantage sensor."""
api_key = config.get(CONF_API_KEY)
api_key = config[CONF_API_KEY]
symbols = config.get(CONF_SYMBOLS, [])
conversions = config.get(CONF_FOREIGN_EXCHANGE, [])
@ -162,8 +162,8 @@ class AlphaVantageForeignExchange(Entity):
def __init__(self, foreign_exchange, config):
"""Initialize the sensor."""
self._foreign_exchange = foreign_exchange
self._from_currency = config.get(CONF_FROM)
self._to_currency = config.get(CONF_TO)
self._from_currency = config[CONF_FROM]
self._to_currency = config[CONF_TO]
if CONF_NAME in config:
self._name = config.get(CONF_NAME)
else:

View File

@ -147,7 +147,7 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
def get_engine(hass, config, discovery_info=None):
"""Set up Amazon Polly speech component."""
output_format = config.get(CONF_OUTPUT_FORMAT)
output_format = config[CONF_OUTPUT_FORMAT]
sample_rate = config.get(CONF_SAMPLE_RATE, DEFAULT_SAMPLE_RATES[output_format])
if sample_rate not in SUPPORTED_SAMPLE_RATES_MAP.get(output_format):
_LOGGER.error(
@ -163,7 +163,7 @@ def get_engine(hass, config, discovery_info=None):
boto3.setup_default_session(profile_name=profile)
aws_config = {
CONF_REGION: config.get(CONF_REGION),
CONF_REGION: config[CONF_REGION],
CONF_ACCESS_KEY_ID: config.get(CONF_ACCESS_KEY_ID),
CONF_SECRET_ACCESS_KEY: config.get(CONF_SECRET_ACCESS_KEY),
}
@ -197,7 +197,7 @@ class AmazonPollyProvider(Provider):
self.config = config
self.supported_langs = supported_languages
self.all_voices = all_voices
self.default_voice = self.config.get(CONF_VOICE)
self.default_voice = self.config[CONF_VOICE]
self.name = "Amazon Polly"
@property