config_entry assignation is deprecated#79
Conversation
|
Grazie, però vorrei poter gestire anche le versioni precedenti. La modifica fatta così com'è sarebbe compatibile solo da HA 2024.12 in poi, sulle altre invece: 2025-01-13 18:28:00.936 ERROR (MainThread) [aiohttp.server] Error handling request
Traceback (most recent call last):
File "/srv/ha4/lib/python3.11/site-packages/aiohttp/web_protocol.py", line 433, in _handle_request
resp = await request_handler(request)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/srv/ha4/lib/python3.11/site-packages/aiohttp/web_app.py", line 504, in _handle
resp = await handler(request)
^^^^^^^^^^^^^^^^^^^^^^
File "/srv/ha4/lib/python3.11/site-packages/aiohttp/web_middlewares.py", line 117, in impl
return await handler(request)
^^^^^^^^^^^^^^^^^^^^^^
File "/srv/ha4/lib/python3.11/site-packages/homeassistant/components/http/security_filter.py", line 85, in security_filter_middleware
return await handler(request)
^^^^^^^^^^^^^^^^^^^^^^
File "/srv/ha4/lib/python3.11/site-packages/homeassistant/components/http/forwarded.py", line 100, in forwarded_middleware
return await handler(request)
^^^^^^^^^^^^^^^^^^^^^^
File "/srv/ha4/lib/python3.11/site-packages/homeassistant/components/http/request_context.py", line 28, in request_context_middleware
return await handler(request)
^^^^^^^^^^^^^^^^^^^^^^
File "/srv/ha4/lib/python3.11/site-packages/homeassistant/components/http/ban.py", line 80, in ban_middleware
return await handler(request)
^^^^^^^^^^^^^^^^^^^^^^
File "/srv/ha4/lib/python3.11/site-packages/homeassistant/components/http/auth.py", line 236, in auth_middleware
return await handler(request)
^^^^^^^^^^^^^^^^^^^^^^
File "/srv/ha4/lib/python3.11/site-packages/homeassistant/components/http/headers.py", line 31, in headers_middleware
response = await handler(request)
^^^^^^^^^^^^^^^^^^^^^^
File "/srv/ha4/lib/python3.11/site-packages/homeassistant/components/http/view.py", line 148, in handle
result = await handler(request, **request.match_info)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/srv/ha4/lib/python3.11/site-packages/homeassistant/components/http/decorators.py", line 63, in with_admin
return await func(self, request, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/srv/ha4/lib/python3.11/site-packages/homeassistant/components/config/config_entries.py", line 213, in post
return await super().post(request)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/srv/ha4/lib/python3.11/site-packages/homeassistant/components/http/data_validator.py", line 72, in wrapper
result = await method(view, request, data, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/srv/ha4/lib/python3.11/site-packages/homeassistant/helpers/data_entry_flow.py", line 71, in post
result = await self._flow_mgr.async_init(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/srv/ha4/lib/python3.11/site-packages/homeassistant/data_entry_flow.py", line 270, in async_init
result = await self._async_handle_step(flow, flow.init_step, data)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/srv/ha4/lib/python3.11/site-packages/homeassistant/data_entry_flow.py", line 394, in _async_handle_step
result: FlowResult = await getattr(flow, method)(user_input)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/homeassistant/.homeassistant/custom_components/pun_sensor/config_flow.py", line 42, in async_step_init
default=self.config_entry.options.get(
^^^^^^^^^^^^^^^^^
AttributeError: 'PUNOptionsFlow' object has no attribute 'config_entry' |
| ) -> PUNOptionsFlow: | ||
| """Ottiene le opzioni per questa configurazione.""" | ||
| return PUNOptionsFlow(config_entry) | ||
| return PUNOptionsFlow() |
There was a problem hiding this comment.
Questo dovrebbe essere eseguito solo con versioni di Home Assistant >= 2024.12, mentre il vecchio codice negli altri casi (sperando che Home Assistant non si lamenti).
There was a problem hiding this comment.
Giusto, grazie, puoi vedere se ora va meglio?
9af437d to
fcbd8a3
Compare
| ) -> PUNOptionsFlow: | ||
| """Ottiene le opzioni per questa configurazione.""" | ||
| return PUNOptionsFlow(config_entry) | ||
| if AwesomeVersion(HA_VERSION) >= AwesomeVersion("2024.12.0b0"): |
There was a problem hiding this comment.
Ho messo anche la versione beta perché il commit home-assistant/core@6d561a9 è anche lì:

Dici che è un problema lasciarlo?
There was a problem hiding this comment.
No, ma dubito che qualcuno usi le beta "in produzione", perciò mi sembrava più pulito "2024.12.0".
There was a problem hiding this comment.
Certo, sono d'accordo che "2024.12.0" sarebbe più pulito ma non credo sarebbe corretto perché nella versione "2024.12.0b0" causerebbe l'errore che hai riportato in #79 (comment):
... AttributeError: 'PUNOptionsFlow' object has no attribute 'config_entry'
edd5152 to
a16d200
Compare
a16d200 to
78a3ddd
Compare
virtualdj
left a comment
There was a problem hiding this comment.
Solo cambiamenti "cosmetici" ma mi piacerebbe di più così.
| if AwesomeVersion(HA_VERSION) < AwesomeVersion("2024.12.0b0"): | ||
| options_flow = PUNOptionsFlow(config_entry) | ||
| else: | ||
| options_flow = PUNOptionsFlow() |
There was a problem hiding this comment.
Puoi ritornare direttamente con return PUNOptionsFlow()?
There was a problem hiding this comment.
Certo, fatto.
Di solito cerco di mantenere un solo punto di uscita delle funzioni/metodi però è solo una mia preferenza 😄
| """Ottiene le opzioni per questa configurazione.""" | ||
| return PUNOptionsFlow(config_entry) | ||
| if AwesomeVersion(HA_VERSION) < AwesomeVersion("2024.12.0b0"): | ||
| options_flow = PUNOptionsFlow(config_entry) |
There was a problem hiding this comment.
Puoi ritornare direttamente con return PUNOptionsFlow(config_entry)?
Otherwise the following warning is raised: Logger: homeassistant.helpers.frame Source: helpers/frame.py:324 First occurred: January 11, 2025 at 23:29:37 (4 occurrences) Last logged: 00:16:34 Detected that custom integration 'pun_sensor' sets option flow config_entry explicitly, which is deprecated at custom_components/pun_sensor/config_flow.py, line 33: self.config_entry = entry. This will stop working in Home Assistant 2025.12, please create a bug report at https://github.com/virtualdj/pun_sensor/issues Deprecation happened in home-assistant/core@6d561a9
78a3ddd to
77d589c
Compare
|
@Daemo00 Tra l'altro stavo cercando di aggiornare HACS all'ultima versione sul mio sistema di test e, tra le novità, ho trovato questa. Pare che la modifica da fare sia ancora più semplice... prova a togliere tutto e cambiare solo: pun_sensor/custom_components/pun_sensor/config_flow.py Lines 31 to 33 in 433d107 in: def __init__(self, entry: config_entries.ConfigEntry) -> None:
"""Inizializzazione opzioni."""
if AwesomeVersion(HA_VERSION) < AwesomeVersion("2024.12.0b0"):
self.config_entry = entryDovrebbe funzionare ed è ancora più pulito! Modifica e prova sul tuo recente che io provo sul mio. |
This reverts commit 77d589c to apply a different fix.
Questa commit annulla le modifiche della PR virtualdj#79 e applica un nuovo fix. Grazie a @Daemo00 per il contributo iniziale.
Grazie che hai portato avanti il tutto, purtroppo questo weekend non ho potuto fare nulla. |
|
@Daemo00 Nessun problema, grazie a te! |

Fix #78.