Clean up access to config in various integrations v4 (#34174)

* Clean up access to config in various integrations v4

* Address review comments
This commit is contained in:
springstan 2020-04-14 20:38:55 +02:00 committed by GitHub
parent 96aaa25aad
commit e2af216bcd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
20 changed files with 53 additions and 55 deletions

View file

@ -194,7 +194,7 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
vol.Inclusive(
CONF_LONGITUDE, "coordinates", "Latitude and longitude must exist together"
): cv.longitude,
vol.Optional(CONF_TIMEFRAME, default=60): vol.All(
vol.Optional(CONF_TIMEFRAME, default=DEFAULT_TIMEFRAME): vol.All(
vol.Coerce(int), vol.Range(min=5, max=120)
),
vol.Optional(CONF_NAME, default="br"): cv.string,
@ -207,7 +207,7 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
latitude = config.get(CONF_LATITUDE, hass.config.latitude)
longitude = config.get(CONF_LONGITUDE, hass.config.longitude)
timeframe = config.get(CONF_TIMEFRAME, DEFAULT_TIMEFRAME)
timeframe = config[CONF_TIMEFRAME]
if None in (latitude, longitude):
_LOGGER.error("Latitude or longitude not set in Home Assistant config")

View file

@ -102,7 +102,7 @@ class BrWeather(WeatherEntity):
def __init__(self, data, config):
"""Initialise the platform with a data instance and station name."""
self._stationname = config.get(CONF_NAME)
self._forecast = config.get(CONF_FORECAST)
self._forecast = config[CONF_FORECAST]
self._data = data
@property

View file

@ -40,9 +40,9 @@ CANARY_COMPONENTS = ["alarm_control_panel", "camera", "sensor"]
def setup(hass, config):
"""Set up the Canary component."""
conf = config[DOMAIN]
username = conf.get(CONF_USERNAME)
password = conf.get(CONF_PASSWORD)
timeout = conf.get(CONF_TIMEOUT)
username = conf[CONF_USERNAME]
password = conf[CONF_PASSWORD]
timeout = conf[CONF_TIMEOUT]
try:
hass.data[DATA_CANARY] = CanaryData(username, password, timeout)

View file

@ -42,7 +42,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
location,
device,
DEFAULT_TIMEOUT,
config.get(CONF_FFMPEG_ARGUMENTS),
config[CONF_FFMPEG_ARGUMENTS],
)
)

View file

@ -70,9 +70,7 @@ CHANNELS_SEEK_BY_SCHEMA = CHANNELS_SCHEMA.extend(
def setup_platform(hass, config, add_entities, discovery_info=None):
"""Set up the Channels platform."""
device = ChannelsPlayer(
config.get(CONF_NAME), config.get(CONF_HOST), config.get(CONF_PORT)
)
device = ChannelsPlayer(config[CONF_NAME], config[CONF_HOST], config[CONF_PORT])
if DATA_CHANNELS not in hass.data:
hass.data[DATA_CHANNELS] = []

View file

@ -42,7 +42,7 @@ class CiscoDeviceScanner(DeviceScanner):
self.host = config[CONF_HOST]
self.username = config[CONF_USERNAME]
self.port = config.get(CONF_PORT)
self.password = config.get(CONF_PASSWORD)
self.password = config[CONF_PASSWORD]
self.last_results = {}

View file

@ -44,7 +44,7 @@ def get_scanner(hass, config):
config[CONF_USERNAME],
config[CONF_PASSWORD],
config[CONF_SSL],
config.get(CONF_VERIFY_SSL),
config[CONF_VERIFY_SSL],
)
if not controller.is_logged_in():
return None

View file

@ -58,8 +58,8 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
def setup_platform(hass, config, add_entities, discovery_info=None):
"""Set up the Clementine platform."""
host = config.get(CONF_HOST)
port = config.get(CONF_PORT)
host = config[CONF_HOST]
port = config[CONF_PORT]
token = config.get(CONF_ACCESS_TOKEN)
client = ClementineRemote(host, port, token, reconnect=True)

View file

@ -29,8 +29,8 @@ class ClickatellNotificationService(BaseNotificationService):
def __init__(self, config):
"""Initialize the service."""
self.api_key = config.get(CONF_API_KEY)
self.recipient = config.get(CONF_RECIPIENT)
self.api_key = config[CONF_API_KEY]
self.recipient = config[CONF_RECIPIENT]
def send_message(self, message="", **kwargs):
"""Send a message to a user."""

View file

@ -56,11 +56,11 @@ class ClicksendNotificationService(BaseNotificationService):
def __init__(self, config):
"""Initialize the service."""
self.username = config.get(CONF_USERNAME)
self.api_key = config.get(CONF_API_KEY)
self.recipient = config.get(CONF_RECIPIENT)
self.language = config.get(CONF_LANGUAGE)
self.voice = config.get(CONF_VOICE)
self.username = config[CONF_USERNAME]
self.api_key = config[CONF_API_KEY]
self.recipient = config[CONF_RECIPIENT]
self.language = config[CONF_LANGUAGE]
self.voice = config[CONF_VOICE]
self.caller = config.get(CONF_CALLER)
if self.caller is None:
self.caller = self.recipient

View file

@ -61,8 +61,8 @@ def setup_platform(hass, config, add_entities, discover_info=None):
host = config.get(CONF_HOST)
password = config.get(CONF_PASSWORD)
port = config.get(CONF_PORT)
name = config.get(CONF_NAME)
port = config[CONF_PORT]
name = config[CONF_NAME]
try:
cmus_remote = CmusDevice(host, password, port, name)

View file

@ -48,10 +48,10 @@ def setup(hass, config):
Will automatically setup sensors to support
wallets discovered on the network.
"""
api_key = config[DOMAIN].get(CONF_API_KEY)
api_secret = config[DOMAIN].get(CONF_API_SECRET)
api_key = config[DOMAIN][CONF_API_KEY]
api_secret = config[DOMAIN][CONF_API_SECRET]
account_currencies = config[DOMAIN].get(CONF_ACCOUNT_CURRENCIES)
exchange_currencies = config[DOMAIN].get(CONF_EXCHANGE_CURRENCIES)
exchange_currencies = config[DOMAIN][CONF_EXCHANGE_CURRENCIES]
hass.data[DATA_COINBASE] = coinbase_data = CoinbaseData(api_key, api_secret)

View file

@ -42,9 +42,9 @@ SCAN_INTERVAL = timedelta(minutes=15)
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
{
vol.Optional(CONF_CURRENCY_ID, default=DEFAULT_CURRENCY_ID): cv.positive_int,
vol.Optional(
CONF_DISPLAY_CURRENCY, default=DEFAULT_DISPLAY_CURRENCY
): cv.string,
vol.Optional(CONF_DISPLAY_CURRENCY, default=DEFAULT_DISPLAY_CURRENCY): vol.All(
cv.string, vol.Upper
),
vol.Optional(
CONF_DISPLAY_CURRENCY_DECIMALS, default=DEFAULT_DISPLAY_CURRENCY_DECIMALS
): vol.All(vol.Coerce(int), vol.Range(min=1)),
@ -54,9 +54,9 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
def setup_platform(hass, config, add_entities, discovery_info=None):
"""Set up the CoinMarketCap sensor."""
currency_id = config.get(CONF_CURRENCY_ID)
display_currency = config.get(CONF_DISPLAY_CURRENCY).upper()
display_currency_decimals = config.get(CONF_DISPLAY_CURRENCY_DECIMALS)
currency_id = config[CONF_CURRENCY_ID]
display_currency = config[CONF_DISPLAY_CURRENCY]
display_currency_decimals = config[CONF_DISPLAY_CURRENCY_DECIMALS]
try:
CoinMarketCapData(currency_id, display_currency).update()

View file

@ -52,11 +52,11 @@ def setup(hass, config):
"""Set up the ComfoConnect bridge."""
conf = config[DOMAIN]
host = conf.get(CONF_HOST)
name = conf.get(CONF_NAME)
token = conf.get(CONF_TOKEN)
user_agent = conf.get(CONF_USER_AGENT)
pin = conf.get(CONF_PIN)
host = conf[CONF_HOST]
name = conf[CONF_NAME]
token = conf[CONF_TOKEN]
user_agent = conf[CONF_USER_AGENT]
pin = conf[CONF_PIN]
# Run discovery on the configured ip
bridges = Bridge.discover(host)

View file

@ -46,11 +46,11 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
def setup_platform(hass, config, add_entities, discovery_info=None):
"""Set up the Concord232 alarm control panel platform."""
name = config.get(CONF_NAME)
name = config[CONF_NAME]
code = config.get(CONF_CODE)
mode = config.get(CONF_MODE)
host = config.get(CONF_HOST)
port = config.get(CONF_PORT)
mode = config[CONF_MODE]
host = config[CONF_HOST]
port = config[CONF_PORT]
url = f"http://{host}:{port}"

View file

@ -44,10 +44,10 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
def setup_platform(hass, config, add_entities, discovery_info=None):
"""Set up the Concord232 binary sensor platform."""
host = config.get(CONF_HOST)
port = config.get(CONF_PORT)
exclude = config.get(CONF_EXCLUDE_ZONES)
zone_types = config.get(CONF_ZONE_TYPES)
host = config[CONF_HOST]
port = config[CONF_PORT]
exclude = config[CONF_EXCLUDE_ZONES]
zone_types = config[CONF_ZONE_TYPES]
sensors = []
try:

View file

@ -29,7 +29,7 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
def setup_platform(hass, config, add_entities, discovery_info=None):
"""Set up the CPU speed sensor."""
name = config.get(CONF_NAME)
name = config[CONF_NAME]
add_entities([CpuSpeedSensor(name)], True)

View file

@ -50,8 +50,8 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
"""Set up the Crime Reports platform."""
latitude = config.get(CONF_LATITUDE, hass.config.latitude)
longitude = config.get(CONF_LONGITUDE, hass.config.longitude)
name = config.get(CONF_NAME)
radius = config.get(CONF_RADIUS)
name = config[CONF_NAME]
radius = config[CONF_RADIUS]
include = config.get(CONF_INCLUDE)
exclude = config.get(CONF_EXCLUDE)

View file

@ -53,10 +53,10 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
def setup_platform(hass, config, add_entities, discovery_info=None):
"""Set up the CUPS sensor."""
host = config.get(CONF_HOST)
port = config.get(CONF_PORT)
printers = config.get(CONF_PRINTERS)
is_cups = config.get(CONF_IS_CUPS_SERVER)
host = config[CONF_HOST]
port = config[CONF_PORT]
printers = config[CONF_PRINTERS]
is_cups = config[CONF_IS_CUPS_SERVER]
if is_cups:
data = CupsData(host, port, None)

View file

@ -40,15 +40,15 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
def setup_platform(hass, config, add_entities, discovery_info=None):
"""Set up the Currencylayer sensor."""
base = config.get(CONF_BASE)
api_key = config.get(CONF_API_KEY)
base = config[CONF_BASE]
api_key = config[CONF_API_KEY]
parameters = {"source": base, "access_key": api_key, "format": 1}
rest = CurrencylayerData(_RESOURCE, parameters)
response = requests.get(_RESOURCE, params=parameters, timeout=10)
sensors = []
for variable in config["quote"]:
for variable in config[CONF_QUOTE]:
sensors.append(CurrencylayerSensor(rest, base, variable))
if "error" in response.json():
return False