mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
Clean up access to config in various integrations v3 (#33842)
This commit is contained in:
parent
b46eee04e4
commit
21dfee831f
@ -35,7 +35,7 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
||||
|
||||
def setup_platform(hass, config, add_entities, discovery_info=None):
|
||||
"""Set up the Beaglebone Black GPIO devices."""
|
||||
pins = config.get(CONF_PINS)
|
||||
pins = config[CONF_PINS]
|
||||
|
||||
binary_sensors = []
|
||||
|
||||
@ -50,10 +50,10 @@ class BBBGPIOBinarySensor(BinarySensorDevice):
|
||||
def __init__(self, pin, params):
|
||||
"""Initialize the Beaglebone Black binary sensor."""
|
||||
self._pin = pin
|
||||
self._name = params.get(CONF_NAME) or DEVICE_DEFAULT_NAME
|
||||
self._bouncetime = params.get(CONF_BOUNCETIME)
|
||||
self._pull_mode = params.get(CONF_PULL_MODE)
|
||||
self._invert_logic = params.get(CONF_INVERT_LOGIC)
|
||||
self._name = params[CONF_NAME] or DEVICE_DEFAULT_NAME
|
||||
self._bouncetime = params[CONF_BOUNCETIME]
|
||||
self._pull_mode = params[CONF_PULL_MODE]
|
||||
self._invert_logic = params[CONF_INVERT_LOGIC]
|
||||
|
||||
bbb_gpio.setup_input(self._pin, self._pull_mode)
|
||||
self._state = bbb_gpio.read_input(self._pin)
|
||||
|
@ -30,7 +30,7 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
||||
|
||||
def setup_platform(hass, config, add_entities, discovery_info=None):
|
||||
"""Set up the BeagleBone Black GPIO devices."""
|
||||
pins = config.get(CONF_PINS)
|
||||
pins = config[CONF_PINS]
|
||||
|
||||
switches = []
|
||||
for pin, params in pins.items():
|
||||
@ -44,9 +44,9 @@ class BBBGPIOSwitch(ToggleEntity):
|
||||
def __init__(self, pin, params):
|
||||
"""Initialize the pin."""
|
||||
self._pin = pin
|
||||
self._name = params.get(CONF_NAME) or DEVICE_DEFAULT_NAME
|
||||
self._state = params.get(CONF_INITIAL)
|
||||
self._invert_logic = params.get(CONF_INVERT_LOGIC)
|
||||
self._name = params[CONF_NAME] or DEVICE_DEFAULT_NAME
|
||||
self._state = params[CONF_INITIAL]
|
||||
self._invert_logic = params[CONF_INVERT_LOGIC]
|
||||
|
||||
bbb_gpio.setup_output(self._pin)
|
||||
|
||||
|
@ -74,7 +74,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
||||
_LOGGER.error(error)
|
||||
return False
|
||||
|
||||
name = config.get(CONF_NAME)
|
||||
name = config[CONF_NAME]
|
||||
|
||||
sensors = []
|
||||
for variable in config[CONF_MONITORED_VARIABLES]:
|
||||
|
@ -63,10 +63,10 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
||||
async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
|
||||
"""Set up the BH1750 sensor."""
|
||||
|
||||
name = config.get(CONF_NAME)
|
||||
bus_number = config.get(CONF_I2C_BUS)
|
||||
i2c_address = config.get(CONF_I2C_ADDRESS)
|
||||
operation_mode = config.get(CONF_OPERATION_MODE)
|
||||
name = config[CONF_NAME]
|
||||
bus_number = config[CONF_I2C_BUS]
|
||||
i2c_address = config[CONF_I2C_ADDRESS]
|
||||
operation_mode = config[CONF_OPERATION_MODE]
|
||||
|
||||
bus = smbus.SMBus(bus_number)
|
||||
|
||||
@ -76,8 +76,8 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
|
||||
bus,
|
||||
i2c_address,
|
||||
operation_mode=operation_mode,
|
||||
measurement_delay=config.get(CONF_DELAY),
|
||||
sensitivity=config.get(CONF_SENSITIVITY),
|
||||
measurement_delay=config[CONF_DELAY],
|
||||
sensitivity=config[CONF_SENSITIVITY],
|
||||
logger=_LOGGER,
|
||||
)
|
||||
)
|
||||
@ -85,7 +85,7 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
|
||||
_LOGGER.error("BH1750 sensor not detected at %s", i2c_address)
|
||||
return False
|
||||
|
||||
dev = [BH1750Sensor(sensor, name, SENSOR_UNIT, config.get(CONF_MULTIPLIER))]
|
||||
dev = [BH1750Sensor(sensor, name, SENSOR_UNIT, config[CONF_MULTIPLIER])]
|
||||
_LOGGER.info(
|
||||
"Setup of BH1750 light sensor at %s in mode %s is complete",
|
||||
i2c_address,
|
||||
|
@ -63,7 +63,7 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
||||
def setup_platform(hass, config, add_entities, discovery_info=None):
|
||||
"""Set up the Bitcoin sensors."""
|
||||
|
||||
currency = config.get(CONF_CURRENCY)
|
||||
currency = config[CONF_CURRENCY]
|
||||
|
||||
if currency not in exchangerates.get_ticker():
|
||||
_LOGGER.warning("Currency %s is not available. Using USD", currency)
|
||||
|
@ -30,7 +30,7 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
||||
|
||||
def setup_platform(hass, config, add_entities, discovery_info=None):
|
||||
"""Set up the Bizkaibus public transport sensor."""
|
||||
name = config.get(CONF_NAME)
|
||||
name = config[CONF_NAME]
|
||||
stop = config[CONF_STOP_ID]
|
||||
route = config[CONF_ROUTE]
|
||||
|
||||
|
@ -35,8 +35,8 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
||||
def setup_platform(hass, config, add_entities, discovery_info=None):
|
||||
"""Set up Blinkstick device specified by serial number."""
|
||||
|
||||
name = config.get(CONF_NAME)
|
||||
serial = config.get(CONF_SERIAL)
|
||||
name = config[CONF_NAME]
|
||||
serial = config[CONF_SERIAL]
|
||||
|
||||
stick = blinkstick.find_by_serial(serial)
|
||||
|
||||
|
@ -35,7 +35,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
||||
# ensure that the lights are off when exiting
|
||||
blinkt.set_clear_on_exit()
|
||||
|
||||
name = config.get(CONF_NAME)
|
||||
name = config[CONF_NAME]
|
||||
|
||||
add_entities(
|
||||
[BlinktLight(blinkt, name, index) for index in range(blinkt.NUM_PIXELS)]
|
||||
|
@ -33,8 +33,8 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
||||
def setup_platform(hass, config, add_entities, discovery_info=None):
|
||||
"""Set up the Blockchain.com sensors."""
|
||||
|
||||
addresses = config.get(CONF_ADDRESSES)
|
||||
name = config.get(CONF_NAME)
|
||||
addresses = config[CONF_ADDRESSES]
|
||||
name = config[CONF_NAME]
|
||||
|
||||
for address in addresses:
|
||||
if not validate_address(address):
|
||||
|
@ -25,7 +25,7 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
||||
def setup_platform(hass, config, add_entities, discovery_info=None):
|
||||
"""Set up the available BloomSky weather binary sensors."""
|
||||
# Default needed in case of discovery
|
||||
sensors = config.get(CONF_MONITORED_CONDITIONS, SENSOR_TYPES)
|
||||
sensors = config[CONF_MONITORED_CONDITIONS]
|
||||
bloomsky = hass.data[DOMAIN]
|
||||
|
||||
for device in bloomsky.devices.values():
|
||||
|
@ -60,7 +60,7 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
||||
def setup_platform(hass, config, add_entities, discovery_info=None):
|
||||
"""Set up the available BloomSky weather sensors."""
|
||||
# Default needed in case of discovery
|
||||
sensors = config.get(CONF_MONITORED_CONDITIONS, SENSOR_TYPES)
|
||||
sensors = config[CONF_MONITORED_CONDITIONS]
|
||||
bloomsky = hass.data[DOMAIN]
|
||||
|
||||
for device in bloomsky.devices.values():
|
||||
|
@ -112,7 +112,7 @@ async def async_setup_scanner(
|
||||
hass: HomeAssistantType, config: dict, async_see, discovery_info=None
|
||||
):
|
||||
"""Set up the Bluetooth Scanner."""
|
||||
device_id: int = config.get(CONF_DEVICE_ID)
|
||||
device_id: int = config[CONF_DEVICE_ID]
|
||||
interval = config.get(CONF_SCAN_INTERVAL, SCAN_INTERVAL)
|
||||
request_rssi = config.get(CONF_REQUEST_RSSI, False)
|
||||
update_bluetooth_lock = asyncio.Lock()
|
||||
|
@ -85,22 +85,22 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
|
||||
"""Set up the BME280 sensor."""
|
||||
|
||||
SENSOR_TYPES[SENSOR_TEMP][1] = hass.config.units.temperature_unit
|
||||
name = config.get(CONF_NAME)
|
||||
i2c_address = config.get(CONF_I2C_ADDRESS)
|
||||
name = config[CONF_NAME]
|
||||
i2c_address = config[CONF_I2C_ADDRESS]
|
||||
|
||||
bus = smbus.SMBus(config.get(CONF_I2C_BUS))
|
||||
bus = smbus.SMBus(config[CONF_I2C_BUS])
|
||||
sensor = await hass.async_add_job(
|
||||
partial(
|
||||
BME280,
|
||||
bus,
|
||||
i2c_address,
|
||||
osrs_t=config.get(CONF_OVERSAMPLING_TEMP),
|
||||
osrs_p=config.get(CONF_OVERSAMPLING_PRES),
|
||||
osrs_h=config.get(CONF_OVERSAMPLING_HUM),
|
||||
mode=config.get(CONF_OPERATION_MODE),
|
||||
t_sb=config.get(CONF_T_STANDBY),
|
||||
filter_mode=config.get(CONF_FILTER_MODE),
|
||||
delta_temp=config.get(CONF_DELTA_TEMP),
|
||||
osrs_t=config[CONF_OVERSAMPLING_TEMP],
|
||||
osrs_p=config[CONF_OVERSAMPLING_PRES],
|
||||
osrs_h=config[CONF_OVERSAMPLING_HUM],
|
||||
mode=config[CONF_OPERATION_MODE],
|
||||
t_sb=config[CONF_T_STANDBY],
|
||||
filter_mode=config[CONF_FILTER_MODE],
|
||||
delta_temp=config[CONF_DELTA_TEMP],
|
||||
logger=_LOGGER,
|
||||
)
|
||||
)
|
||||
|
@ -109,7 +109,7 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
||||
async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
|
||||
"""Set up the BME680 sensor."""
|
||||
SENSOR_TYPES[SENSOR_TEMP][1] = hass.config.units.temperature_unit
|
||||
name = config.get(CONF_NAME)
|
||||
name = config[CONF_NAME]
|
||||
|
||||
sensor_handler = await hass.async_add_job(_setup_bme680, config)
|
||||
if sensor_handler is None:
|
||||
@ -132,8 +132,8 @@ def _setup_bme680(config):
|
||||
sensor = None
|
||||
try:
|
||||
# pylint: disable=no-member
|
||||
i2c_address = config.get(CONF_I2C_ADDRESS)
|
||||
bus = SMBus(config.get(CONF_I2C_BUS))
|
||||
i2c_address = config[CONF_I2C_ADDRESS]
|
||||
bus = SMBus(config[CONF_I2C_BUS])
|
||||
sensor = bme680.BME680(i2c_address, bus)
|
||||
|
||||
# Configure Oversampling
|
||||
@ -145,10 +145,10 @@ def _setup_bme680(config):
|
||||
8: bme680.OS_8X,
|
||||
16: bme680.OS_16X,
|
||||
}
|
||||
sensor.set_temperature_oversample(os_lookup[config.get(CONF_OVERSAMPLING_TEMP)])
|
||||
sensor.set_temp_offset(config.get(CONF_TEMP_OFFSET))
|
||||
sensor.set_humidity_oversample(os_lookup[config.get(CONF_OVERSAMPLING_HUM)])
|
||||
sensor.set_pressure_oversample(os_lookup[config.get(CONF_OVERSAMPLING_PRES)])
|
||||
sensor.set_temperature_oversample(os_lookup[config[CONF_OVERSAMPLING_TEMP]])
|
||||
sensor.set_temp_offset(config[CONF_TEMP_OFFSET])
|
||||
sensor.set_humidity_oversample(os_lookup[config[CONF_OVERSAMPLING_HUM]])
|
||||
sensor.set_pressure_oversample(os_lookup[config[CONF_OVERSAMPLING_PRES]])
|
||||
|
||||
# Configure IIR Filter
|
||||
filter_lookup = {
|
||||
@ -161,7 +161,7 @@ def _setup_bme680(config):
|
||||
63: bme680.FILTER_SIZE_63,
|
||||
127: bme680.FILTER_SIZE_127,
|
||||
}
|
||||
sensor.set_filter(filter_lookup[config.get(CONF_FILTER_SIZE)])
|
||||
sensor.set_filter(filter_lookup[config[CONF_FILTER_SIZE]])
|
||||
|
||||
# Configure the Gas Heater
|
||||
if (
|
||||
|
@ -61,7 +61,7 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
||||
|
||||
def setup_platform(hass, config, add_entities, discovery_info=None):
|
||||
"""Set up the Sony Bravia TV platform."""
|
||||
host = config.get(CONF_HOST)
|
||||
host = config[CONF_HOST]
|
||||
|
||||
if host is None:
|
||||
return
|
||||
@ -74,7 +74,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
||||
if host_ip == host:
|
||||
pin = host_config["pin"]
|
||||
mac = host_config["mac"]
|
||||
name = config.get(CONF_NAME)
|
||||
name = config[CONF_NAME]
|
||||
braviarc = BraviaRC(host, mac)
|
||||
if not braviarc.connect(pin, CLIENTID_PREFIX, NICKNAME):
|
||||
raise PlatformNotReady
|
||||
@ -91,8 +91,8 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
||||
|
||||
def setup_bravia(config, pin, hass, add_entities):
|
||||
"""Set up a Sony Bravia TV based on host parameter."""
|
||||
host = config.get(CONF_HOST)
|
||||
name = config.get(CONF_NAME)
|
||||
host = config[CONF_HOST]
|
||||
name = config[CONF_NAME]
|
||||
|
||||
if pin is None:
|
||||
request_configuration(config, hass, add_entities)
|
||||
@ -128,8 +128,8 @@ def setup_bravia(config, pin, hass, add_entities):
|
||||
|
||||
def request_configuration(config, hass, add_entities):
|
||||
"""Request configuration steps from the user."""
|
||||
host = config.get(CONF_HOST)
|
||||
name = config.get(CONF_NAME)
|
||||
host = config[CONF_HOST]
|
||||
name = config[CONF_NAME]
|
||||
|
||||
configurator = hass.components.configurator
|
||||
|
||||
|
@ -65,7 +65,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
||||
area = config.get(CONF_AREA)
|
||||
latitude = config.get(CONF_LATITUDE, hass.config.latitude)
|
||||
longitude = config.get(CONF_LONGITUDE, hass.config.longitude)
|
||||
name = config.get(CONF_NAME)
|
||||
name = config[CONF_NAME]
|
||||
|
||||
# Every Home Assistant instance should have their own unique
|
||||
# app parameter: https://brottsplatskartan.se/sida/api
|
||||
|
Loading…
x
Reference in New Issue
Block a user