Enable even more SIM ruff rules (#113017)
* SIM202 SIM211 SIM220 SIM221 SIM222 SIM223 * SIM910 SIM911 * SIM * Update homeassistant/components/mqtt/siren.py Co-authored-by: Jan Bouwhuis <jbouwh@users.noreply.github.com> * Update homeassistant/components/mqtt/siren.py Co-authored-by: Jan Bouwhuis <jbouwh@users.noreply.github.com> --------- Co-authored-by: Jan Bouwhuis <jbouwh@users.noreply.github.com>pull/113006/head^2
parent
48cb09a4a8
commit
2792a5f016
|
@ -102,13 +102,9 @@ class BloomSkySensor(SensorEntity):
|
|||
self._attr_name = f"{device['DeviceName']} {sensor_name}"
|
||||
self._attr_unique_id = f"{self._device_id}-{sensor_name}"
|
||||
self._attr_device_class = SENSOR_DEVICE_CLASS.get(sensor_name)
|
||||
self._attr_native_unit_of_measurement = SENSOR_UNITS_IMPERIAL.get(
|
||||
sensor_name, None
|
||||
)
|
||||
self._attr_native_unit_of_measurement = SENSOR_UNITS_IMPERIAL.get(sensor_name)
|
||||
if self._bloomsky.is_metric:
|
||||
self._attr_native_unit_of_measurement = SENSOR_UNITS_METRIC.get(
|
||||
sensor_name, None
|
||||
)
|
||||
self._attr_native_unit_of_measurement = SENSOR_UNITS_METRIC.get(sensor_name)
|
||||
|
||||
def update(self) -> None:
|
||||
"""Request an update from the BloomSky API."""
|
||||
|
|
|
@ -62,7 +62,7 @@ def infrared_brightness_value_to_option(value: int) -> str | None:
|
|||
def infrared_brightness_option_to_value(option: str) -> int | None:
|
||||
"""Convert infrared brightness option to value."""
|
||||
option_values = {v: k for k, v in INFRARED_BRIGHTNESS_VALUES_MAP.items()}
|
||||
return option_values.get(option, None)
|
||||
return option_values.get(option)
|
||||
|
||||
|
||||
def convert_8_to_16(value: int) -> int:
|
||||
|
|
|
@ -166,7 +166,7 @@ async def websocket_commission_on_network(
|
|||
) -> None:
|
||||
"""Commission a device already on the network."""
|
||||
await matter.matter_client.commission_on_network(
|
||||
msg["pin"], ip_addr=msg.get("ip_addr", None)
|
||||
msg["pin"], ip_addr=msg.get("ip_addr")
|
||||
)
|
||||
connection.send_result(msg[ID])
|
||||
|
||||
|
|
|
@ -102,7 +102,7 @@ class BasePlatform(Entity):
|
|||
)
|
||||
|
||||
self._hub = hub
|
||||
self._slave = entry.get(CONF_SLAVE, None) or entry.get(CONF_DEVICE_ADDRESS, 0)
|
||||
self._slave = entry.get(CONF_SLAVE) or entry.get(CONF_DEVICE_ADDRESS, 0)
|
||||
self._address = int(entry[CONF_ADDRESS])
|
||||
self._input_type = entry[CONF_INPUT_TYPE]
|
||||
self._value: str | None = None
|
||||
|
@ -128,7 +128,7 @@ class BasePlatform(Entity):
|
|||
|
||||
self._min_value = get_optional_numeric_config(CONF_MIN_VALUE)
|
||||
self._max_value = get_optional_numeric_config(CONF_MAX_VALUE)
|
||||
self._nan_value = entry.get(CONF_NAN_VALUE, None)
|
||||
self._nan_value = entry.get(CONF_NAN_VALUE)
|
||||
self._zero_suppress = get_optional_numeric_config(CONF_ZERO_SUPPRESS)
|
||||
|
||||
@abstractmethod
|
||||
|
@ -184,7 +184,7 @@ class BaseStructPlatform(BasePlatform, RestoreEntity):
|
|||
self._structure: str = config[CONF_STRUCTURE]
|
||||
self._scale = config[CONF_SCALE]
|
||||
self._offset = config[CONF_OFFSET]
|
||||
self._slave_count = config.get(CONF_SLAVE_COUNT, None) or config.get(
|
||||
self._slave_count = config.get(CONF_SLAVE_COUNT) or config.get(
|
||||
CONF_VIRTUAL_COUNT, 0
|
||||
)
|
||||
self._slave_size = self._count = config[CONF_COUNT]
|
||||
|
|
|
@ -118,8 +118,8 @@ def struct_validator(config: dict[str, Any]) -> dict[str, Any]:
|
|||
data_type = config[CONF_DATA_TYPE]
|
||||
if data_type == "int":
|
||||
data_type = config[CONF_DATA_TYPE] = DataType.INT16
|
||||
count = config.get(CONF_COUNT, None)
|
||||
structure = config.get(CONF_STRUCTURE, None)
|
||||
count = config.get(CONF_COUNT)
|
||||
structure = config.get(CONF_STRUCTURE)
|
||||
slave_count = config.get(CONF_SLAVE_COUNT, config.get(CONF_VIRTUAL_COUNT))
|
||||
validator = DEFAULT_STRUCT_FORMAT[data_type].validate_parm
|
||||
swap_type = config.get(CONF_SWAP)
|
||||
|
@ -148,6 +148,8 @@ def struct_validator(config: dict[str, Any]) -> dict[str, Any]:
|
|||
raise vol.Invalid(error)
|
||||
|
||||
if config[CONF_DATA_TYPE] == DataType.CUSTOM:
|
||||
assert isinstance(structure, str)
|
||||
assert isinstance(count, int)
|
||||
try:
|
||||
size = struct.calcsize(structure)
|
||||
except struct.error as err:
|
||||
|
@ -332,7 +334,7 @@ def check_config(config: dict) -> dict:
|
|||
):
|
||||
if conf_type in entity:
|
||||
addr += f"_{entity[conf_type]}"
|
||||
inx = entity.get(CONF_SLAVE, None) or entity.get(CONF_DEVICE_ADDRESS, 0)
|
||||
inx = entity.get(CONF_SLAVE) or entity.get(CONF_DEVICE_ADDRESS, 0)
|
||||
addr += f"_{inx}"
|
||||
loc_addr: set[str] = {addr}
|
||||
|
||||
|
|
|
@ -301,10 +301,7 @@ class MqttSiren(MqttEntity, SirenEntity):
|
|||
else {}
|
||||
)
|
||||
if extra_attributes:
|
||||
return (
|
||||
dict({*self._extra_attributes.items(), *extra_attributes.items()})
|
||||
or None
|
||||
)
|
||||
return dict({*self._extra_attributes.items(), *extra_attributes.items()})
|
||||
return self._extra_attributes or None
|
||||
|
||||
async def _async_publish(
|
||||
|
|
|
@ -87,7 +87,7 @@ def washer_state(washer: WasherDryer) -> str | None:
|
|||
if func(washer):
|
||||
return cycle_name
|
||||
|
||||
return MACHINE_STATE.get(machine_state, None)
|
||||
return MACHINE_STATE.get(machine_state)
|
||||
|
||||
|
||||
@dataclass(frozen=True, kw_only=True)
|
||||
|
|
|
@ -119,7 +119,7 @@ def cvt_volume(val: int | None) -> str | None:
|
|||
if val is None:
|
||||
return None
|
||||
volume_level = {1: "low", 2: "medium", 3: "high"}
|
||||
return volume_level.get(val, None)
|
||||
return volume_level.get(val)
|
||||
|
||||
|
||||
SENSOR_TYPES: tuple[YoLinkSensorEntityDescription, ...] = (
|
||||
|
|
|
@ -627,23 +627,7 @@ select = [
|
|||
"S604", # call-with-shell-equals-true
|
||||
"S608", # hardcoded-sql-expression
|
||||
"S609", # unix-command-wildcard-injection
|
||||
"SIM101", # Multiple isinstance calls for {name}, merge into a single call
|
||||
"SIM103", # Return the condition {condition} directly
|
||||
"SIM105", # Use contextlib.suppress({exception}) instead of try-except-pass
|
||||
"SIM107", # Don't use return in try-except and finally
|
||||
"SIM109", # Use {replacement} instead of multiple equality comparisons
|
||||
"SIM110", # Use {replacement} instead of for loop
|
||||
"SIM112", # Use capitalized environment variable {expected} instead of {actual}
|
||||
"SIM113", # Use enumerate() for index variable {index} in for loop
|
||||
"SIM114", # Combine if branches using logical or operator
|
||||
"SIM116", # Use a dictionary instead of consecutive if statements
|
||||
"SIM117", # Merge with-statements that use the same scope
|
||||
"SIM118", # Use {key} in {dict} instead of {key} in {dict}.keys()
|
||||
"SIM201", # Use {left} != {right} instead of not {left} == {right}
|
||||
"SIM208", # Use {expr} instead of not (not {expr})
|
||||
"SIM212", # Use {a} if {a} else {b} instead of {b} if not {a} else {a}
|
||||
"SIM300", # Yoda conditions. Use 'age == 42' instead of '42 == age'.
|
||||
"SIM401", # Use get from dict with default instead of an if block
|
||||
"SIM", # flake8-simplify
|
||||
"T100", # Trace found: {name} used
|
||||
"T20", # flake8-print
|
||||
"TID251", # Banned imports
|
||||
|
@ -675,6 +659,9 @@ ignore = [
|
|||
"PLR0915", # Too many statements ({statements} > {max_statements})
|
||||
"PLR2004", # Magic value used in comparison, consider replacing {value} with a constant variable
|
||||
"PLW2901", # Outer {outer_kind} variable {name} overwritten by inner {inner_kind} target
|
||||
"SIM102", # Use a single if statement instead of nested if statements
|
||||
"SIM108", # Use ternary operator {contents} instead of if-else-block
|
||||
"SIM115", # Use context handler for opening files
|
||||
"UP006", # keep type annotation style as is
|
||||
"UP007", # keep type annotation style as is
|
||||
# Ignored due to performance: https://github.com/charliermarsh/ruff/issues/2923
|
||||
|
|
|
@ -283,7 +283,7 @@ class MockBridge:
|
|||
:param domain: one of 'light', 'switch', 'cover', 'fan' or 'sensor'
|
||||
:returns list of zero or more of the devices
|
||||
"""
|
||||
types = _LEAP_DEVICE_TYPES.get(domain, None)
|
||||
types = _LEAP_DEVICE_TYPES.get(domain)
|
||||
|
||||
# return immediately if not a supported domain
|
||||
if types is None:
|
||||
|
|
Loading…
Reference in New Issue