mirror of
https://github.com/home-assistant/core.git
synced 2025-04-25 17:57:55 +00:00
Clean up access to config in various integrations v2 (#33763)
This commit is contained in:
parent
d95ffb3aa3
commit
d7e3b0b755
@ -31,10 +31,10 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
||||
def setup_platform(hass, config, add_entities, discovery_info=None):
|
||||
"""Set up PwrCtrl devices/switches."""
|
||||
host = config.get(CONF_HOST)
|
||||
username = config.get(CONF_USERNAME)
|
||||
password = config.get(CONF_PASSWORD)
|
||||
port_recv = config.get(CONF_PORT_RECV)
|
||||
port_send = config.get(CONF_PORT_SEND)
|
||||
username = config[CONF_USERNAME]
|
||||
password = config[CONF_PASSWORD]
|
||||
port_recv = config[CONF_PORT_RECV]
|
||||
port_send = config[CONF_PORT_SEND]
|
||||
|
||||
try:
|
||||
master = DeviceMaster(
|
||||
|
@ -53,8 +53,8 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
||||
async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
|
||||
"""Set up our socket to the AVR."""
|
||||
|
||||
host = config.get(CONF_HOST)
|
||||
port = config.get(CONF_PORT)
|
||||
host = config[CONF_HOST]
|
||||
port = config[CONF_PORT]
|
||||
name = config.get(CONF_NAME)
|
||||
device = None
|
||||
|
||||
|
@ -37,8 +37,8 @@ CONFIG_SCHEMA = vol.Schema(
|
||||
def setup(hass, config):
|
||||
"""Use config values to set up a function enabling status retrieval."""
|
||||
conf = config[DOMAIN]
|
||||
host = conf.get(CONF_HOST)
|
||||
port = conf.get(CONF_PORT)
|
||||
host = conf[CONF_HOST]
|
||||
port = conf[CONF_PORT]
|
||||
|
||||
apcups_data = APCUPSdData(host, port)
|
||||
hass.data[DOMAIN] = apcups_data
|
||||
|
@ -32,7 +32,7 @@ class OnlineStatus(BinarySensorDevice):
|
||||
@property
|
||||
def name(self):
|
||||
"""Return the name of the UPS online status sensor."""
|
||||
return self._config.get(CONF_NAME)
|
||||
return self._config[CONF_NAME]
|
||||
|
||||
@property
|
||||
def is_on(self):
|
||||
|
@ -45,10 +45,10 @@ REGISTER_SERVICE_SCHEMA = vol.Schema(
|
||||
|
||||
def get_service(hass, config, discovery_info=None):
|
||||
"""Return push service."""
|
||||
name = config.get(CONF_NAME)
|
||||
cert_file = config.get(CONF_CERTFILE)
|
||||
topic = config.get(CONF_TOPIC)
|
||||
sandbox = config.get(CONF_SANDBOX)
|
||||
name = config[CONF_NAME]
|
||||
cert_file = config[CONF_CERTFILE]
|
||||
topic = config[CONF_TOPIC]
|
||||
sandbox = config[CONF_SANDBOX]
|
||||
|
||||
service = ApnsNotificationService(hass, name, topic, sandbox, cert_file)
|
||||
hass.services.register(
|
||||
|
@ -52,7 +52,7 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
|
||||
sensors = []
|
||||
|
||||
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))
|
||||
|
||||
async_add_entities(sensors)
|
||||
|
@ -39,7 +39,7 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
|
||||
switches = []
|
||||
|
||||
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))
|
||||
|
||||
async_add_entities(switches)
|
||||
|
@ -79,11 +79,11 @@ SOURCES = {
|
||||
def setup_platform(hass, config, add_entities, discovery_info=None):
|
||||
"""Set up the Sharp Aquos TV platform."""
|
||||
|
||||
name = config.get(CONF_NAME)
|
||||
port = config.get(CONF_PORT)
|
||||
username = config.get(CONF_USERNAME)
|
||||
password = config.get(CONF_PASSWORD)
|
||||
power_on_enabled = config.get("power_on_enabled")
|
||||
name = config[CONF_NAME]
|
||||
port = config[CONF_PORT]
|
||||
username = config[CONF_USERNAME]
|
||||
password = config[CONF_PASSWORD]
|
||||
power_on_enabled = config["power_on_enabled"]
|
||||
|
||||
if 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)])
|
||||
return True
|
||||
|
||||
host = config.get(CONF_HOST)
|
||||
host = config[CONF_HOST]
|
||||
remote = sharp_aquos_rc.TV(host, port, username, password, 15, 1)
|
||||
|
||||
add_entities([SharpAquosTVDevice(name, remote, power_on_enabled)])
|
||||
|
@ -26,7 +26,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
||||
"""Set up the Arduino platform."""
|
||||
board = hass.data[DOMAIN]
|
||||
|
||||
pins = config.get(CONF_PINS)
|
||||
pins = config[CONF_PINS]
|
||||
|
||||
sensors = []
|
||||
for pinnum, pin in pins.items():
|
||||
|
@ -33,7 +33,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
||||
"""Set up the Arduino platform."""
|
||||
board = hass.data[DOMAIN]
|
||||
|
||||
pins = config.get(CONF_PINS)
|
||||
pins = config[CONF_PINS]
|
||||
|
||||
switches = []
|
||||
for pinnum, pin in pins.items():
|
||||
@ -47,13 +47,13 @@ class ArduinoSwitch(SwitchDevice):
|
||||
def __init__(self, pin, options, board):
|
||||
"""Initialize the Pin."""
|
||||
self._pin = pin
|
||||
self._name = options.get(CONF_NAME)
|
||||
self._name = options[CONF_NAME]
|
||||
self.pin_type = CONF_TYPE
|
||||
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_off_handler = board.set_digital_out_high
|
||||
else:
|
||||
|
@ -30,8 +30,8 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
||||
|
||||
def setup_platform(hass, config, add_entities, discovery_info=None):
|
||||
"""Set up the aREST binary sensor."""
|
||||
resource = config.get(CONF_RESOURCE)
|
||||
pin = config.get(CONF_PIN)
|
||||
resource = config[CONF_RESOURCE]
|
||||
pin = config[CONF_PIN]
|
||||
device_class = config.get(CONF_DEVICE_CLASS)
|
||||
|
||||
try:
|
||||
|
@ -51,9 +51,9 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
||||
|
||||
def setup_platform(hass, config, add_entities, discovery_info=None):
|
||||
"""Set up the aREST sensor."""
|
||||
resource = config.get(CONF_RESOURCE)
|
||||
var_conf = config.get(CONF_MONITORED_VARIABLES)
|
||||
pins = config.get(CONF_PINS)
|
||||
resource = config[CONF_RESOURCE]
|
||||
var_conf = config[CONF_MONITORED_VARIABLES]
|
||||
pins = config[CONF_PINS]
|
||||
|
||||
try:
|
||||
response = requests.get(resource, timeout=10).json()
|
||||
|
@ -40,7 +40,7 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
||||
|
||||
def setup_platform(hass, config, add_entities, discovery_info=None):
|
||||
"""Set up the aREST switches."""
|
||||
resource = config.get(CONF_RESOURCE)
|
||||
resource = config[CONF_RESOURCE]
|
||||
|
||||
try:
|
||||
response = requests.get(resource, timeout=10)
|
||||
@ -54,7 +54,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
||||
return False
|
||||
|
||||
dev = []
|
||||
pins = config.get(CONF_PINS)
|
||||
pins = config[CONF_PINS]
|
||||
for pinnum, pin in pins.items():
|
||||
dev.append(
|
||||
ArestSwitchPin(
|
||||
@ -62,11 +62,11 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
||||
config.get(CONF_NAME, response.json()[CONF_NAME]),
|
||||
pin.get(CONF_NAME),
|
||||
pinnum,
|
||||
pin.get(CONF_INVERT),
|
||||
pin[CONF_INVERT],
|
||||
)
|
||||
)
|
||||
|
||||
functions = config.get(CONF_FUNCTIONS)
|
||||
functions = config[CONF_FUNCTIONS]
|
||||
for funcname, func in functions.items():
|
||||
dev.append(
|
||||
ArestSwitchFunction(
|
||||
|
@ -43,9 +43,9 @@ CONFIG_SCHEMA = vol.Schema(
|
||||
def setup(hass, config):
|
||||
"""Set up an Arlo component."""
|
||||
conf = config[DOMAIN]
|
||||
username = conf.get(CONF_USERNAME)
|
||||
password = conf.get(CONF_PASSWORD)
|
||||
scan_interval = conf.get(CONF_SCAN_INTERVAL)
|
||||
username = conf[CONF_USERNAME]
|
||||
password = conf[CONF_PASSWORD]
|
||||
scan_interval = conf[CONF_SCAN_INTERVAL]
|
||||
|
||||
try:
|
||||
|
||||
|
@ -53,9 +53,9 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
||||
if not arlo.base_stations:
|
||||
return
|
||||
|
||||
home_mode_name = config.get(CONF_HOME_MODE_NAME)
|
||||
away_mode_name = config.get(CONF_AWAY_MODE_NAME)
|
||||
night_mode_name = config.get(CONF_NIGHT_MODE_NAME)
|
||||
home_mode_name = config[CONF_HOME_MODE_NAME]
|
||||
away_mode_name = config[CONF_AWAY_MODE_NAME]
|
||||
night_mode_name = config[CONF_NIGHT_MODE_NAME]
|
||||
base_stations = []
|
||||
for base_station in arlo.base_stations:
|
||||
base_stations.append(
|
||||
|
@ -51,7 +51,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
||||
return
|
||||
|
||||
sensors = []
|
||||
for sensor_type in config.get(CONF_MONITORED_CONDITIONS):
|
||||
for sensor_type in config[CONF_MONITORED_CONDITIONS]:
|
||||
if sensor_type == "total_cameras":
|
||||
sensors.append(ArloSensor(SENSOR_TYPES[sensor_type][0], arlo, sensor_type))
|
||||
else:
|
||||
|
@ -43,9 +43,9 @@ def setup(hass, config):
|
||||
"""Set up for the Asterisk Voicemail box."""
|
||||
conf = config.get(DOMAIN)
|
||||
|
||||
host = conf.get(CONF_HOST)
|
||||
port = conf.get(CONF_PORT)
|
||||
password = conf.get(CONF_PASSWORD)
|
||||
host = conf[CONF_HOST]
|
||||
port = conf[CONF_PORT]
|
||||
password = conf[CONF_PASSWORD]
|
||||
|
||||
hass.data[DOMAIN] = AsteriskData(hass, host, port, password, config)
|
||||
|
||||
|
@ -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")
|
||||
return False
|
||||
|
||||
name = config.get(CONF_NAME)
|
||||
threshold = config.get(CONF_THRESHOLD)
|
||||
name = config[CONF_NAME]
|
||||
threshold = config[CONF_THRESHOLD]
|
||||
|
||||
try:
|
||||
aurora_data = AuroraData(hass.config.latitude, hass.config.longitude, threshold)
|
||||
|
@ -63,21 +63,21 @@ class BaiduTTSProvider(Provider):
|
||||
def __init__(self, hass, conf):
|
||||
"""Init Baidu TTS service."""
|
||||
self.hass = hass
|
||||
self._lang = conf.get(CONF_LANG)
|
||||
self._lang = conf[CONF_LANG]
|
||||
self._codec = "mp3"
|
||||
self.name = "BaiduTTS"
|
||||
|
||||
self._app_data = {
|
||||
"appid": conf.get(CONF_APP_ID),
|
||||
"apikey": conf.get(CONF_API_KEY),
|
||||
"secretkey": conf.get(CONF_SECRET_KEY),
|
||||
"appid": conf[CONF_APP_ID],
|
||||
"apikey": conf[CONF_API_KEY],
|
||||
"secretkey": conf[CONF_SECRET_KEY],
|
||||
}
|
||||
|
||||
self._speech_conf_data = {
|
||||
_OPTIONS[CONF_PERSON]: conf.get(CONF_PERSON),
|
||||
_OPTIONS[CONF_PITCH]: conf.get(CONF_PITCH),
|
||||
_OPTIONS[CONF_SPEED]: conf.get(CONF_SPEED),
|
||||
_OPTIONS[CONF_VOLUME]: conf.get(CONF_VOLUME),
|
||||
_OPTIONS[CONF_PERSON]: conf[CONF_PERSON],
|
||||
_OPTIONS[CONF_PITCH]: conf[CONF_PITCH],
|
||||
_OPTIONS[CONF_SPEED]: conf[CONF_SPEED],
|
||||
_OPTIONS[CONF_VOLUME]: conf[CONF_VOLUME],
|
||||
}
|
||||
|
||||
@property
|
||||
|
@ -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):
|
||||
"""Set up the Bayesian Binary sensor."""
|
||||
name = config.get(CONF_NAME)
|
||||
observations = config.get(CONF_OBSERVATIONS)
|
||||
prior = config.get(CONF_PRIOR)
|
||||
probability_threshold = config.get(CONF_PROBABILITY_THRESHOLD)
|
||||
name = config[CONF_NAME]
|
||||
observations = config[CONF_OBSERVATIONS]
|
||||
prior = config[CONF_PRIOR]
|
||||
probability_threshold = config[CONF_PROBABILITY_THRESHOLD]
|
||||
device_class = config.get(CONF_DEVICE_CLASS)
|
||||
|
||||
async_add_entities(
|
||||
|
Loading…
x
Reference in New Issue
Block a user