From 44ed83a82978e8561b3e18cdf2eff4b40673fc77 Mon Sep 17 00:00:00 2001 From: Bouwe Westerdijk <11290930+bouwew@users.noreply.github.com> Date: Sun, 1 Dec 2024 04:01:33 +0100 Subject: [PATCH 01/41] Bump plugwise to v1.6.1 (#131950) --- homeassistant/components/plugwise/manifest.json | 2 +- requirements_all.txt | 2 +- requirements_test_all.txt | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/plugwise/manifest.json b/homeassistant/components/plugwise/manifest.json index d4d80749a8d1d3..df35777ac54a75 100644 --- a/homeassistant/components/plugwise/manifest.json +++ b/homeassistant/components/plugwise/manifest.json @@ -7,6 +7,6 @@ "integration_type": "hub", "iot_class": "local_polling", "loggers": ["plugwise"], - "requirements": ["plugwise==1.6.0"], + "requirements": ["plugwise==1.6.1"], "zeroconf": ["_plugwise._tcp.local."] } diff --git a/requirements_all.txt b/requirements_all.txt index d25732ee81b5c0..492554972e3b61 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -1622,7 +1622,7 @@ plexauth==0.0.6 plexwebsocket==0.0.14 # homeassistant.components.plugwise -plugwise==1.6.0 +plugwise==1.6.1 # homeassistant.components.plum_lightpad plumlightpad==0.0.11 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index 679b8fabd45f3a..c7b35596e017b2 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -1332,7 +1332,7 @@ plexauth==0.0.6 plexwebsocket==0.0.14 # homeassistant.components.plugwise -plugwise==1.6.0 +plugwise==1.6.1 # homeassistant.components.plum_lightpad plumlightpad==0.0.11 From ffeefd4856d8355b9746e94ca45c27d27168d89d Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sat, 30 Nov 2024 21:07:51 -0600 Subject: [PATCH 02/41] Bump SQLAlchemy to 2.0.36 (#126683) * Bump SQLAlchemy to 2.0.35 changelog: https://docs.sqlalchemy.org/en/20/changelog/changelog_20.html#change-2.0.35 * fix mocking * adjust to .36 * remove ignored as these are now typed * fix SQLAlchemy --- .github/workflows/wheels.yml | 2 +- .../components/recorder/db_schema.py | 6 +-- .../components/recorder/manifest.json | 2 +- homeassistant/components/sql/manifest.json | 2 +- homeassistant/package_constraints.txt | 2 +- pyproject.toml | 2 +- requirements.txt | 2 +- requirements_all.txt | 2 +- requirements_test_all.txt | 2 +- tests/components/sql/test_config_flow.py | 52 ++++++++----------- tests/components/sql/test_sensor.py | 41 +++++++++------ 11 files changed, 59 insertions(+), 56 deletions(-) diff --git a/.github/workflows/wheels.yml b/.github/workflows/wheels.yml index b9f54bba081447..e0a850fa340861 100644 --- a/.github/workflows/wheels.yml +++ b/.github/workflows/wheels.yml @@ -143,7 +143,7 @@ jobs: wheels-key: ${{ secrets.WHEELS_KEY }} env-file: true apk: "libffi-dev;openssl-dev;yaml-dev;nasm;zlib-dev" - skip-binary: aiohttp;multidict;yarl + skip-binary: aiohttp;multidict;yarl;SQLAlchemy constraints: "homeassistant/package_constraints.txt" requirements-diff: "requirements_diff.txt" requirements: "requirements.txt" diff --git a/homeassistant/components/recorder/db_schema.py b/homeassistant/components/recorder/db_schema.py index 7e8343321c3c5d..dbe2b775297bbb 100644 --- a/homeassistant/components/recorder/db_schema.py +++ b/homeassistant/components/recorder/db_schema.py @@ -162,14 +162,14 @@ class Unused(CHAR): """An unused column type that behaves like a string.""" -@compiles(UnusedDateTime, "mysql", "mariadb", "sqlite") # type: ignore[misc,no-untyped-call] -@compiles(Unused, "mysql", "mariadb", "sqlite") # type: ignore[misc,no-untyped-call] +@compiles(UnusedDateTime, "mysql", "mariadb", "sqlite") +@compiles(Unused, "mysql", "mariadb", "sqlite") def compile_char_zero(type_: TypeDecorator, compiler: Any, **kw: Any) -> str: """Compile UnusedDateTime and Unused as CHAR(0) on mysql, mariadb, and sqlite.""" return "CHAR(0)" # Uses 1 byte on MySQL (no change on sqlite) -@compiles(Unused, "postgresql") # type: ignore[misc,no-untyped-call] +@compiles(Unused, "postgresql") def compile_char_one(type_: TypeDecorator, compiler: Any, **kw: Any) -> str: """Compile Unused as CHAR(1) on postgresql.""" return "CHAR(1)" # Uses 1 byte diff --git a/homeassistant/components/recorder/manifest.json b/homeassistant/components/recorder/manifest.json index 2be4b6862bafba..93ffb12d18cf48 100644 --- a/homeassistant/components/recorder/manifest.json +++ b/homeassistant/components/recorder/manifest.json @@ -7,7 +7,7 @@ "iot_class": "local_push", "quality_scale": "internal", "requirements": [ - "SQLAlchemy==2.0.31", + "SQLAlchemy==2.0.36", "fnv-hash-fast==1.0.2", "psutil-home-assistant==0.0.1" ] diff --git a/homeassistant/components/sql/manifest.json b/homeassistant/components/sql/manifest.json index dcb5f47829c613..01c95d6c5e4af0 100644 --- a/homeassistant/components/sql/manifest.json +++ b/homeassistant/components/sql/manifest.json @@ -5,5 +5,5 @@ "config_flow": true, "documentation": "https://www.home-assistant.io/integrations/sql", "iot_class": "local_polling", - "requirements": ["SQLAlchemy==2.0.31", "sqlparse==0.5.0"] + "requirements": ["SQLAlchemy==2.0.36", "sqlparse==0.5.0"] } diff --git a/homeassistant/package_constraints.txt b/homeassistant/package_constraints.txt index cb3f51476c89fe..cb7aa1219abe0b 100644 --- a/homeassistant/package_constraints.txt +++ b/homeassistant/package_constraints.txt @@ -59,7 +59,7 @@ pyudev==0.24.1 PyYAML==6.0.2 requests==2.32.3 securetar==2024.11.0 -SQLAlchemy==2.0.31 +SQLAlchemy==2.0.36 standard-aifc==3.13.0;python_version>='3.13' standard-telnetlib==3.13.0;python_version>='3.13' typing-extensions>=4.12.2,<5.0 diff --git a/pyproject.toml b/pyproject.toml index 4bf14a36948ad3..3f2df027b4a30a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -66,7 +66,7 @@ dependencies = [ "PyYAML==6.0.2", "requests==2.32.3", "securetar==2024.11.0", - "SQLAlchemy==2.0.31", + "SQLAlchemy==2.0.36", "standard-aifc==3.13.0;python_version>='3.13'", "standard-telnetlib==3.13.0;python_version>='3.13'", "typing-extensions>=4.12.2,<5.0", diff --git a/requirements.txt b/requirements.txt index 2cbdeb14b98043..1fa82f175bb484 100644 --- a/requirements.txt +++ b/requirements.txt @@ -37,7 +37,7 @@ python-slugify==8.0.4 PyYAML==6.0.2 requests==2.32.3 securetar==2024.11.0 -SQLAlchemy==2.0.31 +SQLAlchemy==2.0.36 standard-aifc==3.13.0;python_version>='3.13' standard-telnetlib==3.13.0;python_version>='3.13' typing-extensions>=4.12.2,<5.0 diff --git a/requirements_all.txt b/requirements_all.txt index 492554972e3b61..0fa30cee23a316 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -116,7 +116,7 @@ RtmAPI==0.7.2 # homeassistant.components.recorder # homeassistant.components.sql -SQLAlchemy==2.0.31 +SQLAlchemy==2.0.36 # homeassistant.components.tami4 Tami4EdgeAPI==3.0 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index c7b35596e017b2..668e98a262af0a 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -110,7 +110,7 @@ RtmAPI==0.7.2 # homeassistant.components.recorder # homeassistant.components.sql -SQLAlchemy==2.0.31 +SQLAlchemy==2.0.36 # homeassistant.components.tami4 Tami4EdgeAPI==3.0 diff --git a/tests/components/sql/test_config_flow.py b/tests/components/sql/test_config_flow.py index cb990e454b7d05..3f2400c0a323a3 100644 --- a/tests/components/sql/test_config_flow.py +++ b/tests/components/sql/test_config_flow.py @@ -2,6 +2,7 @@ from __future__ import annotations +from pathlib import Path from unittest.mock import patch from sqlalchemy.exc import SQLAlchemyError @@ -597,9 +598,6 @@ async def test_options_flow_db_url_empty( "homeassistant.components.sql.async_setup_entry", return_value=True, ), - patch( - "homeassistant.components.sql.config_flow.sqlalchemy.create_engine", - ), ): result = await hass.config_entries.options.async_configure( result["flow_id"], @@ -621,7 +619,9 @@ async def test_options_flow_db_url_empty( async def test_full_flow_not_recorder_db( - recorder_mock: Recorder, hass: HomeAssistant + recorder_mock: Recorder, + hass: HomeAssistant, + tmp_path: Path, ) -> None: """Test full config flow with not using recorder db.""" result = await hass.config_entries.flow.async_init( @@ -629,20 +629,19 @@ async def test_full_flow_not_recorder_db( ) assert result["type"] is FlowResultType.FORM assert result["errors"] == {} + db_path = tmp_path / "db.db" + db_path_str = f"sqlite:///{db_path}" with ( patch( "homeassistant.components.sql.async_setup_entry", return_value=True, ), - patch( - "homeassistant.components.sql.config_flow.sqlalchemy.create_engine", - ), ): result2 = await hass.config_entries.flow.async_configure( result["flow_id"], { - "db_url": "sqlite://path/to/db.db", + "db_url": db_path_str, "name": "Get Value", "query": "SELECT 5 as value", "column": "value", @@ -654,7 +653,7 @@ async def test_full_flow_not_recorder_db( assert result2["title"] == "Get Value" assert result2["options"] == { "name": "Get Value", - "db_url": "sqlite://path/to/db.db", + "db_url": db_path_str, "query": "SELECT 5 as value", "column": "value", } @@ -671,15 +670,12 @@ async def test_full_flow_not_recorder_db( "homeassistant.components.sql.async_setup_entry", return_value=True, ), - patch( - "homeassistant.components.sql.config_flow.sqlalchemy.create_engine", - ), ): result = await hass.config_entries.options.async_configure( result["flow_id"], user_input={ "query": "SELECT 5 as value", - "db_url": "sqlite://path/to/db.db", + "db_url": db_path_str, "column": "value", "unit_of_measurement": "MiB", }, @@ -689,7 +685,7 @@ async def test_full_flow_not_recorder_db( assert result["type"] is FlowResultType.CREATE_ENTRY assert result["data"] == { "name": "Get Value", - "db_url": "sqlite://path/to/db.db", + "db_url": db_path_str, "query": "SELECT 5 as value", "column": "value", "unit_of_measurement": "MiB", @@ -697,24 +693,22 @@ async def test_full_flow_not_recorder_db( # Need to test same again to mitigate issue with db_url removal result = await hass.config_entries.options.async_init(entry.entry_id) - with patch( - "homeassistant.components.sql.config_flow.sqlalchemy.create_engine", - ): - result = await hass.config_entries.options.async_configure( - result["flow_id"], - user_input={ - "query": "SELECT 5 as value", - "db_url": "sqlite://path/to/db.db", - "column": "value", - "unit_of_measurement": "MB", - }, - ) - await hass.async_block_till_done() + + result = await hass.config_entries.options.async_configure( + result["flow_id"], + user_input={ + "query": "SELECT 5 as value", + "db_url": db_path_str, + "column": "value", + "unit_of_measurement": "MB", + }, + ) + await hass.async_block_till_done() assert result["type"] is FlowResultType.CREATE_ENTRY assert result["data"] == { "name": "Get Value", - "db_url": "sqlite://path/to/db.db", + "db_url": db_path_str, "query": "SELECT 5 as value", "column": "value", "unit_of_measurement": "MB", @@ -722,7 +716,7 @@ async def test_full_flow_not_recorder_db( assert entry.options == { "name": "Get Value", - "db_url": "sqlite://path/to/db.db", + "db_url": db_path_str, "query": "SELECT 5 as value", "column": "value", "unit_of_measurement": "MB", diff --git a/tests/components/sql/test_sensor.py b/tests/components/sql/test_sensor.py index b219ad47f3a940..6b4032323d0fbc 100644 --- a/tests/components/sql/test_sensor.py +++ b/tests/components/sql/test_sensor.py @@ -3,12 +3,13 @@ from __future__ import annotations from datetime import timedelta +from pathlib import Path +import sqlite3 from typing import Any from unittest.mock import patch from freezegun.api import FrozenDateTimeFactory import pytest -from sqlalchemy import text as sql_text from sqlalchemy.exc import SQLAlchemyError from homeassistant.components.recorder import Recorder @@ -143,29 +144,37 @@ async def test_query_no_value( assert text in caplog.text -async def test_query_mssql_no_result( - recorder_mock: Recorder, hass: HomeAssistant, caplog: pytest.LogCaptureFixture +async def test_query_on_disk_sqlite_no_result( + recorder_mock: Recorder, + hass: HomeAssistant, + caplog: pytest.LogCaptureFixture, + tmp_path: Path, ) -> None: """Test the SQL sensor with a query that returns no value.""" + db_path = tmp_path / "test.db" + db_path_str = f"sqlite:///{db_path}" + + def make_test_db(): + """Create a test database.""" + conn = sqlite3.connect(db_path) + conn.execute("CREATE TABLE users (value INTEGER)") + conn.commit() + conn.close() + + await hass.async_add_executor_job(make_test_db) + config = { - "db_url": "mssql://", - "query": "SELECT 5 as value where 1=2", + "db_url": db_path_str, + "query": "SELECT value from users", "column": "value", - "name": "count_tables", + "name": "count_users", } - with ( - patch("homeassistant.components.sql.sensor.sqlalchemy"), - patch( - "homeassistant.components.sql.sensor.sqlalchemy.text", - return_value=sql_text("SELECT TOP 1 5 as value where 1=2"), - ), - ): - await init_integration(hass, config) + await init_integration(hass, config) - state = hass.states.get("sensor.count_tables") + state = hass.states.get("sensor.count_users") assert state.state == STATE_UNKNOWN - text = "SELECT TOP 1 5 AS VALUE WHERE 1=2 returned no results" + text = "SELECT value from users LIMIT 1; returned no results" assert text in caplog.text From 6103cea3f5d018d683209865830aa074978ff430 Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Sat, 30 Nov 2024 23:04:29 -0500 Subject: [PATCH 03/41] Make the full conversation input available to sentence triggers (#131982) Co-authored-by: Michael Hansen --- .../components/conversation/default_agent.py | 6 +- .../components/conversation/models.py | 11 ++ .../components/conversation/trigger.py | 8 +- .../conversation/test_default_agent.py | 2 +- tests/components/conversation/test_trigger.py | 144 +++++++++++++++--- 5 files changed, 146 insertions(+), 25 deletions(-) diff --git a/homeassistant/components/conversation/default_agent.py b/homeassistant/components/conversation/default_agent.py index c1256a1507b37d..59c09232b93bf0 100644 --- a/homeassistant/components/conversation/default_agent.py +++ b/homeassistant/components/conversation/default_agent.py @@ -70,7 +70,7 @@ REGEX_TYPE = type(re.compile("")) TRIGGER_CALLBACK_TYPE = Callable[ - [str, RecognizeResult, str | None], Awaitable[str | None] + [ConversationInput, RecognizeResult], Awaitable[str | None] ] METADATA_CUSTOM_SENTENCE = "hass_custom_sentence" METADATA_CUSTOM_FILE = "hass_custom_file" @@ -1286,9 +1286,7 @@ async def _handle_trigger_result( # Gather callback responses in parallel trigger_callbacks = [ - self._trigger_sentences[trigger_id].callback( - user_input.text, trigger_result, user_input.device_id - ) + self._trigger_sentences[trigger_id].callback(user_input, trigger_result) for trigger_id, trigger_result in result.matched_triggers.items() ] diff --git a/homeassistant/components/conversation/models.py b/homeassistant/components/conversation/models.py index 724e520e6dfe56..10218e767512ca 100644 --- a/homeassistant/components/conversation/models.py +++ b/homeassistant/components/conversation/models.py @@ -40,6 +40,17 @@ class ConversationInput: agent_id: str | None = None """Agent to use for processing.""" + def as_dict(self) -> dict[str, Any]: + """Return input as a dict.""" + return { + "text": self.text, + "context": self.context.as_dict(), + "conversation_id": self.conversation_id, + "device_id": self.device_id, + "language": self.language, + "agent_id": self.agent_id, + } + @dataclass(slots=True) class ConversationResult: diff --git a/homeassistant/components/conversation/trigger.py b/homeassistant/components/conversation/trigger.py index a4f64ffbad9cec..24eb54c5694ad2 100644 --- a/homeassistant/components/conversation/trigger.py +++ b/homeassistant/components/conversation/trigger.py @@ -16,6 +16,7 @@ from homeassistant.helpers.typing import UNDEFINED, ConfigType from .const import DATA_DEFAULT_ENTITY, DOMAIN +from .models import ConversationInput def has_no_punctuation(value: list[str]) -> list[str]: @@ -62,7 +63,7 @@ async def async_attach_trigger( job = HassJob(action) async def call_action( - sentence: str, result: RecognizeResult, device_id: str | None + user_input: ConversationInput, result: RecognizeResult ) -> str | None: """Call action with right context.""" @@ -83,12 +84,13 @@ async def call_action( trigger_input: dict[str, Any] = { # Satisfy type checker **trigger_data, "platform": DOMAIN, - "sentence": sentence, + "sentence": user_input.text, "details": details, "slots": { # direct access to values entity_name: entity["value"] for entity_name, entity in details.items() }, - "device_id": device_id, + "device_id": user_input.device_id, + "user_input": user_input.as_dict(), } # Wait for the automation to complete diff --git a/tests/components/conversation/test_default_agent.py b/tests/components/conversation/test_default_agent.py index 6990ffe7717b71..20fa41944f23d8 100644 --- a/tests/components/conversation/test_default_agent.py +++ b/tests/components/conversation/test_default_agent.py @@ -397,7 +397,7 @@ async def test_trigger_sentences(hass: HomeAssistant) -> None: callback.reset_mock() result = await conversation.async_converse(hass, sentence, None, Context()) assert callback.call_count == 1 - assert callback.call_args[0][0] == sentence + assert callback.call_args[0][0].text == sentence assert ( result.response.response_type == intent.IntentResponseType.ACTION_DONE ), sentence diff --git a/tests/components/conversation/test_trigger.py b/tests/components/conversation/test_trigger.py index 903bc405cf0fab..50fac51c87a4a5 100644 --- a/tests/components/conversation/test_trigger.py +++ b/tests/components/conversation/test_trigger.py @@ -40,18 +40,31 @@ async def test_if_fires_on_event( }, "action": { "service": "test.automation", - "data_template": {"data": "{{ trigger }}"}, + "data": { + "data": { + "alias": "{{ trigger.alias }}", + "id": "{{ trigger.id }}", + "idx": "{{ trigger.idx }}", + "platform": "{{ trigger.platform }}", + "sentence": "{{ trigger.sentence }}", + "slots": "{{ trigger.slots }}", + "details": "{{ trigger.details }}", + "device_id": "{{ trigger.device_id }}", + "user_input": "{{ trigger.user_input }}", + } + }, }, } }, ) - + context = Context() service_response = await hass.services.async_call( "conversation", "process", {"text": "Ha ha ha"}, blocking=True, return_response=True, + context=context, ) assert service_response["response"]["speech"]["plain"]["speech"] == "Done" @@ -61,13 +74,21 @@ async def test_if_fires_on_event( assert service_calls[1].service == "automation" assert service_calls[1].data["data"] == { "alias": None, - "id": "0", - "idx": "0", + "id": 0, + "idx": 0, "platform": "conversation", "sentence": "Ha ha ha", "slots": {}, "details": {}, "device_id": None, + "user_input": { + "agent_id": None, + "context": context.as_dict(), + "conversation_id": None, + "device_id": None, + "language": "en", + "text": "Ha ha ha", + }, } @@ -152,7 +173,19 @@ async def test_response_same_sentence( {"delay": "0:0:0.100"}, { "service": "test.automation", - "data_template": {"data": "{{ trigger }}"}, + "data_template": { + "data": { + "alias": "{{ trigger.alias }}", + "id": "{{ trigger.id }}", + "idx": "{{ trigger.idx }}", + "platform": "{{ trigger.platform }}", + "sentence": "{{ trigger.sentence }}", + "slots": "{{ trigger.slots }}", + "details": "{{ trigger.details }}", + "device_id": "{{ trigger.device_id }}", + "user_input": "{{ trigger.user_input }}", + } + }, }, {"set_conversation_response": "response 2"}, ], @@ -168,13 +201,14 @@ async def test_response_same_sentence( ] }, ) - + context = Context() service_response = await hass.services.async_call( "conversation", "process", {"text": "test sentence"}, blocking=True, return_response=True, + context=context, ) await hass.async_block_till_done() @@ -188,12 +222,20 @@ async def test_response_same_sentence( assert service_calls[1].data["data"] == { "alias": None, "id": "trigger1", - "idx": "0", + "idx": 0, "platform": "conversation", "sentence": "test sentence", "slots": {}, "details": {}, "device_id": None, + "user_input": { + "agent_id": None, + "context": context.as_dict(), + "conversation_id": None, + "device_id": None, + "language": "en", + "text": "test sentence", + }, } @@ -231,13 +273,14 @@ async def test_response_same_sentence_with_error( ] }, ) - + context = Context() service_response = await hass.services.async_call( "conversation", "process", {"text": "test sentence"}, blocking=True, return_response=True, + context=context, ) await hass.async_block_till_done() @@ -320,12 +363,24 @@ async def test_same_trigger_multiple_sentences( }, "action": { "service": "test.automation", - "data_template": {"data": "{{ trigger }}"}, + "data_template": { + "data": { + "alias": "{{ trigger.alias }}", + "id": "{{ trigger.id }}", + "idx": "{{ trigger.idx }}", + "platform": "{{ trigger.platform }}", + "sentence": "{{ trigger.sentence }}", + "slots": "{{ trigger.slots }}", + "details": "{{ trigger.details }}", + "device_id": "{{ trigger.device_id }}", + "user_input": "{{ trigger.user_input }}", + } + }, }, } }, ) - + context = Context() await hass.services.async_call( "conversation", "process", @@ -333,6 +388,7 @@ async def test_same_trigger_multiple_sentences( "text": "hello", }, blocking=True, + context=context, ) # Only triggers once @@ -342,13 +398,21 @@ async def test_same_trigger_multiple_sentences( assert service_calls[1].service == "automation" assert service_calls[1].data["data"] == { "alias": None, - "id": "0", - "idx": "0", + "id": 0, + "idx": 0, "platform": "conversation", "sentence": "hello", "slots": {}, "details": {}, "device_id": None, + "user_input": { + "agent_id": None, + "context": context.as_dict(), + "conversation_id": None, + "device_id": None, + "language": "en", + "text": "hello", + }, } @@ -371,7 +435,19 @@ async def test_same_sentence_multiple_triggers( }, "action": { "service": "test.automation", - "data_template": {"data": "{{ trigger }}"}, + "data_template": { + "data": { + "alias": "{{ trigger.alias }}", + "id": "{{ trigger.id }}", + "idx": "{{ trigger.idx }}", + "platform": "{{ trigger.platform }}", + "sentence": "{{ trigger.sentence }}", + "slots": "{{ trigger.slots }}", + "details": "{{ trigger.details }}", + "device_id": "{{ trigger.device_id }}", + "user_input": "{{ trigger.user_input }}", + } + }, }, }, { @@ -384,7 +460,19 @@ async def test_same_sentence_multiple_triggers( }, "action": { "service": "test.automation", - "data_template": {"data": "{{ trigger }}"}, + "data_template": { + "data": { + "alias": "{{ trigger.alias }}", + "id": "{{ trigger.id }}", + "idx": "{{ trigger.idx }}", + "platform": "{{ trigger.platform }}", + "sentence": "{{ trigger.sentence }}", + "slots": "{{ trigger.slots }}", + "details": "{{ trigger.details }}", + "device_id": "{{ trigger.device_id }}", + "user_input": "{{ trigger.user_input }}", + } + }, }, }, ], @@ -488,12 +576,25 @@ async def test_wildcards(hass: HomeAssistant, service_calls: list[ServiceCall]) }, "action": { "service": "test.automation", - "data_template": {"data": "{{ trigger }}"}, + "data_template": { + "data": { + "alias": "{{ trigger.alias }}", + "id": "{{ trigger.id }}", + "idx": "{{ trigger.idx }}", + "platform": "{{ trigger.platform }}", + "sentence": "{{ trigger.sentence }}", + "slots": "{{ trigger.slots }}", + "details": "{{ trigger.details }}", + "device_id": "{{ trigger.device_id }}", + "user_input": "{{ trigger.user_input }}", + } + }, }, } }, ) + context = Context() await hass.services.async_call( "conversation", "process", @@ -501,6 +602,7 @@ async def test_wildcards(hass: HomeAssistant, service_calls: list[ServiceCall]) "text": "play the white album by the beatles", }, blocking=True, + context=context, ) await hass.async_block_till_done() @@ -509,8 +611,8 @@ async def test_wildcards(hass: HomeAssistant, service_calls: list[ServiceCall]) assert service_calls[1].service == "automation" assert service_calls[1].data["data"] == { "alias": None, - "id": "0", - "idx": "0", + "id": 0, + "idx": 0, "platform": "conversation", "sentence": "play the white album by the beatles", "slots": { @@ -530,6 +632,14 @@ async def test_wildcards(hass: HomeAssistant, service_calls: list[ServiceCall]) }, }, "device_id": None, + "user_input": { + "agent_id": None, + "context": context.as_dict(), + "conversation_id": None, + "device_id": None, + "language": "en", + "text": "play the white album by the beatles", + }, } From 37972ec88e2a9fcb38bce6a3cd86ff9b0bfec949 Mon Sep 17 00:00:00 2001 From: Norbert Rittel Date: Sun, 1 Dec 2024 12:08:35 +0100 Subject: [PATCH 04/41] Match "delete" with "create" in the action descriptions (#131989) --- .../components/persistent_notification/strings.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/persistent_notification/strings.json b/homeassistant/components/persistent_notification/strings.json index b9a4ae4f10f73b..e6c3d3b7775012 100644 --- a/homeassistant/components/persistent_notification/strings.json +++ b/homeassistant/components/persistent_notification/strings.json @@ -21,17 +21,17 @@ }, "dismiss": { "name": "Dismiss", - "description": "Removes a notification from the notifications panel.", + "description": "Deletes a notification from the notifications panel.", "fields": { "notification_id": { "name": "[%key:component::persistent_notification::services::create::fields::notification_id::name%]", - "description": "ID of the notification to be removed." + "description": "ID of the notification to be deleted." } } }, "dismiss_all": { "name": "Dismiss all", - "description": "Removes all notifications from the notifications panel." + "description": "Deletes all notifications from the notifications panel." } } } From 47aebabc513eec2f2eb833c5dc264bd295351ccf Mon Sep 17 00:00:00 2001 From: Jan Bouwhuis Date: Sun, 1 Dec 2024 12:20:45 +0100 Subject: [PATCH 05/41] Add final translations to mqtt exceptions (#131933) --- homeassistant/components/mqtt/client.py | 18 +++++++++++++++--- homeassistant/components/mqtt/config_flow.py | 4 +++- .../components/mqtt/device_trigger.py | 5 ++++- homeassistant/components/mqtt/strings.json | 15 +++++++++++++++ 4 files changed, 37 insertions(+), 5 deletions(-) diff --git a/homeassistant/components/mqtt/client.py b/homeassistant/components/mqtt/client.py index a626e0e5b28a19..1dcd0928434a86 100644 --- a/homeassistant/components/mqtt/client.py +++ b/homeassistant/components/mqtt/client.py @@ -776,7 +776,11 @@ def _async_untrack_subscription(self, subscription: Subscription) -> None: else: del self._wildcard_subscriptions[subscription] except (KeyError, ValueError) as exc: - raise HomeAssistantError("Can't remove subscription twice") from exc + raise HomeAssistantError( + translation_domain=DOMAIN, + translation_key="mqtt_not_setup_cannot_unsubscribe_twice", + translation_placeholders={"topic": topic}, + ) from exc @callback def _async_queue_subscriptions( @@ -822,7 +826,11 @@ def async_subscribe( ) -> Callable[[], None]: """Set up a subscription to a topic with the provided qos.""" if not isinstance(topic, str): - raise HomeAssistantError("Topic needs to be a string!") + raise HomeAssistantError( + translation_domain=DOMAIN, + translation_key="mqtt_topic_not_a_string", + translation_placeholders={"topic": topic}, + ) if job_type is None: job_type = get_hassjob_callable_job_type(msg_callback) @@ -1213,7 +1221,11 @@ async def _async_wait_for_mid_or_raise(self, mid: int, result_code: int) -> None import paho.mqtt.client as mqtt raise HomeAssistantError( - f"Error talking to MQTT: {mqtt.error_string(result_code)}" + translation_domain=DOMAIN, + translation_key="mqtt_broker_error", + translation_placeholders={ + "error_message": mqtt.error_string(result_code) + }, ) # Create the mid event if not created, either _mqtt_handle_mid or diff --git a/homeassistant/components/mqtt/config_flow.py b/homeassistant/components/mqtt/config_flow.py index 69306a1c3830be..34d43ad87f3411 100644 --- a/homeassistant/components/mqtt/config_flow.py +++ b/homeassistant/components/mqtt/config_flow.py @@ -331,7 +331,9 @@ async def _async_start_addon(self) -> None: break else: raise AddonError( - f"Failed to correctly start {addon_manager.addon_name} add-on" + translation_domain=DOMAIN, + translation_key="addon_start_failed", + translation_placeholders={"addon": addon_manager.addon_name}, ) async def async_step_user( diff --git a/homeassistant/components/mqtt/device_trigger.py b/homeassistant/components/mqtt/device_trigger.py index 80faf879587b65..8665ac26961ffe 100644 --- a/homeassistant/components/mqtt/device_trigger.py +++ b/homeassistant/components/mqtt/device_trigger.py @@ -148,7 +148,10 @@ async def add_trigger( def async_remove() -> None: """Remove trigger.""" if instance not in self.trigger_instances: - raise HomeAssistantError("Can't remove trigger twice") + raise HomeAssistantError( + translation_domain=DOMAIN, + translation_key="mqtt_trigger_cannot_remove_twice", + ) if instance.remove: instance.remove() diff --git a/homeassistant/components/mqtt/strings.json b/homeassistant/components/mqtt/strings.json index 7cf35783569730..4d23007e51bbeb 100644 --- a/homeassistant/components/mqtt/strings.json +++ b/homeassistant/components/mqtt/strings.json @@ -289,6 +289,9 @@ } }, "exceptions": { + "addon_start_failed": { + "message": "Failed to correctly start {addon} add-on." + }, "command_template_error": { "message": "Parsing template `{command_template}` for entity `{entity_id}` failed with error: {error}." }, @@ -298,11 +301,23 @@ "invalid_publish_topic": { "message": "Unable to publish: topic template `{topic_template}` produced an invalid topic `{topic}` after rendering ({error})" }, + "mqtt_broker_error": { + "message": "Error talking to MQTT: {error_message}." + }, "mqtt_not_setup_cannot_subscribe": { "message": "Cannot subscribe to topic \"{topic}\", make sure MQTT is set up correctly." }, "mqtt_not_setup_cannot_publish": { "message": "Cannot publish to topic \"{topic}\", make sure MQTT is set up correctly." + }, + "mqtt_not_setup_cannot_unsubscribe_twice": { + "message": "Cannot unsubscribe topic \"{topic}\" twice." + }, + "mqtt_topic_not_a_string": { + "message": "Topic needs to be a string! Got: {topic}." + }, + "mqtt_trigger_cannot_remove_twice": { + "message": "Can't remove trigger twice." } } } From 8878d0f0e13adfebc086bc14d38ea71a7540c7ec Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sun, 1 Dec 2024 08:55:07 -0600 Subject: [PATCH 06/41] Reduce time syscalls needed to insert new statistics (#131984) --- homeassistant/components/recorder/db_schema.py | 15 +++++++++++---- homeassistant/components/recorder/statistics.py | 16 +++++++++------- tests/components/recorder/test_statistics.py | 4 ++-- 3 files changed, 22 insertions(+), 13 deletions(-) diff --git a/homeassistant/components/recorder/db_schema.py b/homeassistant/components/recorder/db_schema.py index dbe2b775297bbb..fb57a1c73e2a21 100644 --- a/homeassistant/components/recorder/db_schema.py +++ b/homeassistant/components/recorder/db_schema.py @@ -691,12 +691,14 @@ class StatisticsBase: duration: timedelta @classmethod - def from_stats(cls, metadata_id: int, stats: StatisticData) -> Self: + def from_stats( + cls, metadata_id: int, stats: StatisticData, now_timestamp: float | None = None + ) -> Self: """Create object from a statistics with datetime objects.""" return cls( # type: ignore[call-arg] metadata_id=metadata_id, created=None, - created_ts=time.time(), + created_ts=now_timestamp or time.time(), start=None, start_ts=stats["start"].timestamp(), mean=stats.get("mean"), @@ -709,12 +711,17 @@ def from_stats(cls, metadata_id: int, stats: StatisticData) -> Self: ) @classmethod - def from_stats_ts(cls, metadata_id: int, stats: StatisticDataTimestamp) -> Self: + def from_stats_ts( + cls, + metadata_id: int, + stats: StatisticDataTimestamp, + now_timestamp: float | None = None, + ) -> Self: """Create object from a statistics with timestamps.""" return cls( # type: ignore[call-arg] metadata_id=metadata_id, created=None, - created_ts=time.time(), + created_ts=now_timestamp or time.time(), start=None, start_ts=stats["start_ts"], mean=stats.get("mean"), diff --git a/homeassistant/components/recorder/statistics.py b/homeassistant/components/recorder/statistics.py index 9f01fd0399c69d..3f1d5b981e37e5 100644 --- a/homeassistant/components/recorder/statistics.py +++ b/homeassistant/components/recorder/statistics.py @@ -11,6 +11,7 @@ import logging from operator import itemgetter import re +from time import time as time_time from typing import TYPE_CHECKING, Any, Literal, TypedDict, cast from sqlalchemy import Select, and_, bindparam, func, lambda_stmt, select, text @@ -446,8 +447,9 @@ def _compile_hourly_statistics(session: Session, start: datetime) -> None: } # Insert compiled hourly statistics in the database + now_timestamp = time_time() session.add_all( - Statistics.from_stats_ts(metadata_id, summary_item) + Statistics.from_stats_ts(metadata_id, summary_item, now_timestamp) for metadata_id, summary_item in summary.items() ) @@ -578,6 +580,7 @@ def _compile_statistics( new_short_term_stats: list[StatisticsBase] = [] updated_metadata_ids: set[int] = set() + now_timestamp = time_time() # Insert collected statistics in the database for stats in platform_stats: modified_statistic_id, metadata_id = statistics_meta_manager.update_or_add( @@ -587,10 +590,7 @@ def _compile_statistics( modified_statistic_ids.add(modified_statistic_id) updated_metadata_ids.add(metadata_id) if new_stat := _insert_statistics( - session, - StatisticsShortTerm, - metadata_id, - stats["stat"], + session, StatisticsShortTerm, metadata_id, stats["stat"], now_timestamp ): new_short_term_stats.append(new_stat) @@ -666,10 +666,11 @@ def _insert_statistics( table: type[StatisticsBase], metadata_id: int, statistic: StatisticData, + now_timestamp: float, ) -> StatisticsBase | None: """Insert statistics in the database.""" try: - stat = table.from_stats(metadata_id, statistic) + stat = table.from_stats(metadata_id, statistic, now_timestamp) session.add(stat) except SQLAlchemyError: _LOGGER.exception( @@ -2347,11 +2348,12 @@ def _import_statistics_with_session( _, metadata_id = statistics_meta_manager.update_or_add( session, metadata, old_metadata_dict ) + now_timestamp = time_time() for stat in statistics: if stat_id := _statistics_exists(session, table, metadata_id, stat["start"]): _update_statistics(session, table, stat_id, stat) else: - _insert_statistics(session, table, metadata_id, stat) + _insert_statistics(session, table, metadata_id, stat, now_timestamp) if table != StatisticsShortTerm: return True diff --git a/tests/components/recorder/test_statistics.py b/tests/components/recorder/test_statistics.py index bdf39c5ef4a66a..6b1e1a655db3c1 100644 --- a/tests/components/recorder/test_statistics.py +++ b/tests/components/recorder/test_statistics.py @@ -337,12 +337,12 @@ def mock_from_stats(): counter = 0 real_from_stats = StatisticsShortTerm.from_stats - def from_stats(metadata_id, stats): + def from_stats(metadata_id, stats, now_timestamp): nonlocal counter if counter == 0 and metadata_id == 2: counter += 1 return None - return real_from_stats(metadata_id, stats) + return real_from_stats(metadata_id, stats, now_timestamp) with patch( "homeassistant.components.recorder.statistics.StatisticsShortTerm.from_stats", From 598ce1f3b008ff323f9118df3aa46614205549b5 Mon Sep 17 00:00:00 2001 From: Erik Montnemery Date: Sun, 1 Dec 2024 16:17:55 +0100 Subject: [PATCH 07/41] Freeze integration setup timeout for recorder during non-live data migration (#131998) --- homeassistant/components/recorder/core.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/homeassistant/components/recorder/core.py b/homeassistant/components/recorder/core.py index 8c2e1c9e006a3d..0c61f8a955ec91 100644 --- a/homeassistant/components/recorder/core.py +++ b/homeassistant/components/recorder/core.py @@ -740,7 +740,7 @@ def _run(self) -> None: self.schema_version = schema_status.current_version # Do non-live data migration - migration.migrate_data_non_live(self, self.get_session, schema_status) + self._migrate_data_offline(schema_status) # Non-live migration is now completed, remaining steps are live self.migration_is_live = True @@ -916,6 +916,13 @@ def _setup_recorder(self) -> bool: return False + def _migrate_data_offline( + self, schema_status: migration.SchemaValidationStatus + ) -> None: + """Migrate data.""" + with self.hass.timeout.freeze(DOMAIN): + migration.migrate_data_non_live(self, self.get_session, schema_status) + def _migrate_schema_offline( self, schema_status: migration.SchemaValidationStatus ) -> tuple[bool, migration.SchemaValidationStatus]: From bc7cfb6761849ceaaa4c5724c99ad00ea149fc93 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Sun, 1 Dec 2024 16:39:33 +0100 Subject: [PATCH 08/41] Use typed ConfigEntry in lamarzocco (#131892) --- homeassistant/components/lamarzocco/__init__.py | 11 +++++++---- homeassistant/components/lamarzocco/config_flow.py | 4 ++-- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/homeassistant/components/lamarzocco/__init__.py b/homeassistant/components/lamarzocco/__init__.py index da513bc8cffa6f..09187848a0f857 100644 --- a/homeassistant/components/lamarzocco/__init__.py +++ b/homeassistant/components/lamarzocco/__init__.py @@ -10,7 +10,6 @@ from pylamarzocco.exceptions import AuthFail, RequestNotSuccessful from homeassistant.components.bluetooth import async_discovered_service_info -from homeassistant.config_entries import ConfigEntry from homeassistant.const import ( CONF_HOST, CONF_MAC, @@ -125,7 +124,9 @@ def bluetooth_configured() -> bool: await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS) - async def update_listener(hass: HomeAssistant, entry: ConfigEntry) -> None: + async def update_listener( + hass: HomeAssistant, entry: LaMarzoccoConfigEntry + ) -> None: await hass.config_entries.async_reload(entry.entry_id) entry.async_on_unload(entry.add_update_listener(update_listener)) @@ -133,12 +134,14 @@ async def update_listener(hass: HomeAssistant, entry: ConfigEntry) -> None: return True -async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: +async def async_unload_entry(hass: HomeAssistant, entry: LaMarzoccoConfigEntry) -> bool: """Unload a config entry.""" return await hass.config_entries.async_unload_platforms(entry, PLATFORMS) -async def async_migrate_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: +async def async_migrate_entry( + hass: HomeAssistant, entry: LaMarzoccoConfigEntry +) -> bool: """Migrate config entry.""" if entry.version > 2: # guard against downgrade from a future version diff --git a/homeassistant/components/lamarzocco/config_flow.py b/homeassistant/components/lamarzocco/config_flow.py index a727e3fe35796e..e4ee0682ae714e 100644 --- a/homeassistant/components/lamarzocco/config_flow.py +++ b/homeassistant/components/lamarzocco/config_flow.py @@ -20,7 +20,6 @@ from homeassistant.config_entries import ( SOURCE_REAUTH, SOURCE_RECONFIGURE, - ConfigEntry, ConfigFlow, ConfigFlowResult, OptionsFlow, @@ -46,6 +45,7 @@ ) from .const import CONF_USE_BLUETOOTH, DOMAIN +from .coordinator import LaMarzoccoConfigEntry CONF_MACHINE = "machine" @@ -354,7 +354,7 @@ async def async_step_reconfigure( @staticmethod @callback def async_get_options_flow( - config_entry: ConfigEntry, + config_entry: LaMarzoccoConfigEntry, ) -> LmOptionsFlowHandler: """Create the options flow.""" return LmOptionsFlowHandler() From fd42c01a21832d64674f55dbb3e450dfefa405ed Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Sun, 1 Dec 2024 16:40:06 +0100 Subject: [PATCH 09/41] Use typed ConfigEntry in tedee (#131893) --- homeassistant/components/tedee/__init__.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/tedee/__init__.py b/homeassistant/components/tedee/__init__.py index 528a5052678c4f..95348053805b50 100644 --- a/homeassistant/components/tedee/__init__.py +++ b/homeassistant/components/tedee/__init__.py @@ -16,7 +16,6 @@ async_register as webhook_register, async_unregister as webhook_unregister, ) -from homeassistant.config_entries import ConfigEntry from homeassistant.const import CONF_WEBHOOK_ID, EVENT_HOMEASSISTANT_STOP, Platform from homeassistant.core import HomeAssistant from homeassistant.helpers import device_registry as dr @@ -99,7 +98,7 @@ async def register_webhook() -> None: return True -async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: +async def async_unload_entry(hass: HomeAssistant, entry: TedeeConfigEntry) -> bool: """Unload a config entry.""" return await hass.config_entries.async_unload_platforms(entry, PLATFORMS) @@ -131,7 +130,9 @@ async def async_webhook_handler( return async_webhook_handler -async def async_migrate_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> bool: +async def async_migrate_entry( + hass: HomeAssistant, config_entry: TedeeConfigEntry +) -> bool: """Migrate old entry.""" if config_entry.version > 1: # This means the user has downgraded from a future version From 8343d7f348ff017d731b96e7679b202d161545c4 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Sun, 1 Dec 2024 16:40:30 +0100 Subject: [PATCH 10/41] Use typed ConfigEntry in twentemilieu (#131894) --- homeassistant/components/twentemilieu/__init__.py | 8 ++++++-- homeassistant/components/twentemilieu/diagnostics.py | 5 +++-- homeassistant/components/twentemilieu/entity.py | 5 ++--- homeassistant/components/twentemilieu/sensor.py | 6 +++--- 4 files changed, 14 insertions(+), 10 deletions(-) diff --git a/homeassistant/components/twentemilieu/__init__.py b/homeassistant/components/twentemilieu/__init__.py index 0a2fb50c7c4698..2796e9916f1f3f 100644 --- a/homeassistant/components/twentemilieu/__init__.py +++ b/homeassistant/components/twentemilieu/__init__.py @@ -29,7 +29,9 @@ type TwenteMilieuConfigEntry = ConfigEntry[TwenteMilieuDataUpdateCoordinator] -async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: +async def async_setup_entry( + hass: HomeAssistant, entry: TwenteMilieuConfigEntry +) -> bool: """Set up Twente Milieu from a config entry.""" session = async_get_clientsession(hass) twentemilieu = TwenteMilieu( @@ -55,6 +57,8 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: return True -async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: +async def async_unload_entry( + hass: HomeAssistant, entry: TwenteMilieuConfigEntry +) -> bool: """Unload Twente Milieu config entry.""" return await hass.config_entries.async_unload_platforms(entry, PLATFORMS) diff --git a/homeassistant/components/twentemilieu/diagnostics.py b/homeassistant/components/twentemilieu/diagnostics.py index 9de3f9bfaffe96..75775303eb684f 100644 --- a/homeassistant/components/twentemilieu/diagnostics.py +++ b/homeassistant/components/twentemilieu/diagnostics.py @@ -4,12 +4,13 @@ from typing import Any -from homeassistant.config_entries import ConfigEntry from homeassistant.core import HomeAssistant +from . import TwenteMilieuConfigEntry + async def async_get_config_entry_diagnostics( - hass: HomeAssistant, entry: ConfigEntry + hass: HomeAssistant, entry: TwenteMilieuConfigEntry ) -> dict[str, Any]: """Return diagnostics for a config entry.""" return { diff --git a/homeassistant/components/twentemilieu/entity.py b/homeassistant/components/twentemilieu/entity.py index 896a8e32de9e9a..0a2473f4524e81 100644 --- a/homeassistant/components/twentemilieu/entity.py +++ b/homeassistant/components/twentemilieu/entity.py @@ -2,13 +2,12 @@ from __future__ import annotations -from homeassistant.config_entries import ConfigEntry from homeassistant.const import CONF_ID from homeassistant.helpers.device_registry import DeviceEntryType, DeviceInfo from homeassistant.helpers.entity import Entity from homeassistant.helpers.update_coordinator import CoordinatorEntity -from . import TwenteMilieuDataUpdateCoordinator +from . import TwenteMilieuConfigEntry, TwenteMilieuDataUpdateCoordinator from .const import DOMAIN @@ -17,7 +16,7 @@ class TwenteMilieuEntity(CoordinatorEntity[TwenteMilieuDataUpdateCoordinator], E _attr_has_entity_name = True - def __init__(self, entry: ConfigEntry) -> None: + def __init__(self, entry: TwenteMilieuConfigEntry) -> None: """Initialize the Twente Milieu entity.""" super().__init__(coordinator=entry.runtime_data) self._attr_device_info = DeviceInfo( diff --git a/homeassistant/components/twentemilieu/sensor.py b/homeassistant/components/twentemilieu/sensor.py index 2d2e3de0f0e02f..f5f91ce7080dd5 100644 --- a/homeassistant/components/twentemilieu/sensor.py +++ b/homeassistant/components/twentemilieu/sensor.py @@ -12,11 +12,11 @@ SensorEntity, SensorEntityDescription, ) -from homeassistant.config_entries import ConfigEntry from homeassistant.const import CONF_ID from homeassistant.core import HomeAssistant from homeassistant.helpers.entity_platform import AddEntitiesCallback +from . import TwenteMilieuConfigEntry from .const import DOMAIN from .entity import TwenteMilieuEntity @@ -64,7 +64,7 @@ class TwenteMilieuSensorDescription(SensorEntityDescription): async def async_setup_entry( hass: HomeAssistant, - entry: ConfigEntry, + entry: TwenteMilieuConfigEntry, async_add_entities: AddEntitiesCallback, ) -> None: """Set up Twente Milieu sensor based on a config entry.""" @@ -80,7 +80,7 @@ class TwenteMilieuSensor(TwenteMilieuEntity, SensorEntity): def __init__( self, - entry: ConfigEntry, + entry: TwenteMilieuConfigEntry, description: TwenteMilieuSensorDescription, ) -> None: """Initialize the Twente Milieu entity.""" From c55a4e9584a81d551e0954df9a6a47b4b7c797ec Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Sun, 1 Dec 2024 16:49:51 +0100 Subject: [PATCH 11/41] Cleanup pylint obsolete import checks (#131904) --- pylint/plugins/hass_imports.py | 266 --------------------------------- 1 file changed, 266 deletions(-) diff --git a/pylint/plugins/hass_imports.py b/pylint/plugins/hass_imports.py index c6a869dd7fcfa6..194f99ae700a76 100644 --- a/pylint/plugins/hass_imports.py +++ b/pylint/plugins/hass_imports.py @@ -37,140 +37,6 @@ class ObsoleteImportMatch: constant=re.compile(r"^cached_property$"), ), ], - "homeassistant.components.alarm_control_panel": [ - ObsoleteImportMatch( - reason="replaced by AlarmControlPanelEntityFeature enum", - constant=re.compile(r"^SUPPORT_(\w*)$"), - ), - ObsoleteImportMatch( - reason="replaced by CodeFormat enum", - constant=re.compile(r"^FORMAT_(\w*)$"), - ), - ], - "homeassistant.components.alarm_control_panel.const": [ - ObsoleteImportMatch( - reason="replaced by AlarmControlPanelEntityFeature enum", - constant=re.compile(r"^SUPPORT_(\w*)$"), - ), - ObsoleteImportMatch( - reason="replaced by CodeFormat enum", - constant=re.compile(r"^FORMAT_(\w*)$"), - ), - ], - "homeassistant.components.automation": [ - ObsoleteImportMatch( - reason="replaced by TriggerActionType from helpers.trigger", - constant=re.compile(r"^AutomationActionType$"), - ), - ObsoleteImportMatch( - reason="replaced by TriggerData from helpers.trigger", - constant=re.compile(r"^AutomationTriggerData$"), - ), - ObsoleteImportMatch( - reason="replaced by TriggerInfo from helpers.trigger", - constant=re.compile(r"^AutomationTriggerInfo$"), - ), - ], - "homeassistant.components.binary_sensor": [ - ObsoleteImportMatch( - reason="replaced by BinarySensorDeviceClass enum", - constant=re.compile(r"^DEVICE_CLASS_(\w*)$"), - ), - ], - "homeassistant.components.camera": [ - ObsoleteImportMatch( - reason="replaced by CameraEntityFeature enum", - constant=re.compile(r"^SUPPORT_(\w*)$"), - ), - ObsoleteImportMatch( - reason="replaced by StreamType enum", - constant=re.compile(r"^STREAM_TYPE_(\w*)$"), - ), - ], - "homeassistant.components.camera.const": [ - ObsoleteImportMatch( - reason="replaced by StreamType enum", - constant=re.compile(r"^STREAM_TYPE_(\w*)$"), - ), - ], - "homeassistant.components.climate": [ - ObsoleteImportMatch( - reason="replaced by HVACMode enum", - constant=re.compile(r"^HVAC_MODE_(\w*)$"), - ), - ObsoleteImportMatch( - reason="replaced by ClimateEntityFeature enum", - constant=re.compile(r"^SUPPORT_(\w*)$"), - ), - ], - "homeassistant.components.climate.const": [ - ObsoleteImportMatch( - reason="replaced by HVACAction enum", - constant=re.compile(r"^CURRENT_HVAC_(\w*)$"), - ), - ObsoleteImportMatch( - reason="replaced by HVACMode enum", - constant=re.compile(r"^HVAC_MODE_(\w*)$"), - ), - ObsoleteImportMatch( - reason="replaced by ClimateEntityFeature enum", - constant=re.compile(r"^SUPPORT_(\w*)$"), - ), - ], - "homeassistant.components.cover": [ - ObsoleteImportMatch( - reason="replaced by CoverDeviceClass enum", - constant=re.compile(r"^DEVICE_CLASS_(\w*)$"), - ), - ObsoleteImportMatch( - reason="replaced by CoverEntityFeature enum", - constant=re.compile(r"^SUPPORT_(\w*)$"), - ), - ], - "homeassistant.components.device_tracker": [ - ObsoleteImportMatch( - reason="replaced by SourceType enum", - constant=re.compile(r"^SOURCE_TYPE_\w+$"), - ), - ], - "homeassistant.components.device_tracker.const": [ - ObsoleteImportMatch( - reason="replaced by SourceType enum", - constant=re.compile(r"^SOURCE_TYPE_\w+$"), - ), - ], - "homeassistant.components.fan": [ - ObsoleteImportMatch( - reason="replaced by FanEntityFeature enum", - constant=re.compile(r"^SUPPORT_(\w*)$"), - ), - ], - "homeassistant.components.humidifier": [ - ObsoleteImportMatch( - reason="replaced by HumidifierDeviceClass enum", - constant=re.compile(r"^DEVICE_CLASS_(\w*)$"), - ), - ObsoleteImportMatch( - reason="replaced by HumidifierEntityFeature enum", - constant=re.compile(r"^SUPPORT_(\w*)$"), - ), - ], - "homeassistant.components.humidifier.const": [ - ObsoleteImportMatch( - reason="replaced by HumidifierDeviceClass enum", - constant=re.compile(r"^DEVICE_CLASS_(\w*)$"), - ), - ObsoleteImportMatch( - reason="replaced by HumidifierEntityFeature enum", - constant=re.compile(r"^SUPPORT_(\w*)$"), - ), - ], - "homeassistant.components.lock": [ - ObsoleteImportMatch( - reason="replaced by LockEntityFeature enum", - constant=re.compile(r"^SUPPORT_(\w*)$"), - ), - ], "homeassistant.components.light": [ ObsoleteImportMatch( reason="replaced by ColorMode enum", @@ -225,52 +91,12 @@ class ObsoleteImportMatch: constant=re.compile(r"^REPEAT_MODE(\w*)$"), ), ], - "homeassistant.components.remote": [ - ObsoleteImportMatch( - reason="replaced by RemoteEntityFeature enum", - constant=re.compile(r"^SUPPORT_(\w*)$"), - ), - ], - "homeassistant.components.sensor": [ - ObsoleteImportMatch( - reason="replaced by SensorDeviceClass enum", - constant=re.compile(r"^DEVICE_CLASS_(?!STATE_CLASSES)$"), - ), - ObsoleteImportMatch( - reason="replaced by SensorStateClass enum", - constant=re.compile(r"^STATE_CLASS_(\w*)$"), - ), - ], - "homeassistant.components.siren": [ - ObsoleteImportMatch( - reason="replaced by SirenEntityFeature enum", - constant=re.compile(r"^SUPPORT_(\w*)$"), - ), - ], - "homeassistant.components.siren.const": [ - ObsoleteImportMatch( - reason="replaced by SirenEntityFeature enum", - constant=re.compile(r"^SUPPORT_(\w*)$"), - ), - ], - "homeassistant.components.switch": [ - ObsoleteImportMatch( - reason="replaced by SwitchDeviceClass enum", - constant=re.compile(r"^DEVICE_CLASS_(\w*)$"), - ), - ], "homeassistant.components.vacuum": [ ObsoleteImportMatch( reason="replaced by VacuumEntityFeature enum", constant=re.compile(r"^SUPPORT_(\w*)$"), ), ], - "homeassistant.components.water_heater": [ - ObsoleteImportMatch( - reason="replaced by WaterHeaterEntityFeature enum", - constant=re.compile(r"^SUPPORT_(\w*)$"), - ), - ], "homeassistant.config_entries": [ ObsoleteImportMatch( reason="replaced by ConfigEntryDisabler enum", @@ -282,86 +108,6 @@ class ObsoleteImportMatch: reason="replaced by local constants", constant=re.compile(r"^CONF_UNIT_SYSTEM_(\w+)$"), ), - ObsoleteImportMatch( - reason="replaced by unit enums", - constant=re.compile(r"^DATA_(\w+)$"), - ), - ObsoleteImportMatch( - reason="replaced by ***DeviceClass enum", - constant=re.compile(r"^DEVICE_CLASS_(\w+)$"), - ), - ObsoleteImportMatch( - reason="replaced by unit enums", - constant=re.compile(r"^ELECTRIC_(\w+)$"), - ), - ObsoleteImportMatch( - reason="replaced by unit enums", - constant=re.compile(r"^ENERGY_(\w+)$"), - ), - ObsoleteImportMatch( - reason="replaced by EntityCategory enum", - constant=re.compile(r"^(ENTITY_CATEGORY_(\w+))|(ENTITY_CATEGORIES)$"), - ), - ObsoleteImportMatch( - reason="replaced by unit enums", - constant=re.compile(r"^FREQUENCY_(\w+)$"), - ), - ObsoleteImportMatch( - reason="replaced by unit enums", - constant=re.compile(r"^IRRADIATION_(\w+)$"), - ), - ObsoleteImportMatch( - reason="replaced by unit enums", - constant=re.compile(r"^LENGTH_(\w+)$"), - ), - ObsoleteImportMatch( - reason="replaced by unit enums", - constant=re.compile(r"^MASS_(\w+)$"), - ), - ObsoleteImportMatch( - reason="replaced by unit enums", - constant=re.compile(r"^POWER_(?!VOLT_AMPERE_REACTIVE)(\w+)$"), - ), - ObsoleteImportMatch( - reason="replaced by unit enums", - constant=re.compile(r"^PRECIPITATION_(\w+)$"), - ), - ObsoleteImportMatch( - reason="replaced by unit enums", - constant=re.compile(r"^PRESSURE_(\w+)$"), - ), - ObsoleteImportMatch( - reason="replaced by unit enums", - constant=re.compile(r"^SOUND_PRESSURE_(\w+)$"), - ), - ObsoleteImportMatch( - reason="replaced by unit enums", - constant=re.compile(r"^SPEED_(\w+)$"), - ), - ObsoleteImportMatch( - reason="replaced by unit enums", - constant=re.compile(r"^TEMP_(\w+)$"), - ), - ObsoleteImportMatch( - reason="replaced by unit enums", - constant=re.compile(r"^TIME_(\w+)$"), - ), - ObsoleteImportMatch( - reason="replaced by unit enums", - constant=re.compile(r"^VOLUME_(\w+)$"), - ), - ], - "homeassistant.core": [ - ObsoleteImportMatch( - reason="replaced by ConfigSource enum", - constant=re.compile(r"^SOURCE_(\w*)$"), - ), - ], - "homeassistant.data_entry_flow": [ - ObsoleteImportMatch( - reason="replaced by FlowResultType enum", - constant=re.compile(r"^RESULT_TYPE_(\w*)$"), - ), ], "homeassistant.helpers.config_validation": [ ObsoleteImportMatch( @@ -369,12 +115,6 @@ class ObsoleteImportMatch: constant=re.compile(r"^PLATFORM_SCHEMA(_BASE)?$"), ), ], - "homeassistant.helpers.device_registry": [ - ObsoleteImportMatch( - reason="replaced by DeviceEntryDisabler enum", - constant=re.compile(r"^DISABLED_(\w*)$"), - ), - ], "homeassistant.helpers.json": [ ObsoleteImportMatch( reason="moved to homeassistant.util.json", @@ -383,12 +123,6 @@ class ObsoleteImportMatch: ), ), ], - "homeassistant.util": [ - ObsoleteImportMatch( - reason="replaced by unit_conversion.***Converter", - constant=re.compile(r"^(distance|pressure|speed|temperature|volume)$"), - ), - ], "homeassistant.util.unit_system": [ ObsoleteImportMatch( reason="replaced by US_CUSTOMARY_SYSTEM", From 3aae9b629fc8ca0b8cbf8a2981f0bce20a78e16f Mon Sep 17 00:00:00 2001 From: Jan Bouwhuis Date: Sun, 1 Dec 2024 16:53:06 +0100 Subject: [PATCH 12/41] Add exception translation for entity action not supported (#131956) --- .../components/homeassistant/strings.json | 3 +++ homeassistant/exceptions.py | 19 +++++++++++++++++++ homeassistant/helpers/service.py | 5 ++--- tests/components/august/test_lock.py | 6 ++++-- tests/components/calendar/test_init.py | 11 ++++++++--- tests/components/google/test_init.py | 13 +++++++++---- tests/components/matter/test_vacuum.py | 10 +++++++--- .../components/samsungtv/test_media_player.py | 6 ++++-- tests/components/tedee/test_lock.py | 9 ++++++--- tests/components/tesla_fleet/test_climate.py | 13 ++++++++++--- tests/components/todo/test_init.py | 13 +++++++++---- tests/components/yale/test_lock.py | 13 ++++++++++--- tests/helpers/test_service.py | 8 +++++++- 13 files changed, 98 insertions(+), 31 deletions(-) diff --git a/homeassistant/components/homeassistant/strings.json b/homeassistant/components/homeassistant/strings.json index da8a1015d79150..52b330bfbc8077 100644 --- a/homeassistant/components/homeassistant/strings.json +++ b/homeassistant/components/homeassistant/strings.json @@ -224,6 +224,9 @@ "service_not_found": { "message": "Action {domain}.{service} not found." }, + "service_not_supported": { + "message": "Entity {entity_id} does not support action {domain}.{service}." + }, "service_does_not_support_response": { "message": "An action which does not return responses can't be called with {return_response}." }, diff --git a/homeassistant/exceptions.py b/homeassistant/exceptions.py index f308cbc5cd8f70..85fe55277fa9e2 100644 --- a/homeassistant/exceptions.py +++ b/homeassistant/exceptions.py @@ -270,6 +270,25 @@ def __init__(self, domain: str, service: str) -> None: self.generate_message = True +class ServiceNotSupported(ServiceValidationError): + """Raised when an entity action is not supported.""" + + def __init__(self, domain: str, service: str, entity_id: str) -> None: + """Initialize ServiceNotSupported exception.""" + super().__init__( + translation_domain="homeassistant", + translation_key="service_not_supported", + translation_placeholders={ + "domain": domain, + "service": service, + "entity_id": entity_id, + }, + ) + self.domain = domain + self.service = service + self.generate_message = True + + class MaxLengthExceeded(HomeAssistantError): """Raised when a property value has exceeded the max character length.""" diff --git a/homeassistant/helpers/service.py b/homeassistant/helpers/service.py index 31b2e8e8ac8cbe..35135010452b6c 100644 --- a/homeassistant/helpers/service.py +++ b/homeassistant/helpers/service.py @@ -42,6 +42,7 @@ ) from homeassistant.exceptions import ( HomeAssistantError, + ServiceNotSupported, TemplateError, Unauthorized, UnknownUser, @@ -986,9 +987,7 @@ async def entity_service_call( ): # If entity explicitly referenced, raise an error if referenced is not None and entity.entity_id in referenced.referenced: - raise HomeAssistantError( - f"Entity {entity.entity_id} does not support this service." - ) + raise ServiceNotSupported(call.domain, call.service, entity.entity_id) continue diff --git a/tests/components/august/test_lock.py b/tests/components/august/test_lock.py index 1b8c98e299c8b7..eb177a35cfb848 100644 --- a/tests/components/august/test_lock.py +++ b/tests/components/august/test_lock.py @@ -20,8 +20,9 @@ STATE_UNKNOWN, ) from homeassistant.core import HomeAssistant -from homeassistant.exceptions import HomeAssistantError +from homeassistant.exceptions import ServiceNotSupported from homeassistant.helpers import device_registry as dr, entity_registry as er +from homeassistant.setup import async_setup_component import homeassistant.util.dt as dt_util from .mocks import ( @@ -453,8 +454,9 @@ async def test_open_throws_hass_service_not_supported_error( hass: HomeAssistant, ) -> None: """Test open throws correct error on entity does not support this service error.""" + await async_setup_component(hass, "homeassistant", {}) mocked_lock_detail = await _mock_operative_august_lock_detail(hass) await _create_august_with_devices(hass, [mocked_lock_detail]) data = {ATTR_ENTITY_ID: "lock.a6697750d607098bae8d6baa11ef8063_name"} - with pytest.raises(HomeAssistantError, match="does not support this service"): + with pytest.raises(ServiceNotSupported, match="does not support action"): await hass.services.async_call(LOCK_DOMAIN, SERVICE_OPEN, data, blocking=True) diff --git a/tests/components/calendar/test_init.py b/tests/components/calendar/test_init.py index 4ad5e11b8e4b6d..36b102b933ae09 100644 --- a/tests/components/calendar/test_init.py +++ b/tests/components/calendar/test_init.py @@ -14,7 +14,8 @@ from homeassistant.components.calendar import DOMAIN, SERVICE_GET_EVENTS from homeassistant.core import HomeAssistant -from homeassistant.exceptions import HomeAssistantError +from homeassistant.exceptions import HomeAssistantError, ServiceNotSupported +from homeassistant.setup import async_setup_component import homeassistant.util.dt as dt_util from .conftest import MockCalendarEntity, MockConfigEntry @@ -214,8 +215,12 @@ async def test_unsupported_websocket( async def test_unsupported_create_event_service(hass: HomeAssistant) -> None: """Test unsupported service call.""" - - with pytest.raises(HomeAssistantError, match="does not support this service"): + await async_setup_component(hass, "homeassistant", {}) + with pytest.raises( + ServiceNotSupported, + match="Entity calendar.calendar_1 does not " + "support action calendar.create_event", + ): await hass.services.async_call( DOMAIN, "create_event", diff --git a/tests/components/google/test_init.py b/tests/components/google/test_init.py index 536a14409581b5..ad43e341968d18 100644 --- a/tests/components/google/test_init.py +++ b/tests/components/google/test_init.py @@ -20,7 +20,8 @@ from homeassistant.config_entries import ConfigEntryState from homeassistant.const import ATTR_FRIENDLY_NAME, STATE_OFF from homeassistant.core import HomeAssistant, State -from homeassistant.exceptions import HomeAssistantError +from homeassistant.exceptions import HomeAssistantError, ServiceNotSupported +from homeassistant.setup import async_setup_component from homeassistant.util.dt import UTC, utcnow from .conftest import ( @@ -593,7 +594,7 @@ async def test_unsupported_create_event( aioclient_mock: AiohttpClientMocker, ) -> None: """Test create event service call is unsupported for virtual calendars.""" - + await async_setup_component(hass, "homeassistant", {}) mock_calendars_list({"items": [test_api_calendar]}) mock_events_list({}) assert await component_setup() @@ -601,8 +602,12 @@ async def test_unsupported_create_event( start_datetime = datetime.datetime.now(tz=zoneinfo.ZoneInfo("America/Regina")) delta = datetime.timedelta(days=3, hours=3) end_datetime = start_datetime + delta + entity_id = "calendar.backyard_light" - with pytest.raises(HomeAssistantError, match="does not support this service"): + with pytest.raises( + ServiceNotSupported, + match=f"Entity {entity_id} does not support action google.create_event", + ): await hass.services.async_call( DOMAIN, "create_event", @@ -613,7 +618,7 @@ async def test_unsupported_create_event( "summary": TEST_EVENT_SUMMARY, "description": TEST_EVENT_DESCRIPTION, }, - target={"entity_id": "calendar.backyard_light"}, + target={"entity_id": entity_id}, blocking=True, ) diff --git a/tests/components/matter/test_vacuum.py b/tests/components/matter/test_vacuum.py index 86f7542395aa1b..1b33f6a2fe27fd 100644 --- a/tests/components/matter/test_vacuum.py +++ b/tests/components/matter/test_vacuum.py @@ -8,8 +8,10 @@ from syrupy import SnapshotAssertion from homeassistant.const import Platform -from homeassistant.core import HomeAssistant, HomeAssistantError +from homeassistant.core import HomeAssistant +from homeassistant.exceptions import ServiceNotSupported from homeassistant.helpers import entity_registry as er +from homeassistant.setup import async_setup_component from .common import ( set_node_attribute, @@ -35,6 +37,8 @@ async def test_vacuum_actions( matter_node: MatterNode, ) -> None: """Test vacuum entity actions.""" + # Fetch translations + await async_setup_component(hass, "homeassistant", {}) entity_id = "vacuum.mock_vacuum" state = hass.states.get(entity_id) assert state @@ -96,8 +100,8 @@ async def test_vacuum_actions( # test stop action # stop command is not supported by the vacuum fixture with pytest.raises( - HomeAssistantError, - match="Entity vacuum.mock_vacuum does not support this service.", + ServiceNotSupported, + match="Entity vacuum.mock_vacuum does not support action vacuum.stop", ): await hass.services.async_call( "vacuum", diff --git a/tests/components/samsungtv/test_media_player.py b/tests/components/samsungtv/test_media_player.py index ef7e58251e89d3..1a7c8713b17632 100644 --- a/tests/components/samsungtv/test_media_player.py +++ b/tests/components/samsungtv/test_media_player.py @@ -76,7 +76,8 @@ STATE_UNAVAILABLE, ) from homeassistant.core import HomeAssistant -from homeassistant.exceptions import HomeAssistantError +from homeassistant.exceptions import ServiceNotSupported +from homeassistant.setup import async_setup_component import homeassistant.util.dt as dt_util from . import async_wait_config_entry_reload, setup_samsungtv_entry @@ -1021,8 +1022,9 @@ async def test_turn_on_wol(hass: HomeAssistant) -> None: async def test_turn_on_without_turnon(hass: HomeAssistant, remote: Mock) -> None: """Test turn on.""" + await async_setup_component(hass, "homeassistant", {}) await setup_samsungtv_entry(hass, MOCK_CONFIG) - with pytest.raises(HomeAssistantError, match="does not support this service"): + with pytest.raises(ServiceNotSupported, match="does not support action"): await hass.services.async_call( MP_DOMAIN, SERVICE_TURN_ON, {ATTR_ENTITY_ID: ENTITY_ID}, True ) diff --git a/tests/components/tedee/test_lock.py b/tests/components/tedee/test_lock.py index 45eae6e22d99c7..d84acb212ea547 100644 --- a/tests/components/tedee/test_lock.py +++ b/tests/components/tedee/test_lock.py @@ -24,8 +24,9 @@ from homeassistant.components.webhook import async_generate_url from homeassistant.const import ATTR_ENTITY_ID, STATE_UNAVAILABLE, STATE_UNKNOWN from homeassistant.core import HomeAssistant -from homeassistant.exceptions import HomeAssistantError +from homeassistant.exceptions import HomeAssistantError, ServiceNotSupported from homeassistant.helpers import device_registry as dr, entity_registry as er +from homeassistant.setup import async_setup_component from .conftest import WEBHOOK_ID @@ -113,6 +114,8 @@ async def test_lock_without_pullspring( snapshot: SnapshotAssertion, ) -> None: """Test the tedee lock without pullspring.""" + # Fetch translations + await async_setup_component(hass, "homeassistant", {}) mock_tedee.lock.return_value = None mock_tedee.unlock.return_value = None mock_tedee.open.return_value = None @@ -131,8 +134,8 @@ async def test_lock_without_pullspring( assert device == snapshot with pytest.raises( - HomeAssistantError, - match="Entity lock.lock_2c3d does not support this service.", + ServiceNotSupported, + match=f"Entity lock.lock_2c3d does not support action {LOCK_DOMAIN}.{SERVICE_OPEN}", ): await hass.services.async_call( LOCK_DOMAIN, diff --git a/tests/components/tesla_fleet/test_climate.py b/tests/components/tesla_fleet/test_climate.py index b8cb7f1269b195..b45e5259a5c843 100644 --- a/tests/components/tesla_fleet/test_climate.py +++ b/tests/components/tesla_fleet/test_climate.py @@ -24,8 +24,13 @@ from homeassistant.components.tesla_fleet.coordinator import VEHICLE_INTERVAL from homeassistant.const import ATTR_ENTITY_ID, Platform from homeassistant.core import HomeAssistant -from homeassistant.exceptions import HomeAssistantError, ServiceValidationError +from homeassistant.exceptions import ( + HomeAssistantError, + ServiceNotSupported, + ServiceValidationError, +) from homeassistant.helpers import entity_registry as er +from homeassistant.setup import async_setup_component from . import assert_entities, setup_platform from .const import ( @@ -391,6 +396,7 @@ async def test_climate_noscope( snapshot: SnapshotAssertion, ) -> None: """Tests with no command scopes.""" + await async_setup_component(hass, "homeassistant", {}) await setup_platform(hass, readonly_config_entry, [Platform.CLIMATE]) entity_id = "climate.test_climate" @@ -405,8 +411,9 @@ async def test_climate_noscope( ) with pytest.raises( - HomeAssistantError, - match="Entity climate.test_climate does not support this service.", + ServiceNotSupported, + match="Entity climate.test_climate does not " + "support action climate.set_temperature", ): await hass.services.async_call( CLIMATE_DOMAIN, diff --git a/tests/components/todo/test_init.py b/tests/components/todo/test_init.py index fd052a7f8a3599..8e8c010f758976 100644 --- a/tests/components/todo/test_init.py +++ b/tests/components/todo/test_init.py @@ -27,7 +27,11 @@ from homeassistant.config_entries import ConfigEntryState from homeassistant.const import ATTR_ENTITY_ID, ATTR_SUPPORTED_FEATURES from homeassistant.core import HomeAssistant -from homeassistant.exceptions import HomeAssistantError, ServiceValidationError +from homeassistant.exceptions import ( + HomeAssistantError, + ServiceNotSupported, + ServiceValidationError, +) from homeassistant.helpers import intent from homeassistant.setup import async_setup_component @@ -941,14 +945,15 @@ async def test_unsupported_service( payload: dict[str, Any] | None, ) -> None: """Test a To-do list that does not support features.""" - + # Fetch translations + await async_setup_component(hass, "homeassistant", "") entity1 = TodoListEntity() entity1.entity_id = "todo.entity1" await create_mock_platform(hass, [entity1]) with pytest.raises( - HomeAssistantError, - match="does not support this service", + ServiceNotSupported, + match=f"Entity todo.entity1 does not support action {DOMAIN}.{service_name}", ): await hass.services.async_call( DOMAIN, diff --git a/tests/components/yale/test_lock.py b/tests/components/yale/test_lock.py index f0fe018759c058..f6b96120d0de82 100644 --- a/tests/components/yale/test_lock.py +++ b/tests/components/yale/test_lock.py @@ -18,7 +18,7 @@ STATE_UNKNOWN, ) from homeassistant.core import HomeAssistant -from homeassistant.exceptions import HomeAssistantError +from homeassistant.exceptions import ServiceNotSupported from homeassistant.helpers import device_registry as dr, entity_registry as er import homeassistant.util.dt as dt_util @@ -29,6 +29,7 @@ _mock_lock_from_fixture, _mock_lock_with_unlatch, _mock_operative_yale_lock_detail, + async_setup_component, ) from tests.common import async_fire_time_changed @@ -418,8 +419,14 @@ async def test_open_throws_hass_service_not_supported_error( hass: HomeAssistant, ) -> None: """Test open throws correct error on entity does not support this service error.""" + # Fetch translations + await async_setup_component(hass, "homeassistant", {}) mocked_lock_detail = await _mock_operative_yale_lock_detail(hass) await _create_yale_with_devices(hass, [mocked_lock_detail]) - data = {ATTR_ENTITY_ID: "lock.a6697750d607098bae8d6baa11ef8063_name"} - with pytest.raises(HomeAssistantError, match="does not support this service"): + entity_id = "lock.a6697750d607098bae8d6baa11ef8063_name" + data = {ATTR_ENTITY_ID: entity_id} + with pytest.raises( + ServiceNotSupported, + match=f"Entity {entity_id} does not support action {LOCK_DOMAIN}.{SERVICE_OPEN}", + ): await hass.services.async_call(LOCK_DOMAIN, SERVICE_OPEN, data, blocking=True) diff --git a/tests/helpers/test_service.py b/tests/helpers/test_service.py index d0e1aa3434014f..e63cb69909cf45 100644 --- a/tests/helpers/test_service.py +++ b/tests/helpers/test_service.py @@ -1274,6 +1274,8 @@ async def test_register_with_mixed_case(hass: HomeAssistant) -> None: async def test_call_with_required_features(hass: HomeAssistant, mock_entities) -> None: """Test service calls invoked only if entity has required features.""" + # Set up homeassistant component to fetch the translations + await async_setup_component(hass, "homeassistant", {}) test_service_mock = AsyncMock(return_value=None) await service.entity_service_call( hass, @@ -1293,7 +1295,11 @@ async def test_call_with_required_features(hass: HomeAssistant, mock_entities) - # Test we raise if we target entity ID that does not support the service test_service_mock.reset_mock() - with pytest.raises(exceptions.HomeAssistantError): + with pytest.raises( + exceptions.ServiceNotSupported, + match="Entity light.living_room does not " + "support action test_domain.test_service", + ): await service.entity_service_call( hass, mock_entities, From 2b094ee25d51bec2887ba65848eef64f6f7fb9e8 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Sun, 1 Dec 2024 16:54:05 +0100 Subject: [PATCH 13/41] Improve renault config-flow translation strings (#131706) --- homeassistant/components/renault/strings.json | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/renault/strings.json b/homeassistant/components/renault/strings.json index a6487772bb6ac8..7d9cae1bcf1b36 100644 --- a/homeassistant/components/renault/strings.json +++ b/homeassistant/components/renault/strings.json @@ -13,14 +13,21 @@ "step": { "kamereon": { "data": { - "kamereon_account_id": "Kamereon account id" + "kamereon_account_id": "Account ID" }, - "title": "Select Kamereon account id" + "data_description": { + "kamereon_account_id": "The Kamereon account ID associated with your vehicle" + }, + "title": "Kamereon Account ID", + "description": "You have multiple Kamereon accounts associated to this email, please select one" }, "reauth_confirm": { "data": { "password": "[%key:common::config_flow::data::password%]" }, + "data_description": { + "password": "Your MyRenault phone application password" + }, "description": "Please update your password for {username}", "title": "[%key:common::config_flow::title::reauth%]" }, @@ -30,6 +37,11 @@ "username": "[%key:common::config_flow::data::email%]", "password": "[%key:common::config_flow::data::password%]" }, + "data_description": { + "locale": "Your country code", + "username": "Your MyRenault phone application email address", + "password": "Your MyRenault phone application password" + }, "title": "Set Renault credentials" } } From a0541c7fe6e82e180eda93c2033f011f905aa44d Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Sun, 1 Dec 2024 16:55:43 +0100 Subject: [PATCH 14/41] Improve renault config flow tests (#131698) --- homeassistant/components/renault/quality_scale.yaml | 4 +--- tests/components/renault/test_config_flow.py | 2 ++ 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/renault/quality_scale.yaml b/homeassistant/components/renault/quality_scale.yaml index aa693e8e86d6de..b49ff669895e10 100644 --- a/homeassistant/components/renault/quality_scale.yaml +++ b/homeassistant/components/renault/quality_scale.yaml @@ -4,9 +4,7 @@ rules: appropriate-polling: done brands: done common-modules: done - config-flow-test-coverage: - status: todo - comment: Tests are not asserting the unique id + config-flow-test-coverage: done config-flow: done dependency-transparency: done docs-actions: done diff --git a/tests/components/renault/test_config_flow.py b/tests/components/renault/test_config_flow.py index 56e0c8a99d70c6..781b7efe226f0f 100644 --- a/tests/components/renault/test_config_flow.py +++ b/tests/components/renault/test_config_flow.py @@ -101,6 +101,7 @@ async def test_config_flow_single_account( assert result["data"][CONF_PASSWORD] == "test" assert result["data"][CONF_KAMEREON_ACCOUNT_ID] == "account_id_1" assert result["data"][CONF_LOCALE] == "fr_FR" + assert result["context"]["unique_id"] == "account_id_1" assert len(mock_setup_entry.mock_calls) == 1 @@ -189,6 +190,7 @@ async def test_config_flow_multiple_accounts( assert result["data"][CONF_PASSWORD] == "test" assert result["data"][CONF_KAMEREON_ACCOUNT_ID] == "account_id_2" assert result["data"][CONF_LOCALE] == "fr_FR" + assert result["context"]["unique_id"] == "account_id_2" assert len(mock_setup_entry.mock_calls) == 1 From c54eed360726a84927d7f07e7c1fb44eb607d284 Mon Sep 17 00:00:00 2001 From: Erik Montnemery Date: Sun, 1 Dec 2024 16:58:24 +0100 Subject: [PATCH 15/41] Improve recorder migration logging (#132006) --- .../components/recorder/migration.py | 24 ++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/homeassistant/components/recorder/migration.py b/homeassistant/components/recorder/migration.py index c9e36f4721888d..fffecff149ca82 100644 --- a/homeassistant/components/recorder/migration.py +++ b/homeassistant/components/recorder/migration.py @@ -313,7 +313,7 @@ def _migrate_schema( for version in range(current_version, end_version): new_version = version + 1 - _LOGGER.info("Upgrading recorder db schema to version %s", new_version) + _LOGGER.warning("Upgrading recorder db schema to version %s", new_version) _apply_update(instance, hass, engine, session_maker, new_version, start_version) with session_scope(session=session_maker()) as session: session.add(SchemaChanges(schema_version=new_version)) @@ -2326,9 +2326,15 @@ def needs_migrate(self, instance: Recorder, session: Session) -> bool: """ if self.schema_version < self.required_schema_version: # Schema is too old, we must have to migrate + _LOGGER.info( + "Data migration '%s' needed, schema too old", self.migration_id + ) return True if self.migration_changes.get(self.migration_id, -1) >= self.migration_version: # The migration changes table indicates that the migration has been done + _LOGGER.debug( + "Data migration '%s' not needed, already completed", self.migration_id + ) return False # We do not know if the migration is done from the # migration changes table so we must check the index and data @@ -2338,10 +2344,19 @@ def needs_migrate(self, instance: Recorder, session: Session) -> bool: and get_index_by_name(session, self.index_to_drop[0], self.index_to_drop[1]) is not None ): + _LOGGER.info( + "Data migration '%s' needed, index to drop still exists", + self.migration_id, + ) return True needs_migrate = self.needs_migrate_impl(instance, session) if needs_migrate.migration_done: _mark_migration_done(session, self.__class__) + _LOGGER.info( + "Data migration '%s' needed: %s", + self.migration_id, + needs_migrate.needs_migrate, + ) return needs_migrate.needs_migrate @@ -2354,10 +2369,17 @@ def migrate_all( """Migrate all data.""" with session_scope(session=session_maker()) as session: if not self.needs_migrate(instance, session): + _LOGGER.debug("Migration not needed for '%s'", self.migration_id) self.migration_done(instance, session) return + _LOGGER.warning( + "The database is about to do data migration step '%s', %s", + self.migration_id, + MIGRATION_NOTE_OFFLINE, + ) while not self.migrate_data(instance): pass + _LOGGER.warning("Data migration step '%s' completed", self.migration_id) @database_job_retry_wrapper_method("migrate data", 10) def migrate_data(self, instance: Recorder) -> bool: From cf0ee635077114961f6e508be56ce7620c718c18 Mon Sep 17 00:00:00 2001 From: Erik Montnemery Date: Sun, 1 Dec 2024 18:26:29 +0100 Subject: [PATCH 16/41] Simplify recorder RecorderRunsManager (#131785) --- .../recorder/table_managers/recorder_runs.py | 73 +++---------------- .../table_managers/test_recorder_runs.py | 32 ++------ 2 files changed, 15 insertions(+), 90 deletions(-) diff --git a/homeassistant/components/recorder/table_managers/recorder_runs.py b/homeassistant/components/recorder/table_managers/recorder_runs.py index b0b9818118ba0a..4ca0aa18b88ea0 100644 --- a/homeassistant/components/recorder/table_managers/recorder_runs.py +++ b/homeassistant/components/recorder/table_managers/recorder_runs.py @@ -2,8 +2,6 @@ from __future__ import annotations -import bisect -from dataclasses import dataclass from datetime import datetime from sqlalchemy.orm.session import Session @@ -11,34 +9,6 @@ import homeassistant.util.dt as dt_util from ..db_schema import RecorderRuns -from ..models import process_timestamp - - -def _find_recorder_run_for_start_time( - run_history: _RecorderRunsHistory, start: datetime -) -> RecorderRuns | None: - """Find the recorder run for a start time in _RecorderRunsHistory.""" - run_timestamps = run_history.run_timestamps - runs_by_timestamp = run_history.runs_by_timestamp - - # bisect_left tells us were we would insert - # a value in the list of runs after the start timestamp. - # - # The run before that (idx-1) is when the run started - # - # If idx is 0, history never ran before the start timestamp - # - if idx := bisect.bisect_left(run_timestamps, start.timestamp()): - return runs_by_timestamp[run_timestamps[idx - 1]] - return None - - -@dataclass(frozen=True) -class _RecorderRunsHistory: - """Bisectable history of RecorderRuns.""" - - run_timestamps: list[int] - runs_by_timestamp: dict[int, RecorderRuns] class RecorderRunsManager: @@ -48,7 +18,7 @@ def __init__(self) -> None: """Track recorder run history.""" self._recording_start = dt_util.utcnow() self._current_run_info: RecorderRuns | None = None - self._run_history = _RecorderRunsHistory([], {}) + self._first_run: RecorderRuns | None = None @property def recording_start(self) -> datetime: @@ -58,9 +28,7 @@ def recording_start(self) -> datetime: @property def first(self) -> RecorderRuns: """Get the first run.""" - if runs_by_timestamp := self._run_history.runs_by_timestamp: - return next(iter(runs_by_timestamp.values())) - return self.current + return self._first_run or self.current @property def current(self) -> RecorderRuns: @@ -78,15 +46,6 @@ def active(self) -> bool: """Return if a run is active.""" return self._current_run_info is not None - def get(self, start: datetime) -> RecorderRuns | None: - """Return the recorder run that started before or at start. - - If the first run started after the start, return None - """ - if start >= self.recording_start: - return self.current - return _find_recorder_run_for_start_time(self._run_history, start) - def start(self, session: Session) -> None: """Start a new run. @@ -122,31 +81,17 @@ def load_from_db(self, session: Session) -> None: Must run in the recorder thread. """ - run_timestamps: list[int] = [] - runs_by_timestamp: dict[int, RecorderRuns] = {} - - for run in session.query(RecorderRuns).order_by(RecorderRuns.start.asc()).all(): + if ( + run := session.query(RecorderRuns) + .order_by(RecorderRuns.start.asc()) + .first() + ): session.expunge(run) - if run_dt := process_timestamp(run.start): - # Not sure if this is correct or runs_by_timestamp annotation should be changed - timestamp = int(run_dt.timestamp()) - run_timestamps.append(timestamp) - runs_by_timestamp[timestamp] = run - - # - # self._run_history is accessed in get() - # which is allowed to be called from any thread - # - # We use a dataclass to ensure that when we update - # run_timestamps and runs_by_timestamp - # are never out of sync with each other. - # - self._run_history = _RecorderRunsHistory(run_timestamps, runs_by_timestamp) + self._first_run = run def clear(self) -> None: """Clear the current run after ending it. Must run in the recorder thread. """ - if self._current_run_info: - self._current_run_info = None + self._current_run_info = None diff --git a/tests/components/recorder/table_managers/test_recorder_runs.py b/tests/components/recorder/table_managers/test_recorder_runs.py index 41f3a8fef4da9d..e79def01badb7a 100644 --- a/tests/components/recorder/table_managers/test_recorder_runs.py +++ b/tests/components/recorder/table_managers/test_recorder_runs.py @@ -21,6 +21,11 @@ async def test_run_history(recorder_mock: Recorder, hass: HomeAssistant) -> None two_days_ago = now - timedelta(days=2) one_day_ago = now - timedelta(days=1) + # Test that the first run falls back to the current run + assert process_timestamp( + instance.recorder_runs_manager.first.start + ) == process_timestamp(instance.recorder_runs_manager.current.start) + with instance.get_session() as session: session.add(RecorderRuns(start=three_days_ago, created=three_days_ago)) session.add(RecorderRuns(start=two_days_ago, created=two_days_ago)) @@ -29,32 +34,7 @@ async def test_run_history(recorder_mock: Recorder, hass: HomeAssistant) -> None instance.recorder_runs_manager.load_from_db(session) assert ( - process_timestamp( - instance.recorder_runs_manager.get( - three_days_ago + timedelta(microseconds=1) - ).start - ) - == three_days_ago - ) - assert ( - process_timestamp( - instance.recorder_runs_manager.get( - two_days_ago + timedelta(microseconds=1) - ).start - ) - == two_days_ago - ) - assert ( - process_timestamp( - instance.recorder_runs_manager.get( - one_day_ago + timedelta(microseconds=1) - ).start - ) - == one_day_ago - ) - assert ( - process_timestamp(instance.recorder_runs_manager.get(now).start) - == instance.recorder_runs_manager.recording_start + process_timestamp(instance.recorder_runs_manager.first.start) == three_days_ago ) From ff1702eefab97922c1e164db09a62be232e61aae Mon Sep 17 00:00:00 2001 From: Erik Montnemery Date: Sun, 1 Dec 2024 19:40:40 +0100 Subject: [PATCH 17/41] Remove unnecessary assignment in Recorder._process_state_changed_event_into_session (#132011) --- homeassistant/components/recorder/core.py | 1 - 1 file changed, 1 deletion(-) diff --git a/homeassistant/components/recorder/core.py b/homeassistant/components/recorder/core.py index 0c61f8a955ec91..a3163d5b396143 100644 --- a/homeassistant/components/recorder/core.py +++ b/homeassistant/components/recorder/core.py @@ -1128,7 +1128,6 @@ def _process_state_changed_event_into_session( # Map the event data to the StateAttributes table shared_attrs = shared_attrs_bytes.decode("utf-8") - dbstate.attributes = None # Matching attributes found in the pending commit if pending_event_data := state_attributes_manager.get_pending(shared_attrs): dbstate.state_attributes = pending_event_data From bd3f4323763b415d68fd487ce9fb32686ec78e77 Mon Sep 17 00:00:00 2001 From: Norbert Rittel Date: Sun, 1 Dec 2024 20:55:27 +0100 Subject: [PATCH 18/41] Clarify description of fan actions, fix typo (#132023) --- homeassistant/components/fan/strings.json | 24 +++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/homeassistant/components/fan/strings.json b/homeassistant/components/fan/strings.json index aab714d3e07235..c4951e88c91b26 100644 --- a/homeassistant/components/fan/strings.json +++ b/homeassistant/components/fan/strings.json @@ -56,17 +56,17 @@ "services": { "set_preset_mode": { "name": "Set preset mode", - "description": "Sets preset mode.", + "description": "Sets preset fan mode.", "fields": { "preset_mode": { "name": "Preset mode", - "description": "Preset mode." + "description": "Preset fan mode." } } }, "set_percentage": { "name": "Set speed", - "description": "Sets the fan speed.", + "description": "Sets the speed of a fan.", "fields": { "percentage": { "name": "Percentage", @@ -94,45 +94,45 @@ }, "oscillate": { "name": "Oscillate", - "description": "Controls oscillatation of the fan.", + "description": "Controls the oscillation of a fan.", "fields": { "oscillating": { "name": "Oscillating", - "description": "Turn on/off oscillation." + "description": "Turns oscillation on/off." } } }, "toggle": { "name": "[%key:common::action::toggle%]", - "description": "Toggles the fan on/off." + "description": "Toggles a fan on/off." }, "set_direction": { "name": "Set direction", - "description": "Sets the fan rotation direction.", + "description": "Sets a fan's rotation direction.", "fields": { "direction": { "name": "Direction", - "description": "Direction to rotate." + "description": "Direction of the fan rotation." } } }, "increase_speed": { "name": "Increase speed", - "description": "Increases the speed of the fan.", + "description": "Increases the speed of a fan.", "fields": { "percentage_step": { "name": "Increment", - "description": "Increases the speed by a percentage step." + "description": "Percentage step by which the speed should be increased." } } }, "decrease_speed": { "name": "Decrease speed", - "description": "Decreases the speed of the fan.", + "description": "Decreases the speed of a fan.", "fields": { "percentage_step": { "name": "Decrement", - "description": "Decreases the speed by a percentage step." + "description": "Percentage step by which the speed should be decreased." } } } From 82e190dc4b565e5f0ab54049a93aead03993d4dd Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sun, 1 Dec 2024 14:37:03 -0600 Subject: [PATCH 19/41] Bump propcache to 0.2.1 (#132022) --- .github/workflows/wheels.yml | 2 +- homeassistant/package_constraints.txt | 2 +- pyproject.toml | 2 +- requirements.txt | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/wheels.yml b/.github/workflows/wheels.yml index e0a850fa340861..749f95fa922164 100644 --- a/.github/workflows/wheels.yml +++ b/.github/workflows/wheels.yml @@ -143,7 +143,7 @@ jobs: wheels-key: ${{ secrets.WHEELS_KEY }} env-file: true apk: "libffi-dev;openssl-dev;yaml-dev;nasm;zlib-dev" - skip-binary: aiohttp;multidict;yarl;SQLAlchemy + skip-binary: aiohttp;multidict;propcache;yarl;SQLAlchemy constraints: "homeassistant/package_constraints.txt" requirements-diff: "requirements_diff.txt" requirements: "requirements.txt" diff --git a/homeassistant/package_constraints.txt b/homeassistant/package_constraints.txt index cb7aa1219abe0b..5c0db0659d6a63 100644 --- a/homeassistant/package_constraints.txt +++ b/homeassistant/package_constraints.txt @@ -45,7 +45,7 @@ orjson==3.10.12 packaging>=23.1 paho-mqtt==1.6.1 Pillow==11.0.0 -propcache==0.2.0 +propcache==0.2.1 psutil-home-assistant==0.0.1 PyJWT==2.10.0 pymicro-vad==1.0.1 diff --git a/pyproject.toml b/pyproject.toml index 3f2df027b4a30a..2c143db77f68ee 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -57,7 +57,7 @@ dependencies = [ # PyJWT has loose dependency. We want the latest one. "cryptography==43.0.1", "Pillow==11.0.0", - "propcache==0.2.0", + "propcache==0.2.1", "pyOpenSSL==24.2.1", "orjson==3.10.12", "packaging>=23.1", diff --git a/requirements.txt b/requirements.txt index 1fa82f175bb484..514ab132bc87ec 100644 --- a/requirements.txt +++ b/requirements.txt @@ -28,7 +28,7 @@ lru-dict==1.3.0 PyJWT==2.10.0 cryptography==43.0.1 Pillow==11.0.0 -propcache==0.2.0 +propcache==0.2.1 pyOpenSSL==24.2.1 orjson==3.10.12 packaging>=23.1 From e706a5ef2738fc97b7381c451cfa764e03ca5863 Mon Sep 17 00:00:00 2001 From: Richard Kroegel <42204099+rikroe@users.noreply.github.com> Date: Sun, 1 Dec 2024 21:37:35 +0100 Subject: [PATCH 20/41] Set parallel updates for BMW entities (#132019) --- homeassistant/components/bmw_connected_drive/button.py | 2 ++ homeassistant/components/bmw_connected_drive/lock.py | 3 +++ homeassistant/components/bmw_connected_drive/notify.py | 2 ++ homeassistant/components/bmw_connected_drive/number.py | 2 ++ homeassistant/components/bmw_connected_drive/select.py | 2 ++ homeassistant/components/bmw_connected_drive/switch.py | 2 ++ 6 files changed, 13 insertions(+) diff --git a/homeassistant/components/bmw_connected_drive/button.py b/homeassistant/components/bmw_connected_drive/button.py index e6bd92b92d7015..85747278cb1b32 100644 --- a/homeassistant/components/bmw_connected_drive/button.py +++ b/homeassistant/components/bmw_connected_drive/button.py @@ -22,6 +22,8 @@ if TYPE_CHECKING: from .coordinator import BMWDataUpdateCoordinator +PARALLEL_UPDATES = 1 + _LOGGER = logging.getLogger(__name__) diff --git a/homeassistant/components/bmw_connected_drive/lock.py b/homeassistant/components/bmw_connected_drive/lock.py index 3dfc0b1c4d4334..b715a1e38cc855 100644 --- a/homeassistant/components/bmw_connected_drive/lock.py +++ b/homeassistant/components/bmw_connected_drive/lock.py @@ -18,7 +18,10 @@ from .coordinator import BMWDataUpdateCoordinator from .entity import BMWBaseEntity +PARALLEL_UPDATES = 1 + DOOR_LOCK_STATE = "door_lock_state" + _LOGGER = logging.getLogger(__name__) diff --git a/homeassistant/components/bmw_connected_drive/notify.py b/homeassistant/components/bmw_connected_drive/notify.py index 56523351e667f4..662a73a20cdef9 100644 --- a/homeassistant/components/bmw_connected_drive/notify.py +++ b/homeassistant/components/bmw_connected_drive/notify.py @@ -22,6 +22,8 @@ from . import DOMAIN, BMWConfigEntry +PARALLEL_UPDATES = 1 + ATTR_LOCATION_ATTRIBUTES = ["street", "city", "postal_code", "country"] POI_SCHEMA = vol.Schema( diff --git a/homeassistant/components/bmw_connected_drive/number.py b/homeassistant/components/bmw_connected_drive/number.py index 54519ff9e6b24f..cce71b3b2fd600 100644 --- a/homeassistant/components/bmw_connected_drive/number.py +++ b/homeassistant/components/bmw_connected_drive/number.py @@ -22,6 +22,8 @@ from .coordinator import BMWDataUpdateCoordinator from .entity import BMWBaseEntity +PARALLEL_UPDATES = 1 + _LOGGER = logging.getLogger(__name__) diff --git a/homeassistant/components/bmw_connected_drive/select.py b/homeassistant/components/bmw_connected_drive/select.py index 323768ad9eb658..7bc91b098ae5f5 100644 --- a/homeassistant/components/bmw_connected_drive/select.py +++ b/homeassistant/components/bmw_connected_drive/select.py @@ -19,6 +19,8 @@ from .coordinator import BMWDataUpdateCoordinator from .entity import BMWBaseEntity +PARALLEL_UPDATES = 1 + _LOGGER = logging.getLogger(__name__) diff --git a/homeassistant/components/bmw_connected_drive/switch.py b/homeassistant/components/bmw_connected_drive/switch.py index e8a02efdcfce1a..f0214bc1262541 100644 --- a/homeassistant/components/bmw_connected_drive/switch.py +++ b/homeassistant/components/bmw_connected_drive/switch.py @@ -18,6 +18,8 @@ from .coordinator import BMWDataUpdateCoordinator from .entity import BMWBaseEntity +PARALLEL_UPDATES = 1 + _LOGGER = logging.getLogger(__name__) From 36ca4e8866a57b7adaa6099121d5a81906e78212 Mon Sep 17 00:00:00 2001 From: Norbert Rittel Date: Sun, 1 Dec 2024 21:42:16 +0100 Subject: [PATCH 21/41] Fix description of 'clear_completed_items' to use "remove" (#132014) --- homeassistant/components/shopping_list/strings.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/homeassistant/components/shopping_list/strings.json b/homeassistant/components/shopping_list/strings.json index c184a1d22271c1..8618d9241b4a0f 100644 --- a/homeassistant/components/shopping_list/strings.json +++ b/homeassistant/components/shopping_list/strings.json @@ -62,7 +62,7 @@ }, "clear_completed_items": { "name": "Clear completed items", - "description": "Clears completed items from the shopping list." + "description": "Removes completed items from the shopping list." }, "sort": { "name": "Sort all items", From 8fdd095dabf85886dedbac7a465a0074c6be6d92 Mon Sep 17 00:00:00 2001 From: dotvav Date: Sun, 1 Dec 2024 21:43:09 +0100 Subject: [PATCH 22/41] Add pre-commit VSCode task (#131637) --- .vscode/tasks.json | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 2b02916a73ebb8..1f95c5eef8fc03 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -56,6 +56,20 @@ }, "problemMatcher": [] }, + { + "label": "Pre-commit", + "type": "shell", + "command": "pre-commit run --show-diff-on-failure", + "group": { + "kind": "test", + "isDefault": true + }, + "presentation": { + "reveal": "always", + "panel": "new" + }, + "problemMatcher": [] + }, { "label": "Pylint", "type": "shell", From ffc3aca41f273d1f25d0dd7ef9369b9e7deb3720 Mon Sep 17 00:00:00 2001 From: David Knowles Date: Sun, 1 Dec 2024 15:44:14 -0500 Subject: [PATCH 23/41] Bump pydrawise to 2024.12.0 (#132015) --- homeassistant/components/hydrawise/manifest.json | 2 +- requirements_all.txt | 2 +- requirements_test_all.txt | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/hydrawise/manifest.json b/homeassistant/components/hydrawise/manifest.json index 9678dc83e5f274..50f803c07dc0de 100644 --- a/homeassistant/components/hydrawise/manifest.json +++ b/homeassistant/components/hydrawise/manifest.json @@ -6,5 +6,5 @@ "documentation": "https://www.home-assistant.io/integrations/hydrawise", "iot_class": "cloud_polling", "loggers": ["pydrawise"], - "requirements": ["pydrawise==2024.9.0"] + "requirements": ["pydrawise==2024.12.0"] } diff --git a/requirements_all.txt b/requirements_all.txt index 0fa30cee23a316..450219d2ac806c 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -1859,7 +1859,7 @@ pydiscovergy==3.0.2 pydoods==1.0.2 # homeassistant.components.hydrawise -pydrawise==2024.9.0 +pydrawise==2024.12.0 # homeassistant.components.android_ip_webcam pydroid-ipcam==2.0.0 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index 668e98a262af0a..4f94f7e6538c23 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -1503,7 +1503,7 @@ pydexcom==0.2.3 pydiscovergy==3.0.2 # homeassistant.components.hydrawise -pydrawise==2024.9.0 +pydrawise==2024.12.0 # homeassistant.components.android_ip_webcam pydroid-ipcam==2.0.0 From 98734ebe4f234a2f7333bad005b9b64be7021010 Mon Sep 17 00:00:00 2001 From: Richard Kroegel <42204099+rikroe@users.noreply.github.com> Date: Sun, 1 Dec 2024 21:45:31 +0100 Subject: [PATCH 24/41] Bump bimmer_connected to 0.17.2 (#132005) --- homeassistant/components/bmw_connected_drive/manifest.json | 2 +- requirements_all.txt | 2 +- requirements_test_all.txt | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/bmw_connected_drive/manifest.json b/homeassistant/components/bmw_connected_drive/manifest.json index d1ca735ce55eb9..81928a59a52bc9 100644 --- a/homeassistant/components/bmw_connected_drive/manifest.json +++ b/homeassistant/components/bmw_connected_drive/manifest.json @@ -6,5 +6,5 @@ "documentation": "https://www.home-assistant.io/integrations/bmw_connected_drive", "iot_class": "cloud_polling", "loggers": ["bimmer_connected"], - "requirements": ["bimmer-connected[china]==0.17.0"] + "requirements": ["bimmer-connected[china]==0.17.2"] } diff --git a/requirements_all.txt b/requirements_all.txt index 450219d2ac806c..56f9f56f061b77 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -582,7 +582,7 @@ beautifulsoup4==4.12.3 # beewi-smartclim==0.0.10 # homeassistant.components.bmw_connected_drive -bimmer-connected[china]==0.17.0 +bimmer-connected[china]==0.17.2 # homeassistant.components.bizkaibus bizkaibus==0.1.1 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index 4f94f7e6538c23..a38e6629b3afb1 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -516,7 +516,7 @@ base36==0.1.1 beautifulsoup4==4.12.3 # homeassistant.components.bmw_connected_drive -bimmer-connected[china]==0.17.0 +bimmer-connected[china]==0.17.2 # homeassistant.components.eq3btsmart # homeassistant.components.esphome From 521505f9b51fb4ae9bd2472aa2be7d552b069565 Mon Sep 17 00:00:00 2001 From: Charles Garwood Date: Sun, 1 Dec 2024 16:00:21 -0500 Subject: [PATCH 25/41] Add additional data_descriptions for Fully Kiosk Browser fields (#131716) --- .../components/fully_kiosk/strings.json | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/homeassistant/components/fully_kiosk/strings.json b/homeassistant/components/fully_kiosk/strings.json index ec7bd7b1c03a8c..a4b466926f0787 100644 --- a/homeassistant/components/fully_kiosk/strings.json +++ b/homeassistant/components/fully_kiosk/strings.json @@ -1,16 +1,22 @@ { "common": { - "data_description_password": "The Remote Admin Password from the Fully Kiosk Browser app settings." + "data_description_password": "The Remote Admin Password from the Fully Kiosk Browser app settings.", + "data_description_ssl": "Is the Fully Kiosk app configured to require SSL for the connection?", + "data_description_verify_ssl": "Should SSL certificartes be verified? This should be off for self-signed certificates." }, "config": { "step": { "discovery_confirm": { "description": "Do you want to set up {name} ({host})?", "data": { - "password": "[%key:common::config_flow::data::password%]" + "password": "[%key:common::config_flow::data::password%]", + "ssl": "[%key:common::config_flow::data::ssl%]", + "verify_ssl": "[%key:common::config_flow::data::verify_ssl%]" }, "data_description": { - "password": "[%key:component::fully_kiosk::common::data_description_password%]" + "password": "[%key:component::fully_kiosk::common::data_description_password%]", + "ssl": "[%key:component::fully_kiosk::common::data_description_ssl%]", + "verify_ssl": "[%key:component::fully_kiosk::common::data_description_verify_ssl%]" } }, "user": { @@ -22,7 +28,9 @@ }, "data_description": { "host": "The hostname or IP address of the device running your Fully Kiosk Browser application.", - "password": "[%key:component::fully_kiosk::common::data_description_password%]" + "password": "[%key:component::fully_kiosk::common::data_description_password%]", + "ssl": "[%key:component::fully_kiosk::common::data_description_ssl%]", + "verify_ssl": "[%key:component::fully_kiosk::common::data_description_verify_ssl%]" } } }, From bd8cd87faecd1483b07443cacb93554ff0d23776 Mon Sep 17 00:00:00 2001 From: Bouwe Westerdijk <11290930+bouwew@users.noreply.github.com> Date: Sun, 1 Dec 2024 22:01:19 +0100 Subject: [PATCH 26/41] Bugfix for Plugwise, small code optimization (#131990) --- homeassistant/components/plugwise/climate.py | 51 +++++++++++--------- 1 file changed, 27 insertions(+), 24 deletions(-) diff --git a/homeassistant/components/plugwise/climate.py b/homeassistant/components/plugwise/climate.py index f1f54aa6647c6b..242b0944782b2c 100644 --- a/homeassistant/components/plugwise/climate.py +++ b/homeassistant/components/plugwise/climate.py @@ -78,19 +78,18 @@ def __init__( self._attr_extra_state_attributes = {} self._attr_unique_id = f"{device_id}-climate" + self._devices = coordinator.data.devices + self._gateway = coordinator.data.gateway + gateway_id: str = self._gateway["gateway_id"] + self._gateway_data = self._devices[gateway_id] + self._location = device_id if (location := self.device.get("location")) is not None: self._location = location - self.cdr_gateway = coordinator.data.gateway - gateway_id: str = coordinator.data.gateway["gateway_id"] - self.gateway_data = coordinator.data.devices[gateway_id] # Determine supported features self._attr_supported_features = ClimateEntityFeature.TARGET_TEMPERATURE - if ( - self.cdr_gateway["cooling_present"] - and self.cdr_gateway["smile_name"] != "Adam" - ): + if self._gateway["cooling_present"] and self._gateway["smile_name"] != "Adam": self._attr_supported_features = ( ClimateEntityFeature.TARGET_TEMPERATURE_RANGE ) @@ -116,10 +115,10 @@ def _previous_action_mode(self, coordinator: PlugwiseDataUpdateCoordinator) -> N """ # When no cooling available, _previous_mode is always heating if ( - "regulation_modes" in self.gateway_data - and "cooling" in self.gateway_data["regulation_modes"] + "regulation_modes" in self._gateway_data + and "cooling" in self._gateway_data["regulation_modes"] ): - mode = self.gateway_data["select_regulation_mode"] + mode = self._gateway_data["select_regulation_mode"] if mode in ("cooling", "heating"): self._previous_mode = mode @@ -166,17 +165,17 @@ def hvac_mode(self) -> HVACMode: def hvac_modes(self) -> list[HVACMode]: """Return a list of available HVACModes.""" hvac_modes: list[HVACMode] = [] - if "regulation_modes" in self.gateway_data: + if "regulation_modes" in self._gateway_data: hvac_modes.append(HVACMode.OFF) if "available_schedules" in self.device: hvac_modes.append(HVACMode.AUTO) - if self.cdr_gateway["cooling_present"]: - if "regulation_modes" in self.gateway_data: - if self.gateway_data["select_regulation_mode"] == "cooling": + if self._gateway["cooling_present"]: + if "regulation_modes" in self._gateway_data: + if self._gateway_data["select_regulation_mode"] == "cooling": hvac_modes.append(HVACMode.COOL) - if self.gateway_data["select_regulation_mode"] == "heating": + if self._gateway_data["select_regulation_mode"] == "heating": hvac_modes.append(HVACMode.HEAT) else: hvac_modes.append(HVACMode.HEAT_COOL) @@ -192,17 +191,21 @@ def hvac_action(self) -> HVACAction: self._previous_action_mode(self.coordinator) # Adam provides the hvac_action for each thermostat - if (control_state := self.device.get("control_state")) == "cooling": - return HVACAction.COOLING - if control_state == "heating": - return HVACAction.HEATING - if control_state == "preheating": - return HVACAction.PREHEATING - if control_state == "off": + if self._gateway["smile_name"] == "Adam": + if (control_state := self.device.get("control_state")) == "cooling": + return HVACAction.COOLING + if control_state == "heating": + return HVACAction.HEATING + if control_state == "preheating": + return HVACAction.PREHEATING + if control_state == "off": + return HVACAction.IDLE + return HVACAction.IDLE - heater: str = self.coordinator.data.gateway["heater_id"] - heater_data = self.coordinator.data.devices[heater] + # Anna + heater: str = self._gateway["heater_id"] + heater_data = self._devices[heater] if heater_data["binary_sensors"]["heating_state"]: return HVACAction.HEATING if heater_data["binary_sensors"].get("cooling_state", False): From 78ced997e2fe6e73acbc5d94dd02b9fce137e723 Mon Sep 17 00:00:00 2001 From: Klaas Schoute Date: Sun, 1 Dec 2024 22:02:50 +0100 Subject: [PATCH 27/41] Add reauthentication flow for Autarco integration (#131816) --- .../components/autarco/config_flow.py | 44 ++++++++++++ .../components/autarco/coordinator.py | 8 ++- .../components/autarco/quality_scale.yaml | 2 +- homeassistant/components/autarco/strings.json | 15 +++- tests/components/autarco/test_config_flow.py | 72 ++++++++++++++++++- tests/components/autarco/test_init.py | 19 +++++ 6 files changed, 154 insertions(+), 6 deletions(-) diff --git a/homeassistant/components/autarco/config_flow.py b/homeassistant/components/autarco/config_flow.py index a66f14047a74fd..294fa685fb88db 100644 --- a/homeassistant/components/autarco/config_flow.py +++ b/homeassistant/components/autarco/config_flow.py @@ -2,6 +2,7 @@ from __future__ import annotations +from collections.abc import Mapping from typing import Any from autarco import Autarco, AutarcoAuthenticationError, AutarcoConnectionError @@ -20,6 +21,12 @@ } ) +STEP_REAUTH_SCHEMA = vol.Schema( + { + vol.Required(CONF_PASSWORD): str, + } +) + class AutarcoConfigFlow(ConfigFlow, domain=DOMAIN): """Handle a config flow for Autarco.""" @@ -55,3 +62,40 @@ async def async_step_user( errors=errors, data_schema=DATA_SCHEMA, ) + + async def async_step_reauth( + self, entry_data: Mapping[str, Any] + ) -> ConfigFlowResult: + """Handle re-authentication request from Autarco.""" + return await self.async_step_reauth_confirm() + + async def async_step_reauth_confirm( + self, user_input: dict[str, Any] | None = None + ) -> ConfigFlowResult: + """Handle re-authentication confirmation.""" + errors = {} + + reauth_entry = self._get_reauth_entry() + if user_input is not None: + client = Autarco( + email=reauth_entry.data[CONF_EMAIL], + password=user_input[CONF_PASSWORD], + session=async_get_clientsession(self.hass), + ) + try: + await client.get_account() + except AutarcoAuthenticationError: + errors["base"] = "invalid_auth" + except AutarcoConnectionError: + errors["base"] = "cannot_connect" + else: + return self.async_update_reload_and_abort( + reauth_entry, + data_updates=user_input, + ) + return self.async_show_form( + step_id="reauth_confirm", + description_placeholders={"email": reauth_entry.data[CONF_EMAIL]}, + data_schema=STEP_REAUTH_SCHEMA, + errors=errors, + ) diff --git a/homeassistant/components/autarco/coordinator.py b/homeassistant/components/autarco/coordinator.py index 5dd19478ae89ec..dd8786bca25177 100644 --- a/homeassistant/components/autarco/coordinator.py +++ b/homeassistant/components/autarco/coordinator.py @@ -7,6 +7,7 @@ from autarco import ( AccountSite, Autarco, + AutarcoAuthenticationError, AutarcoConnectionError, Battery, Inverter, @@ -16,6 +17,7 @@ from homeassistant.config_entries import ConfigEntry from homeassistant.core import HomeAssistant +from homeassistant.exceptions import ConfigEntryAuthFailed from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed from .const import DOMAIN, LOGGER, SCAN_INTERVAL @@ -60,8 +62,10 @@ async def _async_update_data(self) -> AutarcoData: inverters = await self.client.get_inverters(self.account_site.public_key) if site.has_battery: battery = await self.client.get_battery(self.account_site.public_key) - except AutarcoConnectionError as error: - raise UpdateFailed(error) from error + except AutarcoAuthenticationError as err: + raise ConfigEntryAuthFailed(err) from err + except AutarcoConnectionError as err: + raise UpdateFailed(err) from err return AutarcoData( solar=solar, inverters=inverters, diff --git a/homeassistant/components/autarco/quality_scale.yaml b/homeassistant/components/autarco/quality_scale.yaml index f0eb4771447587..d2e1455af7e02d 100644 --- a/homeassistant/components/autarco/quality_scale.yaml +++ b/homeassistant/components/autarco/quality_scale.yaml @@ -51,7 +51,7 @@ rules: This integration only polls data using a coordinator. Since the integration is read-only and poll-only (only provide sensor data), there is no need to implement parallel updates. - reauthentication-flow: todo + reauthentication-flow: done test-coverage: done # Gold diff --git a/homeassistant/components/autarco/strings.json b/homeassistant/components/autarco/strings.json index 8eda5fe0411da4..159dbd097811c2 100644 --- a/homeassistant/components/autarco/strings.json +++ b/homeassistant/components/autarco/strings.json @@ -2,7 +2,7 @@ "config": { "step": { "user": { - "description": "Connect to your Autarco account to get information about your solar panels.", + "description": "Connect to your Autarco account, to get information about your sites.", "data": { "email": "[%key:common::config_flow::data::email%]", "password": "[%key:common::config_flow::data::password%]" @@ -11,6 +11,16 @@ "email": "The email address of your Autarco account.", "password": "The password of your Autarco account." } + }, + "reauth_confirm": { + "title": "[%key:common::config_flow::title::reauth%]", + "description": "The password for {email} is no longer valid.", + "data": { + "password": "[%key:common::config_flow::data::password%]" + }, + "data_description": { + "password": "[%key:component::autarco::config::step::user::data_description::password%]" + } } }, "error": { @@ -18,7 +28,8 @@ "cannot_connect": "[%key:common::config_flow::error::cannot_connect%]" }, "abort": { - "already_configured": "[%key:common::config_flow::abort::already_configured_device%]" + "already_configured": "[%key:common::config_flow::abort::already_configured_device%]", + "reauth_successful": "[%key:common::config_flow::abort::reauth_successful%]" } }, "entity": { diff --git a/tests/components/autarco/test_config_flow.py b/tests/components/autarco/test_config_flow.py index 621ad7f55c8e1f..47c6a2fb0846cb 100644 --- a/tests/components/autarco/test_config_flow.py +++ b/tests/components/autarco/test_config_flow.py @@ -1,6 +1,6 @@ """Test the Autarco config flow.""" -from unittest.mock import AsyncMock +from unittest.mock import AsyncMock, patch from autarco import AutarcoAuthenticationError, AutarcoConnectionError import pytest @@ -92,6 +92,7 @@ async def test_exceptions( assert result.get("type") is FlowResultType.FORM assert result.get("errors") == {"base": error} + # Recover from error mock_autarco_client.get_account.side_effect = None result = await hass.config_entries.flow.async_configure( @@ -99,3 +100,72 @@ async def test_exceptions( user_input={CONF_EMAIL: "test@autarco.com", CONF_PASSWORD: "test-password"}, ) assert result.get("type") is FlowResultType.CREATE_ENTRY + + +async def test_step_reauth( + hass: HomeAssistant, + mock_config_entry: MockConfigEntry, + mock_setup_entry: AsyncMock, +) -> None: + """Test reauth flow.""" + mock_config_entry.add_to_hass(hass) + result = await mock_config_entry.start_reauth_flow(hass) + + assert result.get("type") is FlowResultType.FORM + assert result.get("step_id") == "reauth_confirm" + + with patch("homeassistant.components.autarco.config_flow.Autarco", autospec=True): + result = await hass.config_entries.flow.async_configure( + result["flow_id"], + user_input={CONF_PASSWORD: "new-password"}, + ) + + assert result.get("type") is FlowResultType.ABORT + assert result.get("reason") == "reauth_successful" + + assert len(hass.config_entries.async_entries()) == 1 + assert mock_config_entry.data[CONF_PASSWORD] == "new-password" + + +@pytest.mark.parametrize( + ("exception", "error"), + [ + (AutarcoConnectionError, "cannot_connect"), + (AutarcoAuthenticationError, "invalid_auth"), + ], +) +async def test_step_reauth_exceptions( + hass: HomeAssistant, + mock_autarco_client: AsyncMock, + mock_config_entry: MockConfigEntry, + mock_setup_entry: AsyncMock, + exception: Exception, + error: str, +) -> None: + """Test exceptions in reauth flow.""" + mock_autarco_client.get_account.side_effect = exception + mock_config_entry.add_to_hass(hass) + result = await mock_config_entry.start_reauth_flow(hass) + + assert result.get("type") is FlowResultType.FORM + assert result.get("step_id") == "reauth_confirm" + + result = await hass.config_entries.flow.async_configure( + result["flow_id"], + user_input={CONF_PASSWORD: "new-password"}, + ) + assert result.get("type") is FlowResultType.FORM + assert result.get("errors") == {"base": error} + + # Recover from error + mock_autarco_client.get_account.side_effect = None + + result = await hass.config_entries.flow.async_configure( + result["flow_id"], + user_input={CONF_PASSWORD: "new-password"}, + ) + assert result.get("type") is FlowResultType.ABORT + assert result.get("reason") == "reauth_successful" + + assert len(hass.config_entries.async_entries()) == 1 + assert mock_config_entry.data[CONF_PASSWORD] == "new-password" diff --git a/tests/components/autarco/test_init.py b/tests/components/autarco/test_init.py index 81c5f947251a80..2707c53d35f775 100644 --- a/tests/components/autarco/test_init.py +++ b/tests/components/autarco/test_init.py @@ -4,6 +4,8 @@ from unittest.mock import AsyncMock +from autarco import AutarcoAuthenticationError + from homeassistant.config_entries import ConfigEntryState from homeassistant.core import HomeAssistant @@ -26,3 +28,20 @@ async def test_load_unload_entry( await hass.async_block_till_done() assert mock_config_entry.state is ConfigEntryState.NOT_LOADED + + +async def test_setup_entry_exception( + hass: HomeAssistant, + mock_autarco_client: AsyncMock, + mock_config_entry: MockConfigEntry, +) -> None: + """Test ConfigEntryNotReady when API raises an exception during entry setup.""" + mock_config_entry.add_to_hass(hass) + mock_autarco_client.get_site.side_effect = AutarcoAuthenticationError + + await hass.config_entries.async_setup(mock_config_entry.entry_id) + assert mock_config_entry.state is ConfigEntryState.SETUP_ERROR + + flows = hass.config_entries.flow.async_progress() + assert len(flows) == 1 + assert flows[0]["step_id"] == "reauth_confirm" From 86f8b5893f7618d034a13cb951df08f96ceb5cc7 Mon Sep 17 00:00:00 2001 From: Joost Lekkerkerker Date: Sun, 1 Dec 2024 22:39:26 +0100 Subject: [PATCH 28/41] Bump yt-dlp to 2024.11.18 (#132026) --- homeassistant/components/media_extractor/manifest.json | 2 +- requirements_all.txt | 2 +- requirements_test_all.txt | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/media_extractor/manifest.json b/homeassistant/components/media_extractor/manifest.json index ebfa79d71902cb..866215839bf9ba 100644 --- a/homeassistant/components/media_extractor/manifest.json +++ b/homeassistant/components/media_extractor/manifest.json @@ -8,6 +8,6 @@ "iot_class": "calculated", "loggers": ["yt_dlp"], "quality_scale": "internal", - "requirements": ["yt-dlp[default]==2024.11.04"], + "requirements": ["yt-dlp[default]==2024.11.18"], "single_config_entry": true } diff --git a/requirements_all.txt b/requirements_all.txt index 56f9f56f061b77..35359d3744dcf7 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -3066,7 +3066,7 @@ youless-api==2.1.2 youtubeaio==1.1.5 # homeassistant.components.media_extractor -yt-dlp[default]==2024.11.04 +yt-dlp[default]==2024.11.18 # homeassistant.components.zamg zamg==0.3.6 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index a38e6629b3afb1..54d00b8585b62b 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -2455,7 +2455,7 @@ youless-api==2.1.2 youtubeaio==1.1.5 # homeassistant.components.media_extractor -yt-dlp[default]==2024.11.04 +yt-dlp[default]==2024.11.18 # homeassistant.components.zamg zamg==0.3.6 From b94a47ceb24507fe84f81e526b95aa1ce6896198 Mon Sep 17 00:00:00 2001 From: Joost Lekkerkerker Date: Sun, 1 Dec 2024 22:41:01 +0100 Subject: [PATCH 29/41] Change library to livisi (#132001) Co-authored-by: J. Nick Koston --- homeassistant/components/livisi/__init__.py | 2 +- homeassistant/components/livisi/climate.py | 2 +- homeassistant/components/livisi/config_flow.py | 3 ++- homeassistant/components/livisi/coordinator.py | 5 +++-- homeassistant/components/livisi/entity.py | 2 +- homeassistant/components/livisi/manifest.json | 2 +- requirements_all.txt | 6 +++--- requirements_test_all.txt | 6 +++--- tests/components/livisi/test_config_flow.py | 2 +- 9 files changed, 16 insertions(+), 14 deletions(-) diff --git a/homeassistant/components/livisi/__init__.py b/homeassistant/components/livisi/__init__.py index 26e36e68efa463..fc9e381a1c3a0f 100644 --- a/homeassistant/components/livisi/__init__.py +++ b/homeassistant/components/livisi/__init__.py @@ -5,7 +5,7 @@ from typing import Final from aiohttp import ClientConnectorError -from aiolivisi import AioLivisi +from livisi.aiolivisi import AioLivisi from homeassistant import core from homeassistant.config_entries import ConfigEntry diff --git a/homeassistant/components/livisi/climate.py b/homeassistant/components/livisi/climate.py index 56fe63d351f143..5d70936fc536ed 100644 --- a/homeassistant/components/livisi/climate.py +++ b/homeassistant/components/livisi/climate.py @@ -4,7 +4,7 @@ from typing import Any -from aiolivisi.const import CAPABILITY_CONFIG +from livisi.const import CAPABILITY_CONFIG from homeassistant.components.climate import ( ClimateEntity, diff --git a/homeassistant/components/livisi/config_flow.py b/homeassistant/components/livisi/config_flow.py index 7317aec0abc3a8..ce14c0e44e9a75 100644 --- a/homeassistant/components/livisi/config_flow.py +++ b/homeassistant/components/livisi/config_flow.py @@ -6,7 +6,8 @@ from typing import Any from aiohttp import ClientConnectorError -from aiolivisi import AioLivisi, errors as livisi_errors +from livisi import errors as livisi_errors +from livisi.aiolivisi import AioLivisi import voluptuous as vol from homeassistant.config_entries import ConfigFlow, ConfigFlowResult diff --git a/homeassistant/components/livisi/coordinator.py b/homeassistant/components/livisi/coordinator.py index 7cb5757310fd8d..b8b282c2829120 100644 --- a/homeassistant/components/livisi/coordinator.py +++ b/homeassistant/components/livisi/coordinator.py @@ -6,8 +6,9 @@ from typing import Any from aiohttp import ClientConnectorError -from aiolivisi import AioLivisi, LivisiEvent, Websocket -from aiolivisi.errors import TokenExpiredException +from livisi import LivisiEvent, Websocket +from livisi.aiolivisi import AioLivisi +from livisi.errors import TokenExpiredException from homeassistant.config_entries import ConfigEntry from homeassistant.const import CONF_HOST, CONF_PASSWORD diff --git a/homeassistant/components/livisi/entity.py b/homeassistant/components/livisi/entity.py index 3160b8f288a592..af588b0e3606a8 100644 --- a/homeassistant/components/livisi/entity.py +++ b/homeassistant/components/livisi/entity.py @@ -5,7 +5,7 @@ from collections.abc import Mapping from typing import Any -from aiolivisi.const import CAPABILITY_MAP +from livisi.const import CAPABILITY_MAP from homeassistant.config_entries import ConfigEntry from homeassistant.core import callback diff --git a/homeassistant/components/livisi/manifest.json b/homeassistant/components/livisi/manifest.json index e6f46324ed823f..25cc9d2e9c2b6d 100644 --- a/homeassistant/components/livisi/manifest.json +++ b/homeassistant/components/livisi/manifest.json @@ -5,5 +5,5 @@ "config_flow": true, "documentation": "https://www.home-assistant.io/integrations/livisi", "iot_class": "local_polling", - "requirements": ["aiolivisi==0.0.19"] + "requirements": ["livisi==0.0.22"] } diff --git a/requirements_all.txt b/requirements_all.txt index 35359d3744dcf7..7fa4cea354a495 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -288,9 +288,6 @@ aiolifx-themes==0.5.5 # homeassistant.components.lifx aiolifx==1.1.1 -# homeassistant.components.livisi -aiolivisi==0.0.19 - # homeassistant.components.lookin aiolookin==1.0.0 @@ -1312,6 +1309,9 @@ linear-garage-door==0.2.9 # homeassistant.components.linode linode-api==4.1.9b1 +# homeassistant.components.livisi +livisi==0.0.22 + # homeassistant.components.google_maps locationsharinglib==5.0.1 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index 54d00b8585b62b..f75507dfe5b310 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -270,9 +270,6 @@ aiolifx-themes==0.5.5 # homeassistant.components.lifx aiolifx==1.1.1 -# homeassistant.components.livisi -aiolivisi==0.0.19 - # homeassistant.components.lookin aiolookin==1.0.0 @@ -1093,6 +1090,9 @@ libsoundtouch==0.8 # homeassistant.components.linear_garage_door linear-garage-door==0.2.9 +# homeassistant.components.livisi +livisi==0.0.22 + # homeassistant.components.london_underground london-tube-status==0.5 diff --git a/tests/components/livisi/test_config_flow.py b/tests/components/livisi/test_config_flow.py index 9f492b9a45ac7f..cffae711d28a42 100644 --- a/tests/components/livisi/test_config_flow.py +++ b/tests/components/livisi/test_config_flow.py @@ -2,7 +2,7 @@ from unittest.mock import patch -from aiolivisi import errors as livisi_errors +from livisi import errors as livisi_errors import pytest from homeassistant.components.livisi.const import DOMAIN From b17b1f6db8bace2112589a1bb5c330c04e9841d7 Mon Sep 17 00:00:00 2001 From: Joost Lekkerkerker Date: Sun, 1 Dec 2024 23:05:34 +0100 Subject: [PATCH 30/41] Bump spotifyaio to 0.8.11 (#132032) --- homeassistant/components/spotify/manifest.json | 2 +- requirements_all.txt | 2 +- requirements_test_all.txt | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/spotify/manifest.json b/homeassistant/components/spotify/manifest.json index 6c5b7382bbbdae..27b8da7cecf0f1 100644 --- a/homeassistant/components/spotify/manifest.json +++ b/homeassistant/components/spotify/manifest.json @@ -8,6 +8,6 @@ "integration_type": "service", "iot_class": "cloud_polling", "loggers": ["spotifyaio"], - "requirements": ["spotifyaio==0.8.10"], + "requirements": ["spotifyaio==0.8.11"], "zeroconf": ["_spotify-connect._tcp.local."] } diff --git a/requirements_all.txt b/requirements_all.txt index 7fa4cea354a495..fb0e39176f5514 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -2719,7 +2719,7 @@ speak2mary==1.4.0 speedtest-cli==2.1.3 # homeassistant.components.spotify -spotifyaio==0.8.10 +spotifyaio==0.8.11 # homeassistant.components.sql sqlparse==0.5.0 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index f75507dfe5b310..e459093135efcf 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -2174,7 +2174,7 @@ speak2mary==1.4.0 speedtest-cli==2.1.3 # homeassistant.components.spotify -spotifyaio==0.8.10 +spotifyaio==0.8.11 # homeassistant.components.sql sqlparse==0.5.0 From c2e6f8e761e0555903fb4d3593be5fdc2f77bba3 Mon Sep 17 00:00:00 2001 From: Yazan AbdAl-Rahman Date: Mon, 2 Dec 2024 03:56:15 +0200 Subject: [PATCH 31/41] Improve service names and descriptions for 'remote_connect' and 'remote_disconnect' in Home Assistant Cloud (#131993) * Rename and reword 'remote_connect' and 'remote_disconnect' services for clarity * Trigger pipeline * Trigger pipeline * Trigger pipeline * Trigger pipeline * Apply suggestions from code review --------- Co-authored-by: Paulus Schoutsen --- homeassistant/components/cloud/strings.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/homeassistant/components/cloud/strings.json b/homeassistant/components/cloud/strings.json index 9f7e0dbadcdf81..1da91f6781340c 100644 --- a/homeassistant/components/cloud/strings.json +++ b/homeassistant/components/cloud/strings.json @@ -68,12 +68,12 @@ }, "services": { "remote_connect": { - "name": "Remote connect", - "description": "Makes the instance UI accessible from outside of the local network by using Home Assistant Cloud." + "name": "Enable remote access", + "description": "Makes the instance UI accessible from outside of the local network by enabling your Home Assistant Cloud connection." }, "remote_disconnect": { - "name": "Remote disconnect", - "description": "Disconnects the Home Assistant UI from the Home Assistant Cloud. You will no longer be able to access your Home Assistant instance from outside your local network." + "name": "Disable remote access", + "description": "Disconnects the instance UI from Home Assistant Cloud. This disables access to it from outside your local network." } } } From c6cd7e38f70f0e8106ad3e3709519cb5a88dfefe Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sun, 1 Dec 2024 20:05:45 -0600 Subject: [PATCH 32/41] Bump aiohttp to 3.11.9 (#132036) changelog: https://github.com/aio-libs/aiohttp/compare/v3.11.8...v3.11.9 --- homeassistant/package_constraints.txt | 2 +- pyproject.toml | 2 +- requirements.txt | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/homeassistant/package_constraints.txt b/homeassistant/package_constraints.txt index 5c0db0659d6a63..bf6730a9c75fd7 100644 --- a/homeassistant/package_constraints.txt +++ b/homeassistant/package_constraints.txt @@ -5,7 +5,7 @@ aiodiscover==2.1.0 aiodns==3.2.0 aiohasupervisor==0.2.1 aiohttp-fast-zlib==0.2.0 -aiohttp==3.11.8 +aiohttp==3.11.9 aiohttp_cors==0.7.0 aiozoneinfo==0.2.1 astral==2.2 diff --git a/pyproject.toml b/pyproject.toml index 2c143db77f68ee..ab9001cff42cd3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -29,7 +29,7 @@ dependencies = [ # change behavior based on presence of supervisor. Deprecated with #127228 # Lib can be removed with 2025.11 "aiohasupervisor==0.2.1", - "aiohttp==3.11.8", + "aiohttp==3.11.9", "aiohttp_cors==0.7.0", "aiohttp-fast-zlib==0.2.0", "aiozoneinfo==0.2.1", diff --git a/requirements.txt b/requirements.txt index 514ab132bc87ec..73153bd90cbc66 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,7 +5,7 @@ # Home Assistant Core aiodns==3.2.0 aiohasupervisor==0.2.1 -aiohttp==3.11.8 +aiohttp==3.11.9 aiohttp_cors==0.7.0 aiohttp-fast-zlib==0.2.0 aiozoneinfo==0.2.1 From b6458ff9b8d9336f3b6d43143df8b103eafdc89e Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sun, 1 Dec 2024 20:06:14 -0600 Subject: [PATCH 33/41] Bump cryptography to 44.0.0 and pyOpenSSL to 24.3.0 (#132035) These should be bumped together to make sure we do not have any incompatibility issues. > Note: The Python Cryptographic Authority strongly suggests the use of pyca/cryptography where possible. If you are using pyOpenSSL for anything other than making a TLS connection you should move to cryptography and drop your pyOpenSSL dependency. --- homeassistant/package_constraints.txt | 4 ++-- pyproject.toml | 4 ++-- requirements.txt | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/homeassistant/package_constraints.txt b/homeassistant/package_constraints.txt index bf6730a9c75fd7..f7b2ce8561d9ad 100644 --- a/homeassistant/package_constraints.txt +++ b/homeassistant/package_constraints.txt @@ -25,7 +25,7 @@ bluetooth-data-tools==1.20.0 cached-ipaddress==0.8.0 certifi>=2021.5.30 ciso8601==2.3.1 -cryptography==43.0.1 +cryptography==44.0.0 dbus-fast==2.24.3 fnv-hash-fast==1.0.2 go2rtc-client==0.1.1 @@ -50,7 +50,7 @@ psutil-home-assistant==0.0.1 PyJWT==2.10.0 pymicro-vad==1.0.1 PyNaCl==1.5.0 -pyOpenSSL==24.2.1 +pyOpenSSL==24.3.0 pyserial==3.5 pyspeex-noise==1.0.2 python-slugify==8.0.4 diff --git a/pyproject.toml b/pyproject.toml index ab9001cff42cd3..ec3fe8024d9db6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -55,10 +55,10 @@ dependencies = [ "lru-dict==1.3.0", "PyJWT==2.10.0", # PyJWT has loose dependency. We want the latest one. - "cryptography==43.0.1", + "cryptography==44.0.0", "Pillow==11.0.0", "propcache==0.2.1", - "pyOpenSSL==24.2.1", + "pyOpenSSL==24.3.0", "orjson==3.10.12", "packaging>=23.1", "psutil-home-assistant==0.0.1", diff --git a/requirements.txt b/requirements.txt index 73153bd90cbc66..0967b9b0618a1e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -26,10 +26,10 @@ ifaddr==0.2.0 Jinja2==3.1.4 lru-dict==1.3.0 PyJWT==2.10.0 -cryptography==43.0.1 +cryptography==44.0.0 Pillow==11.0.0 propcache==0.2.1 -pyOpenSSL==24.2.1 +pyOpenSSL==24.3.0 orjson==3.10.12 packaging>=23.1 psutil-home-assistant==0.0.1 From 782fff198cd1aaedbeeedb272973783693a418a5 Mon Sep 17 00:00:00 2001 From: Joost Lekkerkerker Date: Mon, 2 Dec 2024 03:17:07 +0100 Subject: [PATCH 34/41] Handle not found playlists in Spotify (#132033) * Handle not found playlists * Handle not found playlists * Handle not found playlists * Handle not found playlists * Handle not found playlists * Update homeassistant/components/spotify/coordinator.py --------- Co-authored-by: Paulus Schoutsen --- .../components/spotify/coordinator.py | 25 ++++- tests/components/spotify/test_media_player.py | 93 +++++++++++++++++++ 2 files changed, 114 insertions(+), 4 deletions(-) diff --git a/homeassistant/components/spotify/coordinator.py b/homeassistant/components/spotify/coordinator.py index a7c95e3124573b..099b1cb3ca857c 100644 --- a/homeassistant/components/spotify/coordinator.py +++ b/homeassistant/components/spotify/coordinator.py @@ -11,6 +11,7 @@ Playlist, SpotifyClient, SpotifyConnectionError, + SpotifyNotFoundError, UserProfile, ) @@ -62,6 +63,7 @@ def __init__(self, hass: HomeAssistant, client: SpotifyClient) -> None: ) self.client = client self._playlist: Playlist | None = None + self._checked_playlist_id: str | None = None async def _async_setup(self) -> None: """Set up the coordinator.""" @@ -87,15 +89,29 @@ async def _async_update_data(self) -> SpotifyCoordinatorData: dj_playlist = False if (context := current.context) is not None: - if self._playlist is None or self._playlist.uri != context.uri: + dj_playlist = context.uri == SPOTIFY_DJ_PLAYLIST_URI + if not ( + context.uri + in ( + self._checked_playlist_id, + SPOTIFY_DJ_PLAYLIST_URI, + ) + or (self._playlist is None and context.uri == self._checked_playlist_id) + ): + self._checked_playlist_id = context.uri self._playlist = None - if context.uri == SPOTIFY_DJ_PLAYLIST_URI: - dj_playlist = True - elif context.context_type == ContextType.PLAYLIST: + if context.context_type == ContextType.PLAYLIST: # Make sure any playlist lookups don't break the current # playback state update try: self._playlist = await self.client.get_playlist(context.uri) + except SpotifyNotFoundError: + _LOGGER.debug( + "Spotify playlist '%s' not found. " + "Most likely a Spotify-created playlist", + context.uri, + ) + self._playlist = None except SpotifyConnectionError: _LOGGER.debug( "Unable to load spotify playlist '%s'. " @@ -103,6 +119,7 @@ async def _async_update_data(self) -> SpotifyCoordinatorData: context.uri, ) self._playlist = None + self._checked_playlist_id = None return SpotifyCoordinatorData( current_playback=current, position_updated_at=position_updated_at, diff --git a/tests/components/spotify/test_media_player.py b/tests/components/spotify/test_media_player.py index b03424f8459cee..55e0ea8f1d8d3a 100644 --- a/tests/components/spotify/test_media_player.py +++ b/tests/components/spotify/test_media_player.py @@ -10,6 +10,7 @@ ProductType, RepeatMode as SpotifyRepeatMode, SpotifyConnectionError, + SpotifyNotFoundError, ) from syrupy import SnapshotAssertion @@ -142,6 +143,7 @@ async def test_spotify_dj_list( hass: HomeAssistant, mock_spotify: MagicMock, mock_config_entry: MockConfigEntry, + freezer: FrozenDateTimeFactory, ) -> None: """Test the Spotify entities with a Spotify DJ playlist.""" mock_spotify.return_value.get_playback.return_value.context.uri = ( @@ -152,12 +154,67 @@ async def test_spotify_dj_list( assert state assert state.attributes["media_playlist"] == "DJ" + mock_spotify.return_value.get_playlist.assert_not_called() + + freezer.tick(timedelta(seconds=30)) + async_fire_time_changed(hass) + await hass.async_block_till_done() + + state = hass.states.get("media_player.spotify_spotify_1") + assert state + assert state.attributes["media_playlist"] == "DJ" + + mock_spotify.return_value.get_playlist.assert_not_called() + + +@pytest.mark.usefixtures("setup_credentials") +async def test_normal_playlist( + hass: HomeAssistant, + mock_spotify: MagicMock, + freezer: FrozenDateTimeFactory, + mock_config_entry: MockConfigEntry, +) -> None: + """Test normal playlist switching.""" + await setup_integration(hass, mock_config_entry) + state = hass.states.get("media_player.spotify_spotify_1") + assert state + assert state.attributes["media_playlist"] == "Spotify Web API Testing playlist" + + mock_spotify.return_value.get_playlist.assert_called_once_with( + "spotify:user:rushofficial:playlist:2r35vbe6hHl6yDSMfjKgmm" + ) + + freezer.tick(timedelta(seconds=30)) + async_fire_time_changed(hass) + await hass.async_block_till_done() + + state = hass.states.get("media_player.spotify_spotify_1") + assert state + assert state.attributes["media_playlist"] == "Spotify Web API Testing playlist" + + mock_spotify.return_value.get_playlist.assert_called_once_with( + "spotify:user:rushofficial:playlist:2r35vbe6hHl6yDSMfjKgmm" + ) + + mock_spotify.return_value.get_playback.return_value.context.uri = ( + "spotify:playlist:123123123123123" + ) + + freezer.tick(timedelta(seconds=30)) + async_fire_time_changed(hass) + await hass.async_block_till_done() + + mock_spotify.return_value.get_playlist.assert_called_with( + "spotify:playlist:123123123123123" + ) + @pytest.mark.usefixtures("setup_credentials") async def test_fetching_playlist_does_not_fail( hass: HomeAssistant, mock_spotify: MagicMock, mock_config_entry: MockConfigEntry, + freezer: FrozenDateTimeFactory, ) -> None: """Test failing fetching playlist does not fail update.""" mock_spotify.return_value.get_playlist.side_effect = SpotifyConnectionError @@ -166,6 +223,42 @@ async def test_fetching_playlist_does_not_fail( assert state assert "media_playlist" not in state.attributes + mock_spotify.return_value.get_playlist.assert_called_once() + + freezer.tick(timedelta(seconds=30)) + async_fire_time_changed(hass) + await hass.async_block_till_done() + + assert mock_spotify.return_value.get_playlist.call_count == 2 + + +@pytest.mark.usefixtures("setup_credentials") +async def test_fetching_playlist_once( + hass: HomeAssistant, + mock_spotify: MagicMock, + mock_config_entry: MockConfigEntry, + freezer: FrozenDateTimeFactory, +) -> None: + """Test that not being able to find a playlist doesn't retry.""" + mock_spotify.return_value.get_playlist.side_effect = SpotifyNotFoundError + await setup_integration(hass, mock_config_entry) + + state = hass.states.get("media_player.spotify_spotify_1") + assert state + assert "media_playlist" not in state.attributes + + mock_spotify.return_value.get_playlist.assert_called_once() + + freezer.tick(timedelta(seconds=30)) + async_fire_time_changed(hass) + await hass.async_block_till_done() + + state = hass.states.get("media_player.spotify_spotify_1") + assert state + assert "media_playlist" not in state.attributes + + mock_spotify.return_value.get_playlist.assert_called_once() + @pytest.mark.usefixtures("setup_credentials") async def test_idle( From 80f28302a13f669e59a2b43e71efe0ebb16c353b Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sun, 1 Dec 2024 20:17:36 -0600 Subject: [PATCH 35/41] Bump yarl to 1.18.3 (#132025) changelog: https://github.com/aio-libs/yarl/compare/v1.18.0...v1.18.3 --- homeassistant/package_constraints.txt | 2 +- pyproject.toml | 2 +- requirements.txt | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/homeassistant/package_constraints.txt b/homeassistant/package_constraints.txt index f7b2ce8561d9ad..d85fa4293a31d9 100644 --- a/homeassistant/package_constraints.txt +++ b/homeassistant/package_constraints.txt @@ -70,7 +70,7 @@ voluptuous-openapi==0.0.5 voluptuous-serialize==2.6.0 voluptuous==0.15.2 webrtc-models==0.3.0 -yarl==1.18.0 +yarl==1.18.3 zeroconf==0.136.2 # Constrain pycryptodome to avoid vulnerability diff --git a/pyproject.toml b/pyproject.toml index ec3fe8024d9db6..9aa53920318d00 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -79,7 +79,7 @@ dependencies = [ "voluptuous==0.15.2", "voluptuous-serialize==2.6.0", "voluptuous-openapi==0.0.5", - "yarl==1.18.0", + "yarl==1.18.3", "webrtc-models==0.3.0", ] diff --git a/requirements.txt b/requirements.txt index 0967b9b0618a1e..d0e2be91a99e70 100644 --- a/requirements.txt +++ b/requirements.txt @@ -47,5 +47,5 @@ uv==0.5.4 voluptuous==0.15.2 voluptuous-serialize==2.6.0 voluptuous-openapi==0.0.5 -yarl==1.18.0 +yarl==1.18.3 webrtc-models==0.3.0 From 28eb4f3dff05a882cea97747d5ff13f9edef805a Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Mon, 2 Dec 2024 07:27:47 +0100 Subject: [PATCH 36/41] Use typed config entry in rainbird (#132031) * Use typed config entry in rainbird * Adjust --- homeassistant/components/rainbird/__init__.py | 7 +++---- homeassistant/components/rainbird/config_flow.py | 10 +++------- homeassistant/components/rainbird/coordinator.py | 4 ++-- homeassistant/components/rainbird/types.py | 9 ++++++++- 4 files changed, 16 insertions(+), 14 deletions(-) diff --git a/homeassistant/components/rainbird/__init__.py b/homeassistant/components/rainbird/__init__.py index db88902bc3ebfd..4827ac3e67ccf0 100644 --- a/homeassistant/components/rainbird/__init__.py +++ b/homeassistant/components/rainbird/__init__.py @@ -9,7 +9,6 @@ from pyrainbird.async_client import AsyncRainbirdClient, AsyncRainbirdController from pyrainbird.exceptions import RainbirdApiException, RainbirdAuthException -from homeassistant.config_entries import ConfigEntry from homeassistant.const import ( CONF_HOST, CONF_MAC, @@ -46,7 +45,7 @@ def _async_register_clientsession_shutdown( hass: HomeAssistant, - entry: ConfigEntry, + entry: RainbirdConfigEntry, clientsession: aiohttp.ClientSession, ) -> None: """Register cleanup hooks for the clientsession.""" @@ -126,7 +125,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: RainbirdConfigEntry) -> async def _async_fix_unique_id( - hass: HomeAssistant, controller: AsyncRainbirdController, entry: ConfigEntry + hass: HomeAssistant, controller: AsyncRainbirdController, entry: RainbirdConfigEntry ) -> bool: """Update the config entry with a unique id based on the mac address.""" _LOGGER.debug("Checking for migration of config entry (%s)", entry.unique_id) @@ -255,6 +254,6 @@ def _async_fix_device_id( ) -async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: +async def async_unload_entry(hass: HomeAssistant, entry: RainbirdConfigEntry) -> bool: """Unload a config entry.""" return await hass.config_entries.async_unload_platforms(entry, PLATFORMS) diff --git a/homeassistant/components/rainbird/config_flow.py b/homeassistant/components/rainbird/config_flow.py index 86a3c5d5d1c1c4..1390650ea022ee 100644 --- a/homeassistant/components/rainbird/config_flow.py +++ b/homeassistant/components/rainbird/config_flow.py @@ -12,17 +12,13 @@ from pyrainbird.exceptions import RainbirdApiException, RainbirdAuthException import voluptuous as vol -from homeassistant.config_entries import ( - ConfigEntry, - ConfigFlow, - ConfigFlowResult, - OptionsFlow, -) +from homeassistant.config_entries import ConfigFlow, ConfigFlowResult, OptionsFlow from homeassistant.const import CONF_HOST, CONF_MAC, CONF_PASSWORD from homeassistant.core import callback from homeassistant.helpers import config_validation as cv, selector from homeassistant.helpers.device_registry import format_mac +from . import RainbirdConfigEntry from .const import ( ATTR_DURATION, CONF_SERIAL_NUMBER, @@ -69,7 +65,7 @@ class RainbirdConfigFlowHandler(ConfigFlow, domain=DOMAIN): @staticmethod @callback def async_get_options_flow( - config_entry: ConfigEntry, + config_entry: RainbirdConfigEntry, ) -> RainBirdOptionsFlowHandler: """Define the config flow to handle options.""" return RainBirdOptionsFlowHandler() diff --git a/homeassistant/components/rainbird/coordinator.py b/homeassistant/components/rainbird/coordinator.py index 437aa7ddbd407a..2ccfa0af62a3f8 100644 --- a/homeassistant/components/rainbird/coordinator.py +++ b/homeassistant/components/rainbird/coordinator.py @@ -15,13 +15,13 @@ ) from pyrainbird.data import ModelAndVersion, Schedule -from homeassistant.config_entries import ConfigEntry from homeassistant.core import HomeAssistant from homeassistant.helpers.debounce import Debouncer from homeassistant.helpers.device_registry import DeviceInfo from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed from .const import DOMAIN, MANUFACTURER, TIMEOUT_SECONDS +from .types import RainbirdConfigEntry UPDATE_INTERVAL = datetime.timedelta(minutes=1) # The calendar data requires RPCs for each program/zone, and the data rarely @@ -140,7 +140,7 @@ async def _fetch_data(self) -> RainbirdDeviceState: class RainbirdScheduleUpdateCoordinator(DataUpdateCoordinator[Schedule]): """Coordinator for rainbird irrigation schedule calls.""" - config_entry: ConfigEntry + config_entry: RainbirdConfigEntry def __init__( self, diff --git a/homeassistant/components/rainbird/types.py b/homeassistant/components/rainbird/types.py index b452712d971335..cc43353ac171a6 100644 --- a/homeassistant/components/rainbird/types.py +++ b/homeassistant/components/rainbird/types.py @@ -1,13 +1,20 @@ """Types for Rain Bird integration.""" +from __future__ import annotations + from dataclasses import dataclass +from typing import TYPE_CHECKING from pyrainbird.async_client import AsyncRainbirdController from pyrainbird.data import ModelAndVersion from homeassistant.config_entries import ConfigEntry -from .coordinator import RainbirdScheduleUpdateCoordinator, RainbirdUpdateCoordinator +if TYPE_CHECKING: + from .coordinator import ( + RainbirdScheduleUpdateCoordinator, + RainbirdUpdateCoordinator, + ) @dataclass From 5458ee2fa9864869b06814f57b24cf6268d19b92 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Mon, 2 Dec 2024 07:28:29 +0100 Subject: [PATCH 37/41] Use typed config entry in imap (#132029) * Use typed config entry in imap * Adjust --- homeassistant/components/imap/config_flow.py | 10 +++------- homeassistant/components/imap/coordinator.py | 12 +++++++----- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/homeassistant/components/imap/config_flow.py b/homeassistant/components/imap/config_flow.py index 994c53b5b3e84f..df0e63e200a0a8 100644 --- a/homeassistant/components/imap/config_flow.py +++ b/homeassistant/components/imap/config_flow.py @@ -9,12 +9,7 @@ from aioimaplib import AioImapException import voluptuous as vol -from homeassistant.config_entries import ( - ConfigEntry, - ConfigFlow, - ConfigFlowResult, - OptionsFlow, -) +from homeassistant.config_entries import ConfigFlow, ConfigFlowResult, OptionsFlow from homeassistant.const import ( CONF_NAME, CONF_PASSWORD, @@ -35,6 +30,7 @@ ) from homeassistant.util.ssl import SSLCipherList +from . import ImapConfigEntry from .const import ( CONF_CHARSET, CONF_CUSTOM_EVENT_DATA_TEMPLATE, @@ -212,7 +208,7 @@ async def async_step_reauth_confirm( @staticmethod @callback def async_get_options_flow( - config_entry: ConfigEntry, + config_entry: ImapConfigEntry, ) -> ImapOptionsFlow: """Get the options flow for this handler.""" return ImapOptionsFlow() diff --git a/homeassistant/components/imap/coordinator.py b/homeassistant/components/imap/coordinator.py index a9d0fdfbd48a59..41fd703d79bf49 100644 --- a/homeassistant/components/imap/coordinator.py +++ b/homeassistant/components/imap/coordinator.py @@ -14,7 +14,6 @@ from aioimaplib import AUTH, IMAP4_SSL, NONAUTH, SELECTED, AioImapException -from homeassistant.config_entries import ConfigEntry from homeassistant.const import ( CONF_PASSWORD, CONF_PORT, @@ -53,6 +52,9 @@ ) from .errors import InvalidAuth, InvalidFolder +if TYPE_CHECKING: + from . import ImapConfigEntry + _LOGGER = logging.getLogger(__name__) BACKOFF_TIME = 10 @@ -210,14 +212,14 @@ def text(self) -> str: class ImapDataUpdateCoordinator(DataUpdateCoordinator[int | None]): """Base class for imap client.""" - config_entry: ConfigEntry + config_entry: ImapConfigEntry custom_event_template: Template | None def __init__( self, hass: HomeAssistant, imap_client: IMAP4_SSL, - entry: ConfigEntry, + entry: ImapConfigEntry, update_interval: timedelta | None, ) -> None: """Initiate imap client.""" @@ -391,7 +393,7 @@ class ImapPollingDataUpdateCoordinator(ImapDataUpdateCoordinator): """Class for imap client.""" def __init__( - self, hass: HomeAssistant, imap_client: IMAP4_SSL, entry: ConfigEntry + self, hass: HomeAssistant, imap_client: IMAP4_SSL, entry: ImapConfigEntry ) -> None: """Initiate imap client.""" _LOGGER.debug( @@ -437,7 +439,7 @@ class ImapPushDataUpdateCoordinator(ImapDataUpdateCoordinator): """Class for imap client.""" def __init__( - self, hass: HomeAssistant, imap_client: IMAP4_SSL, entry: ConfigEntry + self, hass: HomeAssistant, imap_client: IMAP4_SSL, entry: ImapConfigEntry ) -> None: """Initiate imap client.""" _LOGGER.debug("Connected to server %s using IMAP push", entry.data[CONF_SERVER]) From 4eb5734d73ee601bbd6223941ea12e8ffe0b3583 Mon Sep 17 00:00:00 2001 From: dontinelli <73341522+dontinelli@users.noreply.github.com> Date: Mon, 2 Dec 2024 07:39:48 +0100 Subject: [PATCH 38/41] Remove CONF_NAME from config entry in solarlog (#131738) * Remove CONF_NAME from config entry * Remove name from strings.json --- .../components/solarlog/config_flow.py | 17 ++----- homeassistant/components/solarlog/const.py | 1 - .../components/solarlog/coordinator.py | 1 - homeassistant/components/solarlog/entity.py | 2 +- .../components/solarlog/strings.json | 1 - tests/components/solarlog/conftest.py | 5 +- tests/components/solarlog/const.py | 1 - .../solarlog/snapshots/test_diagnostics.ambr | 1 - .../solarlog/snapshots/test_sensor.ambr | 46 +++++++++---------- tests/components/solarlog/test_config_flow.py | 40 +++++++--------- tests/components/solarlog/test_init.py | 4 +- 11 files changed, 49 insertions(+), 70 deletions(-) diff --git a/homeassistant/components/solarlog/config_flow.py b/homeassistant/components/solarlog/config_flow.py index a61f825aa5e84d..767079ea1f8532 100644 --- a/homeassistant/components/solarlog/config_flow.py +++ b/homeassistant/components/solarlog/config_flow.py @@ -1,7 +1,6 @@ """Config flow for solarlog integration.""" from collections.abc import Mapping -import logging from typing import Any from urllib.parse import ParseResult, urlparse @@ -14,12 +13,9 @@ import voluptuous as vol from homeassistant.config_entries import ConfigFlow, ConfigFlowResult -from homeassistant.const import CONF_HOST, CONF_NAME, CONF_PASSWORD -from homeassistant.util import slugify +from homeassistant.const import CONF_HOST, CONF_PASSWORD -from .const import CONF_HAS_PWD, DEFAULT_HOST, DEFAULT_NAME, DOMAIN - -_LOGGER = logging.getLogger(__name__) +from .const import CONF_HAS_PWD, DEFAULT_HOST, DOMAIN class SolarLogConfigFlow(ConfigFlow, domain=DOMAIN): @@ -84,24 +80,21 @@ async def async_step_user( self._async_abort_entries_match({CONF_HOST: user_input[CONF_HOST]}) - user_input[CONF_NAME] = slugify(user_input[CONF_NAME]) - if await self._test_connection(user_input[CONF_HOST]): if user_input[CONF_HAS_PWD]: self._user_input = user_input return await self.async_step_password() return self.async_create_entry( - title=user_input[CONF_NAME], data=user_input + title=user_input[CONF_HOST], data=user_input ) else: - user_input = {CONF_NAME: DEFAULT_NAME, CONF_HOST: DEFAULT_HOST} + user_input = {CONF_HOST: DEFAULT_HOST} return self.async_show_form( step_id="user", data_schema=vol.Schema( { - vol.Required(CONF_NAME, default=user_input[CONF_NAME]): str, vol.Required(CONF_HOST, default=user_input[CONF_HOST]): str, vol.Required(CONF_HAS_PWD, default=False): bool, } @@ -120,7 +113,7 @@ async def async_step_password( ): self._user_input |= user_input return self.async_create_entry( - title=self._user_input[CONF_NAME], data=self._user_input + title=self._user_input[CONF_HOST], data=self._user_input ) else: user_input = {CONF_PASSWORD: ""} diff --git a/homeassistant/components/solarlog/const.py b/homeassistant/components/solarlog/const.py index f86d103f8306e0..3e814705589a84 100644 --- a/homeassistant/components/solarlog/const.py +++ b/homeassistant/components/solarlog/const.py @@ -6,6 +6,5 @@ # Default config for solarlog. DEFAULT_HOST = "http://solar-log" -DEFAULT_NAME = "solarlog" CONF_HAS_PWD = "has_password" diff --git a/homeassistant/components/solarlog/coordinator.py b/homeassistant/components/solarlog/coordinator.py index 6e8867c0f5225f..11f268db32a57d 100644 --- a/homeassistant/components/solarlog/coordinator.py +++ b/homeassistant/components/solarlog/coordinator.py @@ -52,7 +52,6 @@ def __init__(self, hass: HomeAssistant, entry: SolarlogConfigEntry) -> None: path = url.path if url.netloc else "" url = ParseResult("http", netloc, path, *url[3:]) self.unique_id = entry.entry_id - self.name = entry.title self.host = url.geturl() self.solarlog = SolarLogConnector( diff --git a/homeassistant/components/solarlog/entity.py b/homeassistant/components/solarlog/entity.py index b0f3ddf99f9e01..bfdc52dccf17ec 100644 --- a/homeassistant/components/solarlog/entity.py +++ b/homeassistant/components/solarlog/entity.py @@ -43,7 +43,7 @@ def __init__( manufacturer="Solar-Log", model="Controller", identifiers={(DOMAIN, coordinator.unique_id)}, - name=coordinator.name, + name="SolarLog", configuration_url=coordinator.host, ) diff --git a/homeassistant/components/solarlog/strings.json b/homeassistant/components/solarlog/strings.json index fb724c02adb611..bbd9b509ecf9f3 100644 --- a/homeassistant/components/solarlog/strings.json +++ b/homeassistant/components/solarlog/strings.json @@ -5,7 +5,6 @@ "title": "Define your Solar-Log connection", "data": { "host": "[%key:common::config_flow::data::host%]", - "name": "The prefix to be used for your Solar-Log sensors", "has_password": "I have the password for the Solar-Log user account." }, "data_description": { diff --git a/tests/components/solarlog/conftest.py b/tests/components/solarlog/conftest.py index 2d4b4e32522fb4..caa3621b9bb21d 100644 --- a/tests/components/solarlog/conftest.py +++ b/tests/components/solarlog/conftest.py @@ -10,9 +10,9 @@ CONF_HAS_PWD, DOMAIN as SOLARLOG_DOMAIN, ) -from homeassistant.const import CONF_HOST, CONF_NAME, CONF_PASSWORD +from homeassistant.const import CONF_HOST, CONF_PASSWORD -from .const import HOST, NAME +from .const import HOST from tests.common import MockConfigEntry, load_json_object_fixture @@ -38,7 +38,6 @@ def mock_config_entry() -> MockConfigEntry: title="solarlog", data={ CONF_HOST: HOST, - CONF_NAME: NAME, CONF_HAS_PWD: True, CONF_PASSWORD: "pwd", }, diff --git a/tests/components/solarlog/const.py b/tests/components/solarlog/const.py index e23633c80aeece..1294a376b012c7 100644 --- a/tests/components/solarlog/const.py +++ b/tests/components/solarlog/const.py @@ -1,4 +1,3 @@ """Common const used across tests for SolarLog.""" -NAME = "Solarlog test 1 2 3" HOST = "http://1.1.1.1" diff --git a/tests/components/solarlog/snapshots/test_diagnostics.ambr b/tests/components/solarlog/snapshots/test_diagnostics.ambr index 4b37ea63dce735..e0f1bc2623c5bd 100644 --- a/tests/components/solarlog/snapshots/test_diagnostics.ambr +++ b/tests/components/solarlog/snapshots/test_diagnostics.ambr @@ -5,7 +5,6 @@ 'data': dict({ 'has_password': True, 'host': '**REDACTED**', - 'name': 'Solarlog test 1 2 3', 'password': 'pwd', }), 'disabled_by': None, diff --git a/tests/components/solarlog/snapshots/test_sensor.ambr b/tests/components/solarlog/snapshots/test_sensor.ambr index 32be560fc629ca..06bc01f9d39e9f 100644 --- a/tests/components/solarlog/snapshots/test_sensor.ambr +++ b/tests/components/solarlog/snapshots/test_sensor.ambr @@ -254,7 +254,7 @@ StateSnapshot({ 'attributes': ReadOnlyDict({ 'device_class': 'power', - 'friendly_name': 'solarlog Alternator loss', + 'friendly_name': 'SolarLog Alternator loss', 'state_class': , 'unit_of_measurement': , }), @@ -308,7 +308,7 @@ StateSnapshot({ 'attributes': ReadOnlyDict({ 'device_class': 'power_factor', - 'friendly_name': 'solarlog Capacity', + 'friendly_name': 'SolarLog Capacity', 'state_class': , 'unit_of_measurement': '%', }), @@ -359,7 +359,7 @@ StateSnapshot({ 'attributes': ReadOnlyDict({ 'device_class': 'power', - 'friendly_name': 'solarlog Consumption AC', + 'friendly_name': 'SolarLog Consumption AC', 'state_class': , 'unit_of_measurement': , }), @@ -416,7 +416,7 @@ StateSnapshot({ 'attributes': ReadOnlyDict({ 'device_class': 'energy', - 'friendly_name': 'solarlog Consumption day', + 'friendly_name': 'SolarLog Consumption day', 'state_class': , 'unit_of_measurement': , }), @@ -473,7 +473,7 @@ StateSnapshot({ 'attributes': ReadOnlyDict({ 'device_class': 'energy', - 'friendly_name': 'solarlog Consumption month', + 'friendly_name': 'SolarLog Consumption month', 'state_class': , 'unit_of_measurement': , }), @@ -530,7 +530,7 @@ StateSnapshot({ 'attributes': ReadOnlyDict({ 'device_class': 'energy', - 'friendly_name': 'solarlog Consumption total', + 'friendly_name': 'SolarLog Consumption total', 'state_class': , 'unit_of_measurement': , }), @@ -587,7 +587,7 @@ StateSnapshot({ 'attributes': ReadOnlyDict({ 'device_class': 'energy', - 'friendly_name': 'solarlog Consumption year', + 'friendly_name': 'SolarLog Consumption year', 'state_class': , 'unit_of_measurement': , }), @@ -642,7 +642,7 @@ StateSnapshot({ 'attributes': ReadOnlyDict({ 'device_class': 'energy', - 'friendly_name': 'solarlog Consumption yesterday', + 'friendly_name': 'SolarLog Consumption yesterday', 'unit_of_measurement': , }), 'context': , @@ -695,7 +695,7 @@ StateSnapshot({ 'attributes': ReadOnlyDict({ 'device_class': 'power_factor', - 'friendly_name': 'solarlog Efficiency', + 'friendly_name': 'SolarLog Efficiency', 'state_class': , 'unit_of_measurement': '%', }), @@ -746,7 +746,7 @@ StateSnapshot({ 'attributes': ReadOnlyDict({ 'device_class': 'power', - 'friendly_name': 'solarlog Installed peak power', + 'friendly_name': 'SolarLog Installed peak power', 'state_class': , 'unit_of_measurement': , }), @@ -795,7 +795,7 @@ StateSnapshot({ 'attributes': ReadOnlyDict({ 'device_class': 'timestamp', - 'friendly_name': 'solarlog Last update', + 'friendly_name': 'SolarLog Last update', }), 'context': , 'entity_id': 'sensor.solarlog_last_update', @@ -844,7 +844,7 @@ StateSnapshot({ 'attributes': ReadOnlyDict({ 'device_class': 'power', - 'friendly_name': 'solarlog Power AC', + 'friendly_name': 'SolarLog Power AC', 'state_class': , 'unit_of_measurement': , }), @@ -895,7 +895,7 @@ StateSnapshot({ 'attributes': ReadOnlyDict({ 'device_class': 'power', - 'friendly_name': 'solarlog Power available', + 'friendly_name': 'SolarLog Power available', 'state_class': , 'unit_of_measurement': , }), @@ -946,7 +946,7 @@ StateSnapshot({ 'attributes': ReadOnlyDict({ 'device_class': 'power', - 'friendly_name': 'solarlog Power DC', + 'friendly_name': 'SolarLog Power DC', 'state_class': , 'unit_of_measurement': , }), @@ -997,7 +997,7 @@ StateSnapshot({ 'attributes': ReadOnlyDict({ 'device_class': 'energy', - 'friendly_name': 'solarlog Self-consumption year', + 'friendly_name': 'SolarLog Self-consumption year', 'state_class': , 'unit_of_measurement': , }), @@ -1051,7 +1051,7 @@ StateSnapshot({ 'attributes': ReadOnlyDict({ 'device_class': 'power_factor', - 'friendly_name': 'solarlog Usage', + 'friendly_name': 'SolarLog Usage', 'state_class': , 'unit_of_measurement': '%', }), @@ -1102,7 +1102,7 @@ StateSnapshot({ 'attributes': ReadOnlyDict({ 'device_class': 'voltage', - 'friendly_name': 'solarlog Voltage AC', + 'friendly_name': 'SolarLog Voltage AC', 'state_class': , 'unit_of_measurement': , }), @@ -1153,7 +1153,7 @@ StateSnapshot({ 'attributes': ReadOnlyDict({ 'device_class': 'voltage', - 'friendly_name': 'solarlog Voltage DC', + 'friendly_name': 'SolarLog Voltage DC', 'state_class': , 'unit_of_measurement': , }), @@ -1210,7 +1210,7 @@ StateSnapshot({ 'attributes': ReadOnlyDict({ 'device_class': 'energy', - 'friendly_name': 'solarlog Yield day', + 'friendly_name': 'SolarLog Yield day', 'state_class': , 'unit_of_measurement': , }), @@ -1267,7 +1267,7 @@ StateSnapshot({ 'attributes': ReadOnlyDict({ 'device_class': 'energy', - 'friendly_name': 'solarlog Yield month', + 'friendly_name': 'SolarLog Yield month', 'state_class': , 'unit_of_measurement': , }), @@ -1324,7 +1324,7 @@ StateSnapshot({ 'attributes': ReadOnlyDict({ 'device_class': 'energy', - 'friendly_name': 'solarlog Yield total', + 'friendly_name': 'SolarLog Yield total', 'state_class': , 'unit_of_measurement': , }), @@ -1378,7 +1378,7 @@ StateSnapshot({ 'attributes': ReadOnlyDict({ 'device_class': 'energy', - 'friendly_name': 'solarlog Yield year', + 'friendly_name': 'SolarLog Yield year', 'state_class': , 'unit_of_measurement': , }), @@ -1433,7 +1433,7 @@ StateSnapshot({ 'attributes': ReadOnlyDict({ 'device_class': 'energy', - 'friendly_name': 'solarlog Yield yesterday', + 'friendly_name': 'SolarLog Yield yesterday', 'unit_of_measurement': , }), 'context': , diff --git a/tests/components/solarlog/test_config_flow.py b/tests/components/solarlog/test_config_flow.py index 8a34407ff5484d..3de3c08fcd0079 100644 --- a/tests/components/solarlog/test_config_flow.py +++ b/tests/components/solarlog/test_config_flow.py @@ -12,11 +12,11 @@ from homeassistant.components.solarlog import config_flow from homeassistant.components.solarlog.const import CONF_HAS_PWD, DOMAIN from homeassistant.config_entries import SOURCE_USER -from homeassistant.const import CONF_HOST, CONF_NAME, CONF_PASSWORD +from homeassistant.const import CONF_HOST, CONF_PASSWORD from homeassistant.core import HomeAssistant from homeassistant.data_entry_flow import FlowResultType -from .const import HOST, NAME +from .const import HOST from tests.common import MockConfigEntry @@ -33,12 +33,12 @@ async def test_form(hass: HomeAssistant, mock_setup_entry: AsyncMock) -> None: result2 = await hass.config_entries.flow.async_configure( result["flow_id"], - {CONF_HOST: HOST, CONF_NAME: NAME, CONF_HAS_PWD: False}, + {CONF_HOST: HOST, CONF_HAS_PWD: False}, ) await hass.async_block_till_done() assert result2["type"] is FlowResultType.CREATE_ENTRY - assert result2["title"] == "solarlog_test_1_2_3" + assert result2["title"] == HOST assert result2["data"][CONF_HOST] == "http://1.1.1.1" assert result2["data"][CONF_HAS_PWD] is False assert len(mock_setup_entry.mock_calls) == 1 @@ -66,12 +66,12 @@ async def test_user( # tests with all provided result = await hass.config_entries.flow.async_configure( - result["flow_id"], {CONF_HOST: HOST, CONF_NAME: NAME, CONF_HAS_PWD: False} + result["flow_id"], {CONF_HOST: HOST, CONF_HAS_PWD: False} ) await hass.async_block_till_done() assert result["type"] is FlowResultType.CREATE_ENTRY - assert result["title"] == "solarlog_test_1_2_3" + assert result["title"] == HOST assert result["data"][CONF_HOST] == HOST assert len(mock_setup_entry.mock_calls) == 1 @@ -106,9 +106,7 @@ async def test_form_exceptions( mock_solarlog_connector.test_connection.side_effect = exception1 # tests with connection error - result = await flow.async_step_user( - {CONF_NAME: NAME, CONF_HOST: HOST, CONF_HAS_PWD: False} - ) + result = await flow.async_step_user({CONF_HOST: HOST, CONF_HAS_PWD: False}) await hass.async_block_till_done() assert result["type"] is FlowResultType.FORM @@ -119,9 +117,7 @@ async def test_form_exceptions( mock_solarlog_connector.test_connection.side_effect = None mock_solarlog_connector.test_extended_data_available.side_effect = exception2 - result = await flow.async_step_user( - {CONF_NAME: NAME, CONF_HOST: HOST, CONF_HAS_PWD: True} - ) + result = await flow.async_step_user({CONF_HOST: HOST, CONF_HAS_PWD: True}) await hass.async_block_till_done() assert result["type"] is FlowResultType.FORM @@ -137,13 +133,11 @@ async def test_form_exceptions( mock_solarlog_connector.test_extended_data_available.side_effect = None # tests with all provided (no password) - result = await flow.async_step_user( - {CONF_NAME: NAME, CONF_HOST: HOST, CONF_HAS_PWD: False} - ) + result = await flow.async_step_user({CONF_HOST: HOST, CONF_HAS_PWD: False}) await hass.async_block_till_done() assert result["type"] is FlowResultType.CREATE_ENTRY - assert result["title"] == "solarlog_test_1_2_3" + assert result["title"] == HOST assert result["data"][CONF_HOST] == HOST assert result["data"][CONF_HAS_PWD] is False @@ -152,16 +146,14 @@ async def test_form_exceptions( await hass.async_block_till_done() assert result["type"] is FlowResultType.CREATE_ENTRY - assert result["title"] == "solarlog_test_1_2_3" + assert result["title"] == HOST assert result["data"][CONF_PASSWORD] == "pwd" async def test_abort_if_already_setup(hass: HomeAssistant, test_connect: None) -> None: """Test we abort if the device is already setup.""" - MockConfigEntry(domain=DOMAIN, data={CONF_NAME: NAME, CONF_HOST: HOST}).add_to_hass( - hass - ) + MockConfigEntry(domain=DOMAIN, data={CONF_HOST: HOST}).add_to_hass(hass) result = await hass.config_entries.flow.async_init( DOMAIN, context={"source": SOURCE_USER} @@ -173,7 +165,7 @@ async def test_abort_if_already_setup(hass: HomeAssistant, test_connect: None) - result = await hass.config_entries.flow.async_configure( result["flow_id"], - {CONF_HOST: HOST, CONF_NAME: "solarlog_test_7_8_9", CONF_HAS_PWD: False}, + {CONF_HOST: HOST, CONF_HAS_PWD: False}, ) assert result["type"] is FlowResultType.ABORT assert result["reason"] == "already_configured" @@ -196,7 +188,7 @@ async def test_reconfigure_flow( """Test config flow options.""" entry = MockConfigEntry( domain=DOMAIN, - title="solarlog_test_1_2_3", + title=HOST, data={ CONF_HOST: HOST, CONF_HAS_PWD: False, @@ -221,7 +213,7 @@ async def test_reconfigure_flow( entry = hass.config_entries.async_get_entry(entry.entry_id) assert entry - assert entry.title == "solarlog_test_1_2_3" + assert entry.title == HOST assert entry.data[CONF_HAS_PWD] == has_password assert entry.data[CONF_PASSWORD] == password @@ -244,7 +236,7 @@ async def test_reauth( entry = MockConfigEntry( domain=DOMAIN, - title="solarlog_test_1_2_3", + title=HOST, data={ CONF_HOST: HOST, CONF_HAS_PWD: True, diff --git a/tests/components/solarlog/test_init.py b/tests/components/solarlog/test_init.py index b4ef270e78bcb2..a9a595f8962b3d 100644 --- a/tests/components/solarlog/test_init.py +++ b/tests/components/solarlog/test_init.py @@ -19,7 +19,7 @@ from homeassistant.helpers.entity_registry import EntityRegistry from . import setup_platform -from .const import HOST, NAME +from .const import HOST from tests.common import MockConfigEntry @@ -140,7 +140,7 @@ async def test_migrate_config_entry( """Test successful migration of entry data.""" entry = MockConfigEntry( domain=DOMAIN, - title=NAME, + title=HOST, data={ CONF_HOST: HOST, }, From 4eb75a56e60a0c3e3a7879549ef82691120e0835 Mon Sep 17 00:00:00 2001 From: Andrew Sayre <6730289+andrewsayre@users.noreply.github.com> Date: Mon, 2 Dec 2024 01:19:43 -0600 Subject: [PATCH 39/41] Use runtime data in HEOS (#132030) * Adopt runtime_data * Fix missing variable assignment * Address PR feedback --- homeassistant/components/heos/__init__.py | 70 ++++++++++--------- homeassistant/components/heos/const.py | 4 -- homeassistant/components/heos/media_player.py | 43 +++++------- tests/components/heos/test_init.py | 21 ++---- tests/components/heos/test_media_player.py | 12 ++-- 5 files changed, 62 insertions(+), 88 deletions(-) diff --git a/homeassistant/components/heos/__init__.py b/homeassistant/components/heos/__init__.py index 1573ff3f23e801..de56e541501f8c 100644 --- a/homeassistant/components/heos/__init__.py +++ b/homeassistant/components/heos/__init__.py @@ -3,10 +3,11 @@ from __future__ import annotations import asyncio +from dataclasses import dataclass from datetime import timedelta import logging -from pyheos import Heos, HeosError, const as heos_const +from pyheos import Heos, HeosError, HeosPlayer, const as heos_const import voluptuous as vol from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry @@ -27,10 +28,6 @@ from .const import ( COMMAND_RETRY_ATTEMPTS, COMMAND_RETRY_DELAY, - DATA_CONTROLLER_MANAGER, - DATA_ENTITY_ID_MAP, - DATA_GROUP_MANAGER, - DATA_SOURCE_MANAGER, DOMAIN, SIGNAL_HEOS_PLAYER_ADDED, SIGNAL_HEOS_UPDATED, @@ -51,6 +48,19 @@ _LOGGER = logging.getLogger(__name__) +@dataclass +class HeosRuntimeData: + """Runtime data and coordinators for HEOS config entries.""" + + controller_manager: ControllerManager + group_manager: GroupManager + source_manager: SourceManager + players: dict[int, HeosPlayer] + + +type HeosConfigEntry = ConfigEntry[HeosRuntimeData] + + async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: """Set up the HEOS component.""" if DOMAIN not in config: @@ -75,7 +85,7 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: return True -async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: +async def async_setup_entry(hass: HomeAssistant, entry: HeosConfigEntry) -> bool: """Initialize config entry which represents the HEOS controller.""" # For backwards compat if entry.unique_id is None: @@ -128,17 +138,11 @@ async def disconnect_controller(event): source_manager = SourceManager(favorites, inputs) source_manager.connect_update(hass, controller) - group_manager = GroupManager(hass, controller) + group_manager = GroupManager(hass, controller, players) - hass.data[DOMAIN] = { - DATA_CONTROLLER_MANAGER: controller_manager, - DATA_GROUP_MANAGER: group_manager, - DATA_SOURCE_MANAGER: source_manager, - Platform.MEDIA_PLAYER: players, - # Maps player_id to entity_id. Populated by the individual - # HeosMediaPlayer entities. - DATA_ENTITY_ID_MAP: {}, - } + entry.runtime_data = HeosRuntimeData( + controller_manager, group_manager, source_manager, players + ) services.register(hass, controller) group_manager.connect_update() @@ -149,11 +153,9 @@ async def disconnect_controller(event): return True -async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: +async def async_unload_entry(hass: HomeAssistant, entry: HeosConfigEntry) -> bool: """Unload a config entry.""" - controller_manager = hass.data[DOMAIN][DATA_CONTROLLER_MANAGER] - await controller_manager.disconnect() - hass.data.pop(DOMAIN) + await entry.runtime_data.controller_manager.disconnect() services.remove(hass) @@ -246,21 +248,25 @@ def update_ids(self, mapped_ids: dict[int, int]): class GroupManager: """Class that manages HEOS groups.""" - def __init__(self, hass, controller): + def __init__( + self, hass: HomeAssistant, controller: Heos, players: dict[int, HeosPlayer] + ) -> None: """Init group manager.""" self._hass = hass - self._group_membership = {} + self._group_membership: dict[str, str] = {} self._disconnect_player_added = None self._initialized = False self.controller = controller + self.players = players + self.entity_id_map: dict[int, str] = {} def _get_entity_id_to_player_id_map(self) -> dict: """Return mapping of all HeosMediaPlayer entity_ids to player_ids.""" - return {v: k for k, v in self._hass.data[DOMAIN][DATA_ENTITY_ID_MAP].items()} + return {v: k for k, v in self.entity_id_map.items()} - async def async_get_group_membership(self): + async def async_get_group_membership(self) -> dict[str, list[str]]: """Return all group members for each player as entity_ids.""" - group_info_by_entity_id = { + group_info_by_entity_id: dict[str, list[str]] = { player_entity_id: [] for player_entity_id in self._get_entity_id_to_player_id_map() } @@ -271,7 +277,7 @@ async def async_get_group_membership(self): _LOGGER.error("Unable to get HEOS group info: %s", err) return group_info_by_entity_id - player_id_to_entity_id_map = self._hass.data[DOMAIN][DATA_ENTITY_ID_MAP] + player_id_to_entity_id_map = self.entity_id_map for group in groups.values(): leader_entity_id = player_id_to_entity_id_map.get(group.leader.player_id) member_entity_ids = [ @@ -282,9 +288,9 @@ async def async_get_group_membership(self): # Make sure the group leader is always the first element group_info = [leader_entity_id, *member_entity_ids] if leader_entity_id: - group_info_by_entity_id[leader_entity_id] = group_info + group_info_by_entity_id[leader_entity_id] = group_info # type: ignore[assignment] for member_entity_id in member_entity_ids: - group_info_by_entity_id[member_entity_id] = group_info + group_info_by_entity_id[member_entity_id] = group_info # type: ignore[assignment] return group_info_by_entity_id @@ -358,13 +364,9 @@ def connect_update(self): # When adding a new HEOS player we need to update the groups. async def _async_handle_player_added(): - # Avoid calling async_update_groups when `DATA_ENTITY_ID_MAP` has not been + # Avoid calling async_update_groups when the entity_id map has not been # fully populated yet. This may only happen during early startup. - if ( - len(self._hass.data[DOMAIN][Platform.MEDIA_PLAYER]) - <= len(self._hass.data[DOMAIN][DATA_ENTITY_ID_MAP]) - and not self._initialized - ): + if len(self.players) <= len(self.entity_id_map) and not self._initialized: self._initialized = True await self.async_update_groups(SIGNAL_HEOS_PLAYER_ADDED) diff --git a/homeassistant/components/heos/const.py b/homeassistant/components/heos/const.py index 636751d150b2b6..827a0c53fbfb1b 100644 --- a/homeassistant/components/heos/const.py +++ b/homeassistant/components/heos/const.py @@ -4,10 +4,6 @@ ATTR_USERNAME = "username" COMMAND_RETRY_ATTEMPTS = 2 COMMAND_RETRY_DELAY = 1 -DATA_CONTROLLER_MANAGER = "controller" -DATA_ENTITY_ID_MAP = "entity_id_map" -DATA_GROUP_MANAGER = "group_manager" -DATA_SOURCE_MANAGER = "source_manager" DATA_DISCOVERED_HOSTS = "heos_discovered_hosts" DOMAIN = "heos" SERVICE_SIGN_IN = "sign_in" diff --git a/homeassistant/components/heos/media_player.py b/homeassistant/components/heos/media_player.py index 0f9f7facd330e4..5255d369c2f15d 100644 --- a/homeassistant/components/heos/media_player.py +++ b/homeassistant/components/heos/media_player.py @@ -13,7 +13,6 @@ from homeassistant.components import media_source from homeassistant.components.media_player import ( ATTR_MEDIA_ENQUEUE, - DOMAIN as MEDIA_PLAYER_DOMAIN, BrowseMedia, MediaPlayerEnqueue, MediaPlayerEntity, @@ -22,7 +21,6 @@ MediaType, async_process_play_media_url, ) -from homeassistant.config_entries import ConfigEntry from homeassistant.core import HomeAssistant from homeassistant.helpers.device_registry import DeviceInfo from homeassistant.helpers.dispatcher import ( @@ -32,14 +30,8 @@ from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.util.dt import utcnow -from .const import ( - DATA_ENTITY_ID_MAP, - DATA_GROUP_MANAGER, - DATA_SOURCE_MANAGER, - DOMAIN as HEOS_DOMAIN, - SIGNAL_HEOS_PLAYER_ADDED, - SIGNAL_HEOS_UPDATED, -) +from . import GroupManager, HeosConfigEntry, SourceManager +from .const import DOMAIN as HEOS_DOMAIN, SIGNAL_HEOS_PLAYER_ADDED, SIGNAL_HEOS_UPDATED BASE_SUPPORTED_FEATURES = ( MediaPlayerEntityFeature.VOLUME_MUTE @@ -80,11 +72,16 @@ async def async_setup_entry( - hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback + hass: HomeAssistant, entry: HeosConfigEntry, async_add_entities: AddEntitiesCallback ) -> None: """Add media players for a config entry.""" - players = hass.data[HEOS_DOMAIN][MEDIA_PLAYER_DOMAIN] - devices = [HeosMediaPlayer(player) for player in players.values()] + players = entry.runtime_data.players + devices = [ + HeosMediaPlayer( + player, entry.runtime_data.source_manager, entry.runtime_data.group_manager + ) + for player in players.values() + ] async_add_entities(devices, True) @@ -120,13 +117,15 @@ class HeosMediaPlayer(MediaPlayerEntity): _attr_has_entity_name = True _attr_name = None - def __init__(self, player): + def __init__( + self, player, source_manager: SourceManager, group_manager: GroupManager + ) -> None: """Initialize.""" self._media_position_updated_at = None self._player = player - self._signals = [] - self._source_manager = None - self._group_manager = None + self._signals: list = [] + self._source_manager = source_manager + self._group_manager = group_manager self._attr_unique_id = str(player.player_id) self._attr_device_info = DeviceInfo( identifiers={(HEOS_DOMAIN, player.player_id)}, @@ -161,9 +160,7 @@ async def async_added_to_hass(self) -> None: async_dispatcher_connect(self.hass, SIGNAL_HEOS_UPDATED, self._heos_updated) ) # Register this player's entity_id so it can be resolved by the group manager - self.hass.data[HEOS_DOMAIN][DATA_ENTITY_ID_MAP][self._player.player_id] = ( - self.entity_id - ) + self._group_manager.entity_id_map[self._player.player_id] = self.entity_id async_dispatcher_send(self.hass, SIGNAL_HEOS_PLAYER_ADDED) @log_command_error("clear playlist") @@ -294,12 +291,6 @@ async def async_update(self) -> None: ior, current_support, BASE_SUPPORTED_FEATURES ) - if self._group_manager is None: - self._group_manager = self.hass.data[HEOS_DOMAIN][DATA_GROUP_MANAGER] - - if self._source_manager is None: - self._source_manager = self.hass.data[HEOS_DOMAIN][DATA_SOURCE_MANAGER] - @log_command_error("unjoin_player") async def async_unjoin_player(self) -> None: """Remove this player from any group.""" diff --git a/tests/components/heos/test_init.py b/tests/components/heos/test_init.py index 9341c8fbace923..04b745135d485a 100644 --- a/tests/components/heos/test_init.py +++ b/tests/components/heos/test_init.py @@ -8,15 +8,11 @@ from homeassistant.components.heos import ( ControllerManager, + HeosRuntimeData, async_setup_entry, async_unload_entry, ) -from homeassistant.components.heos.const import ( - DATA_CONTROLLER_MANAGER, - DATA_SOURCE_MANAGER, - DOMAIN, -) -from homeassistant.components.media_player import DOMAIN as MEDIA_PLAYER_DOMAIN +from homeassistant.components.heos.const import DOMAIN from homeassistant.const import CONF_HOST from homeassistant.core import HomeAssistant from homeassistant.exceptions import ConfigEntryNotReady @@ -92,10 +88,6 @@ async def test_async_setup_entry_loads_platforms( assert controller.get_favorites.call_count == 1 assert controller.get_input_sources.call_count == 1 controller.disconnect.assert_not_called() - assert hass.data[DOMAIN][DATA_CONTROLLER_MANAGER].controller == controller - assert hass.data[DOMAIN][MEDIA_PLAYER_DOMAIN] == controller.players - assert hass.data[DOMAIN][DATA_SOURCE_MANAGER].favorites == favorites - assert hass.data[DOMAIN][DATA_SOURCE_MANAGER].inputs == input_sources async def test_async_setup_entry_not_signed_in_loads_platforms( @@ -121,10 +113,6 @@ async def test_async_setup_entry_not_signed_in_loads_platforms( assert controller.get_favorites.call_count == 0 assert controller.get_input_sources.call_count == 1 controller.disconnect.assert_not_called() - assert hass.data[DOMAIN][DATA_CONTROLLER_MANAGER].controller == controller - assert hass.data[DOMAIN][MEDIA_PLAYER_DOMAIN] == controller.players - assert hass.data[DOMAIN][DATA_SOURCE_MANAGER].favorites == {} - assert hass.data[DOMAIN][DATA_SOURCE_MANAGER].inputs == input_sources assert ( "127.0.0.1 is not logged in to a HEOS account and will be unable to retrieve " "HEOS favorites: Use the 'heos.sign_in' service to sign-in to a HEOS account" @@ -163,7 +151,8 @@ async def test_async_setup_entry_player_failure( async def test_unload_entry(hass: HomeAssistant, config_entry, controller) -> None: """Test entries are unloaded correctly.""" controller_manager = Mock(ControllerManager) - hass.data[DOMAIN] = {DATA_CONTROLLER_MANAGER: controller_manager} + config_entry.runtime_data = HeosRuntimeData(controller_manager, None, None, {}) + with patch.object( hass.config_entries, "async_forward_entry_unload", return_value=True ) as unload: @@ -186,7 +175,7 @@ async def test_update_sources_retry( assert await async_setup_component(hass, DOMAIN, config) controller.get_favorites.reset_mock() controller.get_input_sources.reset_mock() - source_manager = hass.data[DOMAIN][DATA_SOURCE_MANAGER] + source_manager = config_entry.runtime_data.source_manager source_manager.retry_delay = 0 source_manager.max_retry_attempts = 1 controller.get_favorites.side_effect = CommandFailedError("Test", "test", 0) diff --git a/tests/components/heos/test_media_player.py b/tests/components/heos/test_media_player.py index 089fa1cceea7bc..fa3f01107c1573 100644 --- a/tests/components/heos/test_media_player.py +++ b/tests/components/heos/test_media_player.py @@ -8,11 +8,7 @@ import pytest from homeassistant.components.heos import media_player -from homeassistant.components.heos.const import ( - DATA_SOURCE_MANAGER, - DOMAIN, - SIGNAL_HEOS_UPDATED, -) +from homeassistant.components.heos.const import DOMAIN, SIGNAL_HEOS_UPDATED from homeassistant.components.media_player import ( ATTR_GROUP_MEMBERS, ATTR_INPUT_SOURCE, @@ -106,7 +102,7 @@ async def test_state_attributes( assert ATTR_INPUT_SOURCE not in state.attributes assert ( state.attributes[ATTR_INPUT_SOURCE_LIST] - == hass.data[DOMAIN][DATA_SOURCE_MANAGER].source_list + == config_entry.runtime_data.source_manager.source_list ) @@ -219,7 +215,7 @@ async def set_signal(): const.SIGNAL_CONTROLLER_EVENT, const.EVENT_SOURCES_CHANGED, {} ) await event.wait() - source_list = hass.data[DOMAIN][DATA_SOURCE_MANAGER].source_list + source_list = config_entry.runtime_data.source_manager.source_list assert len(source_list) == 2 state = hass.states.get("media_player.test_player") assert state.attributes[ATTR_INPUT_SOURCE_LIST] == source_list @@ -318,7 +314,7 @@ async def set_signal(): const.SIGNAL_CONTROLLER_EVENT, const.EVENT_USER_CHANGED, None ) await event.wait() - source_list = hass.data[DOMAIN][DATA_SOURCE_MANAGER].source_list + source_list = config_entry.runtime_data.source_manager.source_list assert len(source_list) == 1 state = hass.states.get("media_player.test_player") assert state.attributes[ATTR_INPUT_SOURCE_LIST] == source_list From 5dc390b6b93a1f800badfb10389790c34bfc85f6 Mon Sep 17 00:00:00 2001 From: TimL Date: Mon, 2 Dec 2024 19:24:49 +1100 Subject: [PATCH 40/41] Bump psymlight v0.1.4 (#132045) --- homeassistant/components/smlight/manifest.json | 2 +- requirements_all.txt | 2 +- requirements_test_all.txt | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/smlight/manifest.json b/homeassistant/components/smlight/manifest.json index c1eca45871b206..cb791ac111bded 100644 --- a/homeassistant/components/smlight/manifest.json +++ b/homeassistant/components/smlight/manifest.json @@ -6,7 +6,7 @@ "documentation": "https://www.home-assistant.io/integrations/smlight", "integration_type": "device", "iot_class": "local_push", - "requirements": ["pysmlight==0.1.3"], + "requirements": ["pysmlight==0.1.4"], "zeroconf": [ { "type": "_slzb-06._tcp.local." diff --git a/requirements_all.txt b/requirements_all.txt index fb0e39176f5514..150fc195f8dbaf 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -2269,7 +2269,7 @@ pysmarty2==0.10.1 pysml==0.0.12 # homeassistant.components.smlight -pysmlight==0.1.3 +pysmlight==0.1.4 # homeassistant.components.snmp pysnmp==6.2.6 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index e459093135efcf..d79571888af27f 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -1832,7 +1832,7 @@ pysmarty2==0.10.1 pysml==0.0.12 # homeassistant.components.smlight -pysmlight==0.1.3 +pysmlight==0.1.4 # homeassistant.components.snmp pysnmp==6.2.6 From 8d1493036a405f710bbf8c75abed933f8cea57e3 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Mon, 2 Dec 2024 09:59:57 +0100 Subject: [PATCH 41/41] Set PARALLEL_UPDATES in renault and bump quality scale (#132047) --- homeassistant/components/renault/binary_sensor.py | 3 +++ homeassistant/components/renault/button.py | 4 ++++ homeassistant/components/renault/device_tracker.py | 3 +++ homeassistant/components/renault/manifest.json | 1 + homeassistant/components/renault/quality_scale.yaml | 2 +- homeassistant/components/renault/select.py | 4 ++++ homeassistant/components/renault/sensor.py | 3 +++ 7 files changed, 19 insertions(+), 1 deletion(-) diff --git a/homeassistant/components/renault/binary_sensor.py b/homeassistant/components/renault/binary_sensor.py index 98c298761ce252..a8fdf324f1c538 100644 --- a/homeassistant/components/renault/binary_sensor.py +++ b/homeassistant/components/renault/binary_sensor.py @@ -19,6 +19,9 @@ from . import RenaultConfigEntry from .entity import RenaultDataEntity, RenaultDataEntityDescription +# Coordinator is used to centralize the data updates +PARALLEL_UPDATES = 0 + @dataclass(frozen=True, kw_only=True) class RenaultBinarySensorEntityDescription( diff --git a/homeassistant/components/renault/button.py b/homeassistant/components/renault/button.py index d3666388fbbadd..6a9f5e05a38e96 100644 --- a/homeassistant/components/renault/button.py +++ b/homeassistant/components/renault/button.py @@ -13,6 +13,10 @@ from . import RenaultConfigEntry from .entity import RenaultEntity +# Coordinator is used to centralize the data updates +# but renault servers are unreliable and it's safer to queue action calls +PARALLEL_UPDATES = 1 + @dataclass(frozen=True, kw_only=True) class RenaultButtonEntityDescription(ButtonEntityDescription): diff --git a/homeassistant/components/renault/device_tracker.py b/homeassistant/components/renault/device_tracker.py index 2f7aeda5c39b23..08a2a698802f5f 100644 --- a/homeassistant/components/renault/device_tracker.py +++ b/homeassistant/components/renault/device_tracker.py @@ -16,6 +16,9 @@ from . import RenaultConfigEntry from .entity import RenaultDataEntity, RenaultDataEntityDescription +# Coordinator is used to centralize the data updates +PARALLEL_UPDATES = 0 + @dataclass(frozen=True, kw_only=True) class RenaultTrackerEntityDescription( diff --git a/homeassistant/components/renault/manifest.json b/homeassistant/components/renault/manifest.json index 396410dfc2021c..111f296fc85c7f 100644 --- a/homeassistant/components/renault/manifest.json +++ b/homeassistant/components/renault/manifest.json @@ -7,5 +7,6 @@ "integration_type": "hub", "iot_class": "cloud_polling", "loggers": ["renault_api"], + "quality_scale": "silver", "requirements": ["renault-api==0.2.7"] } diff --git a/homeassistant/components/renault/quality_scale.yaml b/homeassistant/components/renault/quality_scale.yaml index b49ff669895e10..f2d70622192d5b 100644 --- a/homeassistant/components/renault/quality_scale.yaml +++ b/homeassistant/components/renault/quality_scale.yaml @@ -28,7 +28,7 @@ rules: entity-unavailable: done integration-owner: done log-when-unavailable: done - parallel-updates: todo + parallel-updates: done reauthentication-flow: done test-coverage: done # Gold diff --git a/homeassistant/components/renault/select.py b/homeassistant/components/renault/select.py index b430da9396e333..cab1d1f4d8a409 100644 --- a/homeassistant/components/renault/select.py +++ b/homeassistant/components/renault/select.py @@ -15,6 +15,10 @@ from . import RenaultConfigEntry from .entity import RenaultDataEntity, RenaultDataEntityDescription +# Coordinator is used to centralize the data updates +# but renault servers are unreliable and it's safer to queue action calls +PARALLEL_UPDATES = 1 + @dataclass(frozen=True, kw_only=True) class RenaultSelectEntityDescription( diff --git a/homeassistant/components/renault/sensor.py b/homeassistant/components/renault/sensor.py index 78e64ae9acc3bd..7854d70b1c41e0 100644 --- a/homeassistant/components/renault/sensor.py +++ b/homeassistant/components/renault/sensor.py @@ -40,6 +40,9 @@ from .entity import RenaultDataEntity, RenaultDataEntityDescription from .renault_vehicle import RenaultVehicleProxy +# Coordinator is used to centralize the data updates +PARALLEL_UPDATES = 0 + @dataclass(frozen=True, kw_only=True) class RenaultSensorEntityDescription(