Skip to content

Commit f6cf37f

Browse files
authored
Merge pull request #511 from plugwise/fix-509
Fix ruf-related stuff related to PR #509
2 parents cc46b6d + d6eba10 commit f6cf37f

File tree

3 files changed

+19
-18
lines changed

3 files changed

+19
-18
lines changed

plugwise/helper.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -164,9 +164,9 @@ async def _request_validate(self, resp: ClientResponse, method: str) -> etree:
164164
try:
165165
# Encode to ensure utf8 parsing
166166
xml = etree.XML(escape_illegal_xml_characters(result).encode())
167-
except etree.ParseError:
167+
except etree.ParseError as exc:
168168
LOGGER.warning("Smile returns invalid XML for %s", self._endpoint)
169-
raise InvalidXMLError
169+
raise InvalidXMLError from exc
170170

171171
return xml
172172

@@ -202,15 +202,15 @@ async def _request(
202202
)
203203
except (
204204
ClientError
205-
) as err: # ClientError is an ancestor class of ServerTimeoutError
205+
) as exc: # ClientError is an ancestor class of ServerTimeoutError
206206
if retry < 1:
207207
LOGGER.warning(
208208
"Failed sending %s %s to Plugwise Smile, error: %s",
209209
method,
210210
command,
211-
err,
211+
exc,
212212
)
213-
raise ConnectionFailedError
213+
raise ConnectionFailedError from exc
214214
return await self._request(command, retry - 1)
215215

216216
return await self._request_validate(resp, method)

pyproject.toml

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -220,12 +220,13 @@ omit= [
220220
[tool.ruff]
221221
target-version = "py312"
222222

223-
select = [
223+
lint.select = [
224224
"B002", # Python does not support the unary prefix increment
225225
"B007", # Loop control variable {name} not used within loop body
226226
"B014", # Exception handler with duplicate exception
227227
"B023", # Function definition does not bind loop variable {name}
228228
"B026", # Star-arg unpacking after a keyword argument is strongly discouraged
229+
"B904", # Use raise from err or None to specify exception cause
229230
"C", # complexity
230231
"COM818", # Trailing comma on bare tuple prohibited
231232
"D", # docstrings
@@ -240,7 +241,7 @@ select = [
240241
"N804", # First argument of a class method should be named cls
241242
"N805", # First argument of a method should be named self
242243
"N815", # Variable {name} in class scope should not be mixedCase
243-
"PGH001", # No builtin eval() allowed
244+
# "PGH001", # PGH001 has been remapped to S307
244245
"PGH004", # Use specific rule codes when using noqa
245246
"PL", # https://github.com/astral-sh/ruff/issues/7491#issuecomment-1730008111
246247
"PLC0414", # Useless import alias. Import alias does not rename original package.
@@ -280,13 +281,13 @@ select = [
280281
"T20", # flake8-print
281282
"TID251", # Banned imports
282283
"TRY004", # Prefer TypeError exception for invalid type
283-
"TRY200", # Use raise from to specify exception cause
284+
# "TRY200", # TRY200 has been remapped to B904
284285
"TRY302", # Remove exception handler; error is immediately re-raised
285286
"UP", # pyupgrade
286287
"W", # pycodestyle
287288
]
288289

289-
ignore = [
290+
lint.ignore = [
290291
"D202", # No blank lines allowed after function docstring
291292
"D203", # 1 blank line required before class docstring
292293
"D213", # Multi-line docstring summary should start at the second line
@@ -310,24 +311,24 @@ ignore = [
310311

311312
exclude = []
312313

313-
[tool.ruff.flake8-import-conventions.extend-aliases]
314+
[tool.ruff.lint.flake8-import-conventions.extend-aliases]
314315
voluptuous = "vol"
315316
"homeassistant.helpers.area_registry" = "ar"
316317
"homeassistant.helpers.config_validation" = "cv"
317318
"homeassistant.helpers.device_registry" = "dr"
318319
"homeassistant.helpers.entity_registry" = "er"
319320
"homeassistant.helpers.issue_registry" = "ir"
320321

321-
[tool.ruff.flake8-pytest-style]
322+
[tool.ruff.lint.flake8-pytest-style]
322323
fixture-parentheses = false
323324

324-
[tool.ruff.mccabe]
325+
[tool.ruff.lint.mccabe]
325326
max-complexity = 25
326327

327-
[tool.ruff.flake8-tidy-imports.banned-api]
328+
[tool.ruff.lint.flake8-tidy-imports.banned-api]
328329
"pytz".msg = "use zoneinfo instead"
329330

330-
[tool.ruff.isort]
331+
[tool.ruff.lint.isort]
331332
force-sort-within-sections = true
332333
section-order = ["future", "standard-library", "first-party", "third-party", "local-folder"]
333334
known-third-party = [

tests/test_init.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -183,8 +183,8 @@ async def smile_status(self, request):
183183
with open(userdata, encoding="utf-8") as filedata:
184184
data = filedata.read()
185185
return aiohttp.web.Response(text=data)
186-
except OSError:
187-
raise aiohttp.web.HTTPNotFound
186+
except OSError as exc:
187+
raise aiohttp.web.HTTPNotFound from exc
188188

189189
@classmethod
190190
async def smile_http_accept(cls, request):
@@ -317,9 +317,9 @@ async def connect_wrapper(
317317
await self.connect(fail_auth=fail_auth)
318318
_LOGGER.error(" - invalid credentials not handled") # pragma: no cover
319319
raise self.ConnectError # pragma: no cover
320-
except pw_exceptions.InvalidAuthentication:
320+
except pw_exceptions.InvalidAuthentication as exc:
321321
_LOGGER.info(" + successfully aborted on credentials missing.")
322-
raise pw_exceptions.InvalidAuthentication
322+
raise pw_exceptions.InvalidAuthentication from exc
323323

324324
if raise_timeout:
325325
_LOGGER.warning("Connecting to device exceeding timeout in handling:")

0 commit comments

Comments
 (0)