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