Skip to content

Commit

Permalink
Update Ruff configuration (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
dmulcahey authored Mar 29, 2024
1 parent 5f7c2ec commit b5f068a
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 33 deletions.
23 changes: 9 additions & 14 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -145,20 +145,11 @@ select = [
"S604", # call-with-shell-equals-true
"S608", # hardcoded-sql-expression
"S609", # unix-command-wildcard-injection
"SIM105", # Use contextlib.suppress({exception}) instead of try-except-pass
"SIM114", # Combine if branches using logical or operator
"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
"TRY004", # Prefer TypeError exception for invalid type
"TRY302", # Remove exception handler; error is immediately re-raised
"TRY", # tryceratops
"UP", # pyupgrade
"W", # pycodestyle
]
Expand Down Expand Up @@ -190,6 +181,9 @@ ignore = [
# Ignored due to performance: https://github.com/charliermarsh/ruff/issues/2923
"UP038", # Use `X | Y` in `isinstance` call instead of `(X, Y)`

# Ignored due to incompatible with mypy: https://github.com/python/mypy/issues/15238
"UP040", # Checks for use of TypeAlias annotation for declaring type aliases.

# May conflict with the formatter, https://docs.astral.sh/ruff/formatter/#conflicting-lint-rules
"W191",
"E111",
Expand All @@ -198,16 +192,17 @@ ignore = [
"D206",
"D300",
"Q000",
"Q001",
"Q002",
"Q003",
"Q",
"COM812",
"COM819",
"ISC001",
"ISC002",

# Disabled because ruff does not understand type of __all__ generated by a function
"PLE0605",
"TRY003",
"TRY201",
"TRY300",
]

[tool.ruff.lint.flake8-pytest-style]
Expand Down
6 changes: 1 addition & 5 deletions tests/test_climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,11 +197,7 @@ def device_climate_mock(
"""Test regular thermostat device."""

async def _dev(clusters, plug=None, manuf=None, quirk=None):
if plug is None:
plugged_attrs = ZCL_ATTR_PLUG
else:
plugged_attrs = {**ZCL_ATTR_PLUG, **plug}

plugged_attrs = ZCL_ATTR_PLUG if plug is None else {**ZCL_ATTR_PLUG, **plug}
zigpy_device = zigpy_device_mock(clusters, manufacturer=manuf, quirk=quirk)
zigpy_device.node_desc.mac_capability_flags |= 0b_0000_0100
zigpy_device.endpoints[1].thermostat.PLUGGED_ATTR_READS = plugged_attrs
Expand Down
9 changes: 3 additions & 6 deletions zha/application/platforms/climate/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,12 +333,12 @@ async def handle_cluster_handler_attribute_updated(
if (
event.attribute_name in (ATTR_OCCP_COOL_SETPT, ATTR_OCCP_HEAT_SETPT)
and self.preset_mode == Preset.AWAY
and await self._thermostat_cluster_handler.get_occupancy() is True
):
# occupancy attribute is an unreportable attribute, but if we get
# an attribute update for an "occupied" setpoint, there's a chance
# occupancy has changed
if await self._thermostat_cluster_handler.get_occupancy() is True:
self._preset = Preset.NONE
self._preset = Preset.NONE

self.debug(
"Attribute '%s' = %s update", event.attribute_name, event.attribute_value
Expand All @@ -351,10 +351,7 @@ async def async_set_fan_mode(self, fan_mode: str) -> None:
self.warning("Unsupported '%s' fan mode", fan_mode)
return

if fan_mode == FAN_ON:
mode = FanMode.On
else:
mode = FanMode.Auto
mode = FanMode.On if fan_mode == FAN_ON else FanMode.Auto

await self._fan_cluster_handler.async_set_speed(mode)

Expand Down
12 changes: 6 additions & 6 deletions zha/application/platforms/light/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,9 +357,12 @@ def color_xy_brightness_to_RGB(
b = X * 0.051713 - Y * 0.121364 + Z * 1.011530

# Apply reverse gamma correction.
r, g, b = ((12.92 * x)
r, g, b = (
(12.92 * x)
if (x <= 0.0031308)
else ((1.0 + 0.055) * cast(float, pow(x, (1.0 / 2.4))) - 0.055) for x in [r, g, b])
else ((1.0 + 0.055) * cast(float, pow(x, (1.0 / 2.4))) - 0.055)
for x in [r, g, b]
)

# Bring all negative components to zero.
r, g, b = (max(0, x) for x in [r, g, b])
Expand Down Expand Up @@ -468,10 +471,7 @@ def match_max_scale(
"""Match the maximum value of the output to the input."""
max_in = max(input_colors)
max_out = max(output_colors)
if max_out == 0:
factor = 0.0
else:
factor = max_in / max_out
factor = 0.0 if max_out == 0 else max_in / max_out
return tuple(int(round(i * factor)) for i in output_colors)


Expand Down
3 changes: 1 addition & 2 deletions zha/application/platforms/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,7 @@ def state(self) -> bool | None:
return False

try:
newer = _version_is_newer(latest_version, installed_version)
return True if newer else False
return _version_is_newer(latest_version, installed_version)
except AwesomeVersionCompareException:
# Can't compare versions, already tried exact match
return True
Expand Down

0 comments on commit b5f068a

Please sign in to comment.