Type check KNX integration factory and schema (#48045)

these are used non-optional anyway
get them per config[] notation
This commit is contained in:
Matthias Alphart 2021-03-19 10:23:50 +01:00 committed by GitHub
parent e522b311ce
commit 66b537c0e3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 8 deletions

View file

@ -264,9 +264,9 @@ def _create_climate(knx_module: XKNX, config: ConfigType) -> XknxClimate:
max_temp=config.get(ClimateSchema.CONF_MAX_TEMP), max_temp=config.get(ClimateSchema.CONF_MAX_TEMP),
mode=climate_mode, mode=climate_mode,
on_off_invert=config[ClimateSchema.CONF_ON_OFF_INVERT], on_off_invert=config[ClimateSchema.CONF_ON_OFF_INVERT],
create_temperature_sensors=config.get( create_temperature_sensors=config[
ClimateSchema.CONF_CREATE_TEMPERATURE_SENSORS ClimateSchema.CONF_CREATE_TEMPERATURE_SENSORS
), ],
) )
@ -277,7 +277,7 @@ def _create_switch(knx_module: XKNX, config: ConfigType) -> XknxSwitch:
name=config[CONF_NAME], name=config[CONF_NAME],
group_address=config[KNX_ADDRESS], group_address=config[KNX_ADDRESS],
group_address_state=config.get(SwitchSchema.CONF_STATE_ADDRESS), group_address_state=config.get(SwitchSchema.CONF_STATE_ADDRESS),
invert=config.get(SwitchSchema.CONF_INVERT), invert=config[SwitchSchema.CONF_INVERT],
) )
@ -320,7 +320,7 @@ def _create_binary_sensor(knx_module: XKNX, config: ConfigType) -> XknxBinarySen
knx_module, knx_module,
name=device_name, name=device_name,
group_address_state=config[BinarySensorSchema.CONF_STATE_ADDRESS], group_address_state=config[BinarySensorSchema.CONF_STATE_ADDRESS],
invert=config.get(BinarySensorSchema.CONF_INVERT), invert=config[BinarySensorSchema.CONF_INVERT],
sync_state=config[BinarySensorSchema.CONF_SYNC_STATE], sync_state=config[BinarySensorSchema.CONF_SYNC_STATE],
device_class=config.get(CONF_DEVICE_CLASS), device_class=config.get(CONF_DEVICE_CLASS),
ignore_internal_state=config[BinarySensorSchema.CONF_IGNORE_INTERNAL_STATE], ignore_internal_state=config[BinarySensorSchema.CONF_IGNORE_INTERNAL_STATE],

View file

@ -30,13 +30,13 @@ from .const import (
################## ##################
ga_validator = vol.Any( ga_validator = vol.Any(
cv.matches_regex(GroupAddress.ADDRESS_RE), cv.matches_regex(GroupAddress.ADDRESS_RE.pattern),
vol.All(vol.Coerce(int), vol.Range(min=1, max=65535)), vol.All(vol.Coerce(int), vol.Range(min=1, max=65535)),
msg="value does not match pattern for KNX group address '<main>/<middle>/<sub>', '<main>/<sub>' or '<free>' (eg.'1/2/3', '9/234', '123')", msg="value does not match pattern for KNX group address '<main>/<middle>/<sub>', '<main>/<sub>' or '<free>' (eg.'1/2/3', '9/234', '123')",
) )
ia_validator = vol.Any( ia_validator = vol.Any(
cv.matches_regex(IndividualAddress.ADDRESS_RE), cv.matches_regex(IndividualAddress.ADDRESS_RE.pattern),
vol.All(vol.Coerce(int), vol.Range(min=1, max=65535)), vol.All(vol.Coerce(int), vol.Range(min=1, max=65535)),
msg="value does not match pattern for KNX individual address '<area>.<line>.<device>' (eg.'1.1.100')", msg="value does not match pattern for KNX individual address '<area>.<line>.<device>' (eg.'1.1.100')",
) )
@ -96,12 +96,12 @@ class BinarySensorSchema:
vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string, vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
vol.Optional(CONF_SYNC_STATE, default=True): sync_state_validator, vol.Optional(CONF_SYNC_STATE, default=True): sync_state_validator,
vol.Optional(CONF_IGNORE_INTERNAL_STATE, default=False): cv.boolean, vol.Optional(CONF_IGNORE_INTERNAL_STATE, default=False): cv.boolean,
vol.Optional(CONF_INVERT, default=False): cv.boolean,
vol.Required(CONF_STATE_ADDRESS): ga_validator, vol.Required(CONF_STATE_ADDRESS): ga_validator,
vol.Optional(CONF_CONTEXT_TIMEOUT): vol.All( vol.Optional(CONF_CONTEXT_TIMEOUT): vol.All(
vol.Coerce(float), vol.Range(min=0, max=10) vol.Coerce(float), vol.Range(min=0, max=10)
), ),
vol.Optional(CONF_DEVICE_CLASS): cv.string, vol.Optional(CONF_DEVICE_CLASS): cv.string,
vol.Optional(CONF_INVERT): cv.boolean,
vol.Optional(CONF_RESET_AFTER): cv.positive_float, vol.Optional(CONF_RESET_AFTER): cv.positive_float,
} }
), ),
@ -448,9 +448,9 @@ class SwitchSchema:
SCHEMA = vol.Schema( SCHEMA = vol.Schema(
{ {
vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string, vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
vol.Optional(CONF_INVERT, default=False): cv.boolean,
vol.Required(KNX_ADDRESS): ga_validator, vol.Required(KNX_ADDRESS): ga_validator,
vol.Optional(CONF_STATE_ADDRESS): ga_validator, vol.Optional(CONF_STATE_ADDRESS): ga_validator,
vol.Optional(CONF_INVERT): cv.boolean,
} }
) )