Clean up access to config in various integrations v2 (#33763)

This commit is contained in:
springstan 2020-04-07 22:45:56 +02:00 committed by GitHub
parent d95ffb3aa3
commit d7e3b0b755
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
20 changed files with 59 additions and 59 deletions

View File

@ -31,10 +31,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 PwrCtrl devices/switches.""" """Set up PwrCtrl devices/switches."""
host = config.get(CONF_HOST) host = config.get(CONF_HOST)
username = config.get(CONF_USERNAME) username = config[CONF_USERNAME]
password = config.get(CONF_PASSWORD) password = config[CONF_PASSWORD]
port_recv = config.get(CONF_PORT_RECV) port_recv = config[CONF_PORT_RECV]
port_send = config.get(CONF_PORT_SEND) port_send = config[CONF_PORT_SEND]
try: try:
master = DeviceMaster( master = DeviceMaster(

View File

@ -53,8 +53,8 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
async def async_setup_platform(hass, config, async_add_entities, discovery_info=None): async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
"""Set up our socket to the AVR.""" """Set up our socket to the AVR."""
host = config.get(CONF_HOST) host = config[CONF_HOST]
port = config.get(CONF_PORT) port = config[CONF_PORT]
name = config.get(CONF_NAME) name = config.get(CONF_NAME)
device = None device = None

View File

@ -37,8 +37,8 @@ CONFIG_SCHEMA = vol.Schema(
def setup(hass, config): def setup(hass, config):
"""Use config values to set up a function enabling status retrieval.""" """Use config values to set up a function enabling status retrieval."""
conf = config[DOMAIN] conf = config[DOMAIN]
host = conf.get(CONF_HOST) host = conf[CONF_HOST]
port = conf.get(CONF_PORT) port = conf[CONF_PORT]
apcups_data = APCUPSdData(host, port) apcups_data = APCUPSdData(host, port)
hass.data[DOMAIN] = apcups_data hass.data[DOMAIN] = apcups_data

View File

@ -32,7 +32,7 @@ class OnlineStatus(BinarySensorDevice):
@property @property
def name(self): def name(self):
"""Return the name of the UPS online status sensor.""" """Return the name of the UPS online status sensor."""
return self._config.get(CONF_NAME) return self._config[CONF_NAME]
@property @property
def is_on(self): def is_on(self):

View File

@ -45,10 +45,10 @@ REGISTER_SERVICE_SCHEMA = vol.Schema(
def get_service(hass, config, discovery_info=None): def get_service(hass, config, discovery_info=None):
"""Return push service.""" """Return push service."""
name = config.get(CONF_NAME) name = config[CONF_NAME]
cert_file = config.get(CONF_CERTFILE) cert_file = config[CONF_CERTFILE]
topic = config.get(CONF_TOPIC) topic = config[CONF_TOPIC]
sandbox = config.get(CONF_SANDBOX) sandbox = config[CONF_SANDBOX]
service = ApnsNotificationService(hass, name, topic, sandbox, cert_file) service = ApnsNotificationService(hass, name, topic, sandbox, cert_file)
hass.services.register( hass.services.register(

View File

@ -52,7 +52,7 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
sensors = [] sensors = []
processor = hass.data[DOMAIN] processor = hass.data[DOMAIN]
for sensor_type in config.get(CONF_MONITORED_CONDITIONS): for sensor_type in config[CONF_MONITORED_CONDITIONS]:
sensors.append(AquaLogicSensor(processor, sensor_type)) sensors.append(AquaLogicSensor(processor, sensor_type))
async_add_entities(sensors) async_add_entities(sensors)

View File

@ -39,7 +39,7 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
switches = [] switches = []
processor = hass.data[DOMAIN] processor = hass.data[DOMAIN]
for switch_type in config.get(CONF_MONITORED_CONDITIONS): for switch_type in config[CONF_MONITORED_CONDITIONS]:
switches.append(AquaLogicSwitch(processor, switch_type)) switches.append(AquaLogicSwitch(processor, switch_type))
async_add_entities(switches) async_add_entities(switches)

View File

@ -79,11 +79,11 @@ SOURCES = {
def setup_platform(hass, config, add_entities, discovery_info=None): def setup_platform(hass, config, add_entities, discovery_info=None):
"""Set up the Sharp Aquos TV platform.""" """Set up the Sharp Aquos TV platform."""
name = config.get(CONF_NAME) name = config[CONF_NAME]
port = config.get(CONF_PORT) port = config[CONF_PORT]
username = config.get(CONF_USERNAME) username = config[CONF_USERNAME]
password = config.get(CONF_PASSWORD) password = config[CONF_PASSWORD]
power_on_enabled = config.get("power_on_enabled") power_on_enabled = config["power_on_enabled"]
if discovery_info: if discovery_info:
_LOGGER.debug("%s", discovery_info) _LOGGER.debug("%s", discovery_info)
@ -96,7 +96,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
add_entities([SharpAquosTVDevice(name, remote, power_on_enabled)]) add_entities([SharpAquosTVDevice(name, remote, power_on_enabled)])
return True return True
host = config.get(CONF_HOST) host = config[CONF_HOST]
remote = sharp_aquos_rc.TV(host, port, username, password, 15, 1) remote = sharp_aquos_rc.TV(host, port, username, password, 15, 1)
add_entities([SharpAquosTVDevice(name, remote, power_on_enabled)]) add_entities([SharpAquosTVDevice(name, remote, power_on_enabled)])

View File

@ -26,7 +26,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
"""Set up the Arduino platform.""" """Set up the Arduino platform."""
board = hass.data[DOMAIN] board = hass.data[DOMAIN]
pins = config.get(CONF_PINS) pins = config[CONF_PINS]
sensors = [] sensors = []
for pinnum, pin in pins.items(): for pinnum, pin in pins.items():

View File

@ -33,7 +33,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
"""Set up the Arduino platform.""" """Set up the Arduino platform."""
board = hass.data[DOMAIN] board = hass.data[DOMAIN]
pins = config.get(CONF_PINS) pins = config[CONF_PINS]
switches = [] switches = []
for pinnum, pin in pins.items(): for pinnum, pin in pins.items():
@ -47,13 +47,13 @@ class ArduinoSwitch(SwitchDevice):
def __init__(self, pin, options, board): def __init__(self, pin, options, board):
"""Initialize the Pin.""" """Initialize the Pin."""
self._pin = pin self._pin = pin
self._name = options.get(CONF_NAME) self._name = options[CONF_NAME]
self.pin_type = CONF_TYPE self.pin_type = CONF_TYPE
self.direction = "out" self.direction = "out"
self._state = options.get(CONF_INITIAL) self._state = options[CONF_INITIAL]
if options.get(CONF_NEGATE): if options[CONF_NEGATE]:
self.turn_on_handler = board.set_digital_out_low self.turn_on_handler = board.set_digital_out_low
self.turn_off_handler = board.set_digital_out_high self.turn_off_handler = board.set_digital_out_high
else: else:

View File

@ -30,8 +30,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 aREST binary sensor.""" """Set up the aREST binary sensor."""
resource = config.get(CONF_RESOURCE) resource = config[CONF_RESOURCE]
pin = config.get(CONF_PIN) pin = config[CONF_PIN]
device_class = config.get(CONF_DEVICE_CLASS) device_class = config.get(CONF_DEVICE_CLASS)
try: try:

View File

@ -51,9 +51,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 aREST sensor.""" """Set up the aREST sensor."""
resource = config.get(CONF_RESOURCE) resource = config[CONF_RESOURCE]
var_conf = config.get(CONF_MONITORED_VARIABLES) var_conf = config[CONF_MONITORED_VARIABLES]
pins = config.get(CONF_PINS) pins = config[CONF_PINS]
try: try:
response = requests.get(resource, timeout=10).json() response = requests.get(resource, timeout=10).json()

View File

@ -40,7 +40,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 aREST switches.""" """Set up the aREST switches."""
resource = config.get(CONF_RESOURCE) resource = config[CONF_RESOURCE]
try: try:
response = requests.get(resource, timeout=10) response = requests.get(resource, timeout=10)
@ -54,7 +54,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
return False return False
dev = [] dev = []
pins = config.get(CONF_PINS) pins = config[CONF_PINS]
for pinnum, pin in pins.items(): for pinnum, pin in pins.items():
dev.append( dev.append(
ArestSwitchPin( ArestSwitchPin(
@ -62,11 +62,11 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
config.get(CONF_NAME, response.json()[CONF_NAME]), config.get(CONF_NAME, response.json()[CONF_NAME]),
pin.get(CONF_NAME), pin.get(CONF_NAME),
pinnum, pinnum,
pin.get(CONF_INVERT), pin[CONF_INVERT],
) )
) )
functions = config.get(CONF_FUNCTIONS) functions = config[CONF_FUNCTIONS]
for funcname, func in functions.items(): for funcname, func in functions.items():
dev.append( dev.append(
ArestSwitchFunction( ArestSwitchFunction(

View File

@ -43,9 +43,9 @@ CONFIG_SCHEMA = vol.Schema(
def setup(hass, config): def setup(hass, config):
"""Set up an Arlo component.""" """Set up an Arlo 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]
scan_interval = conf.get(CONF_SCAN_INTERVAL) scan_interval = conf[CONF_SCAN_INTERVAL]
try: try:

View File

@ -53,9 +53,9 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
if not arlo.base_stations: if not arlo.base_stations:
return return
home_mode_name = config.get(CONF_HOME_MODE_NAME) home_mode_name = config[CONF_HOME_MODE_NAME]
away_mode_name = config.get(CONF_AWAY_MODE_NAME) away_mode_name = config[CONF_AWAY_MODE_NAME]
night_mode_name = config.get(CONF_NIGHT_MODE_NAME) night_mode_name = config[CONF_NIGHT_MODE_NAME]
base_stations = [] base_stations = []
for base_station in arlo.base_stations: for base_station in arlo.base_stations:
base_stations.append( base_stations.append(

View File

@ -51,7 +51,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]:
if sensor_type == "total_cameras": if sensor_type == "total_cameras":
sensors.append(ArloSensor(SENSOR_TYPES[sensor_type][0], arlo, sensor_type)) sensors.append(ArloSensor(SENSOR_TYPES[sensor_type][0], arlo, sensor_type))
else: else:

View File

@ -43,9 +43,9 @@ def setup(hass, config):
"""Set up for the Asterisk Voicemail box.""" """Set up for the Asterisk Voicemail box."""
conf = config.get(DOMAIN) conf = config.get(DOMAIN)
host = conf.get(CONF_HOST) host = conf[CONF_HOST]
port = conf.get(CONF_PORT) port = conf[CONF_PORT]
password = conf.get(CONF_PASSWORD) password = conf[CONF_PASSWORD]
hass.data[DOMAIN] = AsteriskData(hass, host, port, password, config) hass.data[DOMAIN] = AsteriskData(hass, host, port, password, config)

View File

@ -41,8 +41,8 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
_LOGGER.error("Lat. or long. not set in Home Assistant config") _LOGGER.error("Lat. or long. not set in Home Assistant config")
return False return False
name = config.get(CONF_NAME) name = config[CONF_NAME]
threshold = config.get(CONF_THRESHOLD) threshold = config[CONF_THRESHOLD]
try: try:
aurora_data = AuroraData(hass.config.latitude, hass.config.longitude, threshold) aurora_data = AuroraData(hass.config.latitude, hass.config.longitude, threshold)

View File

@ -63,21 +63,21 @@ class BaiduTTSProvider(Provider):
def __init__(self, hass, conf): def __init__(self, hass, conf):
"""Init Baidu TTS service.""" """Init Baidu TTS service."""
self.hass = hass self.hass = hass
self._lang = conf.get(CONF_LANG) self._lang = conf[CONF_LANG]
self._codec = "mp3" self._codec = "mp3"
self.name = "BaiduTTS" self.name = "BaiduTTS"
self._app_data = { self._app_data = {
"appid": conf.get(CONF_APP_ID), "appid": conf[CONF_APP_ID],
"apikey": conf.get(CONF_API_KEY), "apikey": conf[CONF_API_KEY],
"secretkey": conf.get(CONF_SECRET_KEY), "secretkey": conf[CONF_SECRET_KEY],
} }
self._speech_conf_data = { self._speech_conf_data = {
_OPTIONS[CONF_PERSON]: conf.get(CONF_PERSON), _OPTIONS[CONF_PERSON]: conf[CONF_PERSON],
_OPTIONS[CONF_PITCH]: conf.get(CONF_PITCH), _OPTIONS[CONF_PITCH]: conf[CONF_PITCH],
_OPTIONS[CONF_SPEED]: conf.get(CONF_SPEED), _OPTIONS[CONF_SPEED]: conf[CONF_SPEED],
_OPTIONS[CONF_VOLUME]: conf.get(CONF_VOLUME), _OPTIONS[CONF_VOLUME]: conf[CONF_VOLUME],
} }
@property @property

View File

@ -97,10 +97,10 @@ def update_probability(prior, prob_given_true, prob_given_false):
async def async_setup_platform(hass, config, async_add_entities, discovery_info=None): async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
"""Set up the Bayesian Binary sensor.""" """Set up the Bayesian Binary sensor."""
name = config.get(CONF_NAME) name = config[CONF_NAME]
observations = config.get(CONF_OBSERVATIONS) observations = config[CONF_OBSERVATIONS]
prior = config.get(CONF_PRIOR) prior = config[CONF_PRIOR]
probability_threshold = config.get(CONF_PROBABILITY_THRESHOLD) probability_threshold = config[CONF_PROBABILITY_THRESHOLD]
device_class = config.get(CONF_DEVICE_CLASS) device_class = config.get(CONF_DEVICE_CLASS)
async_add_entities( async_add_entities(