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( vol.Inclusive(
CONF_LONGITUDE, "coordinates", "Latitude and longitude must exist together" CONF_LONGITUDE, "coordinates", "Latitude and longitude must exist together"
): cv.longitude, ): 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.Coerce(int), vol.Range(min=5, max=120)
), ),
vol.Optional(CONF_NAME, default="br"): cv.string, 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) latitude = config.get(CONF_LATITUDE, hass.config.latitude)
longitude = config.get(CONF_LONGITUDE, hass.config.longitude) longitude = config.get(CONF_LONGITUDE, hass.config.longitude)
timeframe = config.get(CONF_TIMEFRAME, DEFAULT_TIMEFRAME) timeframe = config[CONF_TIMEFRAME]
if None in (latitude, longitude): if None in (latitude, longitude):
_LOGGER.error("Latitude or longitude not set in Home Assistant config") _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): def __init__(self, data, config):
"""Initialise the platform with a data instance and station name.""" """Initialise the platform with a data instance and station name."""
self._stationname = config.get(CONF_NAME) self._stationname = config.get(CONF_NAME)
self._forecast = config.get(CONF_FORECAST) self._forecast = config[CONF_FORECAST]
self._data = data self._data = data
@property @property

View file

@ -40,9 +40,9 @@ CANARY_COMPONENTS = ["alarm_control_panel", "camera", "sensor"]
def setup(hass, config): def setup(hass, config):
"""Set up the Canary component.""" """Set up the Canary component."""
conf = config[DOMAIN] conf = config[DOMAIN]
username = conf.get(CONF_USERNAME) username = conf[CONF_USERNAME]
password = conf.get(CONF_PASSWORD) password = conf[CONF_PASSWORD]
timeout = conf.get(CONF_TIMEOUT) timeout = conf[CONF_TIMEOUT]
try: try:
hass.data[DATA_CANARY] = CanaryData(username, password, timeout) 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, location,
device, device,
DEFAULT_TIMEOUT, 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): def setup_platform(hass, config, add_entities, discovery_info=None):
"""Set up the Channels platform.""" """Set up the Channels platform."""
device = ChannelsPlayer( device = ChannelsPlayer(config[CONF_NAME], config[CONF_HOST], config[CONF_PORT])
config.get(CONF_NAME), config.get(CONF_HOST), config.get(CONF_PORT)
)
if DATA_CHANNELS not in hass.data: if DATA_CHANNELS not in hass.data:
hass.data[DATA_CHANNELS] = [] hass.data[DATA_CHANNELS] = []

View file

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

View file

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

View file

@ -58,8 +58,8 @@ 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 Clementine platform.""" """Set up the Clementine platform."""
host = config.get(CONF_HOST) host = config[CONF_HOST]
port = config.get(CONF_PORT) port = config[CONF_PORT]
token = config.get(CONF_ACCESS_TOKEN) token = config.get(CONF_ACCESS_TOKEN)
client = ClementineRemote(host, port, token, reconnect=True) client = ClementineRemote(host, port, token, reconnect=True)

View file

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

View file

@ -56,11 +56,11 @@ class ClicksendNotificationService(BaseNotificationService):
def __init__(self, config): def __init__(self, config):
"""Initialize the service.""" """Initialize the service."""
self.username = config.get(CONF_USERNAME) self.username = config[CONF_USERNAME]
self.api_key = config.get(CONF_API_KEY) self.api_key = config[CONF_API_KEY]
self.recipient = config.get(CONF_RECIPIENT) self.recipient = config[CONF_RECIPIENT]
self.language = config.get(CONF_LANGUAGE) self.language = config[CONF_LANGUAGE]
self.voice = config.get(CONF_VOICE) self.voice = config[CONF_VOICE]
self.caller = config.get(CONF_CALLER) self.caller = config.get(CONF_CALLER)
if self.caller is None: if self.caller is None:
self.caller = self.recipient 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) host = config.get(CONF_HOST)
password = config.get(CONF_PASSWORD) password = config.get(CONF_PASSWORD)
port = config.get(CONF_PORT) port = config[CONF_PORT]
name = config.get(CONF_NAME) name = config[CONF_NAME]
try: try:
cmus_remote = CmusDevice(host, password, port, name) cmus_remote = CmusDevice(host, password, port, name)

View file

@ -48,10 +48,10 @@ def setup(hass, config):
Will automatically setup sensors to support Will automatically setup sensors to support
wallets discovered on the network. wallets discovered on the network.
""" """
api_key = config[DOMAIN].get(CONF_API_KEY) api_key = config[DOMAIN][CONF_API_KEY]
api_secret = config[DOMAIN].get(CONF_API_SECRET) api_secret = config[DOMAIN][CONF_API_SECRET]
account_currencies = config[DOMAIN].get(CONF_ACCOUNT_CURRENCIES) 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) 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( PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
{ {
vol.Optional(CONF_CURRENCY_ID, default=DEFAULT_CURRENCY_ID): cv.positive_int, vol.Optional(CONF_CURRENCY_ID, default=DEFAULT_CURRENCY_ID): cv.positive_int,
vol.Optional( vol.Optional(CONF_DISPLAY_CURRENCY, default=DEFAULT_DISPLAY_CURRENCY): vol.All(
CONF_DISPLAY_CURRENCY, default=DEFAULT_DISPLAY_CURRENCY cv.string, vol.Upper
): cv.string, ),
vol.Optional( vol.Optional(
CONF_DISPLAY_CURRENCY_DECIMALS, default=DEFAULT_DISPLAY_CURRENCY_DECIMALS CONF_DISPLAY_CURRENCY_DECIMALS, default=DEFAULT_DISPLAY_CURRENCY_DECIMALS
): vol.All(vol.Coerce(int), vol.Range(min=1)), ): 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): def setup_platform(hass, config, add_entities, discovery_info=None):
"""Set up the CoinMarketCap sensor.""" """Set up the CoinMarketCap sensor."""
currency_id = config.get(CONF_CURRENCY_ID) currency_id = config[CONF_CURRENCY_ID]
display_currency = config.get(CONF_DISPLAY_CURRENCY).upper() display_currency = config[CONF_DISPLAY_CURRENCY]
display_currency_decimals = config.get(CONF_DISPLAY_CURRENCY_DECIMALS) display_currency_decimals = config[CONF_DISPLAY_CURRENCY_DECIMALS]
try: try:
CoinMarketCapData(currency_id, display_currency).update() CoinMarketCapData(currency_id, display_currency).update()

View file

@ -52,11 +52,11 @@ def setup(hass, config):
"""Set up the ComfoConnect bridge.""" """Set up the ComfoConnect bridge."""
conf = config[DOMAIN] conf = config[DOMAIN]
host = conf.get(CONF_HOST) host = conf[CONF_HOST]
name = conf.get(CONF_NAME) name = conf[CONF_NAME]
token = conf.get(CONF_TOKEN) token = conf[CONF_TOKEN]
user_agent = conf.get(CONF_USER_AGENT) user_agent = conf[CONF_USER_AGENT]
pin = conf.get(CONF_PIN) pin = conf[CONF_PIN]
# Run discovery on the configured ip # Run discovery on the configured ip
bridges = Bridge.discover(host) 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): def setup_platform(hass, config, add_entities, discovery_info=None):
"""Set up the Concord232 alarm control panel platform.""" """Set up the Concord232 alarm control panel platform."""
name = config.get(CONF_NAME) name = config[CONF_NAME]
code = config.get(CONF_CODE) code = config.get(CONF_CODE)
mode = config.get(CONF_MODE) mode = config[CONF_MODE]
host = config.get(CONF_HOST) host = config[CONF_HOST]
port = config.get(CONF_PORT) port = config[CONF_PORT]
url = f"http://{host}:{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): def setup_platform(hass, config, add_entities, discovery_info=None):
"""Set up the Concord232 binary sensor platform.""" """Set up the Concord232 binary sensor platform."""
host = config.get(CONF_HOST) host = config[CONF_HOST]
port = config.get(CONF_PORT) port = config[CONF_PORT]
exclude = config.get(CONF_EXCLUDE_ZONES) exclude = config[CONF_EXCLUDE_ZONES]
zone_types = config.get(CONF_ZONE_TYPES) zone_types = config[CONF_ZONE_TYPES]
sensors = [] sensors = []
try: try:

View file

@ -29,7 +29,7 @@ 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 CPU speed sensor.""" """Set up the CPU speed sensor."""
name = config.get(CONF_NAME) name = config[CONF_NAME]
add_entities([CpuSpeedSensor(name)], True) 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.""" """Set up the Crime Reports platform."""
latitude = config.get(CONF_LATITUDE, hass.config.latitude) latitude = config.get(CONF_LATITUDE, hass.config.latitude)
longitude = config.get(CONF_LONGITUDE, hass.config.longitude) longitude = config.get(CONF_LONGITUDE, hass.config.longitude)
name = config.get(CONF_NAME) name = config[CONF_NAME]
radius = config.get(CONF_RADIUS) radius = config[CONF_RADIUS]
include = config.get(CONF_INCLUDE) include = config.get(CONF_INCLUDE)
exclude = config.get(CONF_EXCLUDE) 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): def setup_platform(hass, config, add_entities, discovery_info=None):
"""Set up the CUPS sensor.""" """Set up the CUPS sensor."""
host = config.get(CONF_HOST) host = config[CONF_HOST]
port = config.get(CONF_PORT) port = config[CONF_PORT]
printers = config.get(CONF_PRINTERS) printers = config[CONF_PRINTERS]
is_cups = config.get(CONF_IS_CUPS_SERVER) is_cups = config[CONF_IS_CUPS_SERVER]
if is_cups: if is_cups:
data = CupsData(host, port, None) 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): def setup_platform(hass, config, add_entities, discovery_info=None):
"""Set up the Currencylayer sensor.""" """Set up the Currencylayer sensor."""
base = config.get(CONF_BASE) base = config[CONF_BASE]
api_key = config.get(CONF_API_KEY) api_key = config[CONF_API_KEY]
parameters = {"source": base, "access_key": api_key, "format": 1} parameters = {"source": base, "access_key": api_key, "format": 1}
rest = CurrencylayerData(_RESOURCE, parameters) rest = CurrencylayerData(_RESOURCE, parameters)
response = requests.get(_RESOURCE, params=parameters, timeout=10) response = requests.get(_RESOURCE, params=parameters, timeout=10)
sensors = [] sensors = []
for variable in config["quote"]: for variable in config[CONF_QUOTE]:
sensors.append(CurrencylayerSensor(rest, base, variable)) sensors.append(CurrencylayerSensor(rest, base, variable))
if "error" in response.json(): if "error" in response.json():
return False return False