From 4e8d68a2efca4e98019453ab5c5491a36f3ca222 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20K=C3=B6lsch?= <20746434+andreaskoelsch@users.noreply.github.com> Date: Fri, 2 May 2025 00:07:52 +0200 Subject: [PATCH 01/90] Fix brightness calculation when using brightness_step_pct (#143786) --- homeassistant/components/light/__init__.py | 5 +- tests/components/light/test_init.py | 59 ++++++++++++++++------ 2 files changed, 47 insertions(+), 17 deletions(-) diff --git a/homeassistant/components/light/__init__.py b/homeassistant/components/light/__init__.py index 7b548533058..d2869670ba4 100644 --- a/homeassistant/components/light/__init__.py +++ b/homeassistant/components/light/__init__.py @@ -442,7 +442,10 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: # noqa: brightness += params.pop(ATTR_BRIGHTNESS_STEP) else: - brightness += round(params.pop(ATTR_BRIGHTNESS_STEP_PCT) / 100 * 255) + brightness_pct = round(brightness / 255 * 100) + brightness = round( + (brightness_pct + params.pop(ATTR_BRIGHTNESS_STEP_PCT)) / 100 * 255 + ) params[ATTR_BRIGHTNESS] = max(0, min(255, brightness)) diff --git a/tests/components/light/test_init.py b/tests/components/light/test_init.py index 29604ce7595..014e3ec8c35 100644 --- a/tests/components/light/test_init.py +++ b/tests/components/light/test_init.py @@ -958,21 +958,6 @@ async def test_light_brightness_step(hass: HomeAssistant) -> None: _, data = entity1.last_call("turn_on") assert data["brightness"] == 40 # 50 - 10 - await hass.services.async_call( - "light", - "turn_on", - { - "entity_id": [entity0.entity_id, entity1.entity_id], - "brightness_step_pct": 10, - }, - blocking=True, - ) - - _, data = entity0.last_call("turn_on") - assert data["brightness"] == 116 # 90 + (255 * 0.10) - _, data = entity1.last_call("turn_on") - assert data["brightness"] == 66 # 40 + (255 * 0.10) - await hass.services.async_call( "light", "turn_on", @@ -983,7 +968,49 @@ async def test_light_brightness_step(hass: HomeAssistant) -> None: blocking=True, ) - assert entity0.state == "off" # 126 - 126; brightness is 0, light should turn off + assert entity0.state == "off" # 40 - 126; brightness is 0, light should turn off + + +async def test_light_brightness_step_pct(hass: HomeAssistant) -> None: + """Test that percentage based brightness steps work as expected.""" + entity = MockLight("Test_0", STATE_ON) + + setup_test_component_platform(hass, light.DOMAIN, [entity]) + + entity.supported_features = light.SUPPORT_BRIGHTNESS + # Set color modes to none to trigger backwards compatibility in LightEntity + entity.supported_color_modes = None + entity.color_mode = None + entity.brightness = 255 + assert await async_setup_component(hass, "light", {"light": {"platform": "test"}}) + await hass.async_block_till_done() + + state = hass.states.get(entity.entity_id) + assert state is not None + assert state.attributes["brightness"] == 255 # 100% + + def reduce_brightness_by_ten_percent(): + return hass.services.async_call( + "light", + "turn_on", + { + "entity_id": [entity.entity_id], + "brightness_step_pct": -10, + }, + blocking=True, + ) + + await reduce_brightness_by_ten_percent() + _, data = entity.last_call("turn_on") + assert round(data["brightness"] / 2.55) == 90 # 100% - 10% = 90% + + await reduce_brightness_by_ten_percent() + _, data = entity.last_call("turn_on") + assert round(data["brightness"] / 2.55) == 80 # 90% - 10% = 80% + + await reduce_brightness_by_ten_percent() + _, data = entity.last_call("turn_on") + assert round(data["brightness"] / 2.55) == 70 # 80% - 10% = 70% @pytest.mark.usefixtures("enable_custom_integrations") From fca62f1ae8241c14588861e1f7f73e1217058740 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Fri, 2 May 2025 08:32:44 +0200 Subject: [PATCH 02/90] Move SamsungTV test constants to fixture files (#144086) --- tests/components/samsungtv/conftest.py | 8 +- tests/components/samsungtv/const.py | 101 ------------- .../fixtures/device_info_UE43LS003.json | 34 +++++ .../fixtures/device_info_UE48JU6400.json | 28 ++++ .../fixtures/ws_installed_app_event.json | 29 ++++ .../samsungtv/snapshots/test_diagnostics.ambr | 137 ++++++++++++++++++ .../components/samsungtv/test_config_flow.py | 7 +- .../components/samsungtv/test_diagnostics.py | 131 ++++------------- tests/components/samsungtv/test_init.py | 7 +- .../components/samsungtv/test_media_player.py | 20 ++- 10 files changed, 283 insertions(+), 219 deletions(-) create mode 100644 tests/components/samsungtv/fixtures/device_info_UE43LS003.json create mode 100644 tests/components/samsungtv/fixtures/device_info_UE48JU6400.json create mode 100644 tests/components/samsungtv/fixtures/ws_installed_app_event.json create mode 100644 tests/components/samsungtv/snapshots/test_diagnostics.ambr diff --git a/tests/components/samsungtv/conftest.py b/tests/components/samsungtv/conftest.py index 4b3ad59defd..c33fd89ec56 100644 --- a/tests/components/samsungtv/conftest.py +++ b/tests/components/samsungtv/conftest.py @@ -19,9 +19,11 @@ from samsungtvws.event import ED_INSTALLED_APP_EVENT from samsungtvws.exceptions import ResponseError from samsungtvws.remote import ChannelEmitCommand -from homeassistant.components.samsungtv.const import WEBSOCKET_SSL_PORT +from homeassistant.components.samsungtv.const import DOMAIN, WEBSOCKET_SSL_PORT -from .const import SAMPLE_DEVICE_INFO_UE48JU6400, SAMPLE_DEVICE_INFO_WIFI +from .const import SAMPLE_DEVICE_INFO_WIFI + +from tests.common import load_json_object_fixture @pytest.fixture @@ -186,7 +188,7 @@ def rest_api_fixture_non_ssl_only() -> Generator[None]: """Mock rest_device_info to fail for ssl and work for non-ssl.""" if self.port == WEBSOCKET_SSL_PORT: raise ResponseError - return SAMPLE_DEVICE_INFO_UE48JU6400 + return load_json_object_fixture("device_info_UE48JU6400.json", DOMAIN) with patch( "homeassistant.components.samsungtv.bridge.SamsungTVAsyncRest", diff --git a/tests/components/samsungtv/const.py b/tests/components/samsungtv/const.py index c1a9da4e284..5d09087dadd 100644 --- a/tests/components/samsungtv/const.py +++ b/tests/components/samsungtv/const.py @@ -1,7 +1,5 @@ """Constants for the samsungtv tests.""" -from samsungtvws.event import ED_INSTALLED_APP_EVENT - from homeassistant.components.samsungtv.const import ( CONF_SESSION_ID, METHOD_LEGACY, @@ -94,102 +92,3 @@ SAMPLE_DEVICE_INFO_WIFI = { "networkType": "wireless", }, } - -SAMPLE_DEVICE_INFO_FRAME = { - "device": { - "FrameTVSupport": "true", - "GamePadSupport": "true", - "ImeSyncedSupport": "true", - "OS": "Tizen", - "TokenAuthSupport": "true", - "VoiceSupport": "true", - "countryCode": "FR", - "description": "Samsung DTV RCR", - "developerIP": "0.0.0.0", - "developerMode": "0", - "duid": "uuid:be9554b9-c9fb-41f4-8920-22da015376a4", - "firmwareVersion": "Unknown", - "id": "uuid:be9554b9-c9fb-41f4-8920-22da015376a4", - "ip": "1.2.3.4", - "model": "17_KANTM_UHD", - "modelName": "UE43LS003", - "name": "[TV] Samsung Frame (43)", - "networkType": "wired", - "resolution": "3840x2160", - "smartHubAgreement": "true", - "type": "Samsung SmartTV", - "udn": "uuid:be9554b9-c9fb-41f4-8920-22da015376a4", - "wifiMac": "aa:ee:tt:hh:ee:rr", - }, - "id": "uuid:be9554b9-c9fb-41f4-8920-22da015376a4", - "isSupport": ( - '{"DMP_DRM_PLAYREADY":"false","DMP_DRM_WIDEVINE":"false","DMP_available":"true",' - '"EDEN_available":"true","FrameTVSupport":"true","ImeSyncedSupport":"true",' - '"TokenAuthSupport":"true","remote_available":"true","remote_fourDirections":"true",' - '"remote_touchPad":"true","remote_voiceControl":"true"}\n' - ), - "name": "[TV] Samsung Frame (43)", - "remote": "1.0", - "type": "Samsung SmartTV", - "uri": "https://1.2.3.4:8002/api/v2/", - "version": "2.0.25", -} - -SAMPLE_DEVICE_INFO_UE48JU6400 = { - "id": "uuid:223da676-497a-4e06-9507-5e27ec4f0fb3", - "name": "[TV] TV-UE48JU6470", - "version": "2.0.25", - "device": { - "type": "Samsung SmartTV", - "duid": "uuid:223da676-497a-4e06-9507-5e27ec4f0fb3", - "model": "15_HAWKM_UHD_2D", - "modelName": "UE48JU6400", - "description": "Samsung DTV RCR", - "networkType": "wired", - "ssid": "", - "ip": "1.2.3.4", - "firmwareVersion": "Unknown", - "name": "[TV] TV-UE48JU6470", - "id": "uuid:223da676-497a-4e06-9507-5e27ec4f0fb3", - "udn": "uuid:223da676-497a-4e06-9507-5e27ec4f0fb3", - "resolution": "1920x1080", - "countryCode": "AT", - "msfVersion": "2.0.25", - "smartHubAgreement": "true", - "wifiMac": "aa:bb:aa:aa:aa:aa", - "developerMode": "0", - "developerIP": "", - }, - "type": "Samsung SmartTV", - "uri": "https://1.2.3.4:8002/api/v2/", -} - -SAMPLE_EVENT_ED_INSTALLED_APP = { - "event": ED_INSTALLED_APP_EVENT, - "from": "host", - "data": { - "data": [ - { - "appId": "111299001912", - "app_type": 2, - "icon": "/opt/share/webappservice/apps_icon/FirstScreen/111299001912/250x250.png", - "is_lock": 0, - "name": "YouTube", - }, - { - "appId": "3201608010191", - "app_type": 2, - "icon": "/opt/share/webappservice/apps_icon/FirstScreen/3201608010191/250x250.png", - "is_lock": 0, - "name": "Deezer", - }, - { - "appId": "3201606009684", - "app_type": 2, - "icon": "/opt/share/webappservice/apps_icon/FirstScreen/3201606009684/250x250.png", - "is_lock": 0, - "name": "Spotify - Music and Podcasts", - }, - ] - }, -} diff --git a/tests/components/samsungtv/fixtures/device_info_UE43LS003.json b/tests/components/samsungtv/fixtures/device_info_UE43LS003.json new file mode 100644 index 00000000000..ac961fafd6b --- /dev/null +++ b/tests/components/samsungtv/fixtures/device_info_UE43LS003.json @@ -0,0 +1,34 @@ +{ + "device": { + "FrameTVSupport": "true", + "GamePadSupport": "true", + "ImeSyncedSupport": "true", + "OS": "Tizen", + "TokenAuthSupport": "true", + "VoiceSupport": "true", + "countryCode": "FR", + "description": "Samsung DTV RCR", + "developerIP": "0.0.0.0", + "developerMode": "0", + "duid": "uuid:be9554b9-c9fb-41f4-8920-22da015376a4", + "firmwareVersion": "Unknown", + "id": "uuid:be9554b9-c9fb-41f4-8920-22da015376a4", + "ip": "1.2.3.4", + "model": "17_KANTM_UHD", + "modelName": "UE43LS003", + "name": "[TV] Samsung Frame (43)", + "networkType": "wired", + "resolution": "3840x2160", + "smartHubAgreement": "true", + "type": "Samsung SmartTV", + "udn": "uuid:be9554b9-c9fb-41f4-8920-22da015376a4", + "wifiMac": "aa:ee:tt:hh:ee:rr" + }, + "id": "uuid:be9554b9-c9fb-41f4-8920-22da015376a4", + "isSupport": "{\"DMP_DRM_PLAYREADY\":\"false\",\"DMP_DRM_WIDEVINE\":\"false\",\"DMP_available\":\"true\",\"EDEN_available\":\"true\",\"FrameTVSupport\":\"true\",\"ImeSyncedSupport\":\"true\",\"TokenAuthSupport\":\"true\",\"remote_available\":\"true\",\"remote_fourDirections\":\"true\",\"remote_touchPad\":\"true\",\"remote_voiceControl\":\"true\"}\n", + "name": "[TV] Samsung Frame (43)", + "remote": "1.0", + "type": "Samsung SmartTV", + "uri": "https://1.2.3.4:8002/api/v2/", + "version": "2.0.25" +} diff --git a/tests/components/samsungtv/fixtures/device_info_UE48JU6400.json b/tests/components/samsungtv/fixtures/device_info_UE48JU6400.json new file mode 100644 index 00000000000..65cecf095a2 --- /dev/null +++ b/tests/components/samsungtv/fixtures/device_info_UE48JU6400.json @@ -0,0 +1,28 @@ +{ + "id": "uuid:223da676-497a-4e06-9507-5e27ec4f0fb3", + "name": "[TV] TV-UE48JU6470", + "version": "2.0.25", + "device": { + "type": "Samsung SmartTV", + "duid": "uuid:223da676-497a-4e06-9507-5e27ec4f0fb3", + "model": "15_HAWKM_UHD_2D", + "modelName": "UE48JU6400", + "description": "Samsung DTV RCR", + "networkType": "wired", + "ssid": "", + "ip": "1.2.3.4", + "firmwareVersion": "Unknown", + "name": "[TV] TV-UE48JU6470", + "id": "uuid:223da676-497a-4e06-9507-5e27ec4f0fb3", + "udn": "uuid:223da676-497a-4e06-9507-5e27ec4f0fb3", + "resolution": "1920x1080", + "countryCode": "AT", + "msfVersion": "2.0.25", + "smartHubAgreement": "true", + "wifiMac": "aa:bb:aa:aa:aa:aa", + "developerMode": "0", + "developerIP": "" + }, + "type": "Samsung SmartTV", + "uri": "https://1.2.3.4:8002/api/v2/" +} diff --git a/tests/components/samsungtv/fixtures/ws_installed_app_event.json b/tests/components/samsungtv/fixtures/ws_installed_app_event.json new file mode 100644 index 00000000000..81c64f60958 --- /dev/null +++ b/tests/components/samsungtv/fixtures/ws_installed_app_event.json @@ -0,0 +1,29 @@ +{ + "event": "ed.installedApp.get", + "from": "host", + "data": { + "data": [ + { + "appId": "111299001912", + "app_type": 2, + "icon": "/opt/share/webappservice/apps_icon/FirstScreen/111299001912/250x250.png", + "is_lock": 0, + "name": "YouTube" + }, + { + "appId": "3201608010191", + "app_type": 2, + "icon": "/opt/share/webappservice/apps_icon/FirstScreen/3201608010191/250x250.png", + "is_lock": 0, + "name": "Deezer" + }, + { + "appId": "3201606009684", + "app_type": 2, + "icon": "/opt/share/webappservice/apps_icon/FirstScreen/3201606009684/250x250.png", + "is_lock": 0, + "name": "Spotify - Music and Podcasts" + } + ] + } +} diff --git a/tests/components/samsungtv/snapshots/test_diagnostics.ambr b/tests/components/samsungtv/snapshots/test_diagnostics.ambr new file mode 100644 index 00000000000..dd1b3654186 --- /dev/null +++ b/tests/components/samsungtv/snapshots/test_diagnostics.ambr @@ -0,0 +1,137 @@ +# serializer version: 1 +# name: test_entry_diagnostics + dict({ + 'device_info': dict({ + 'device': dict({ + 'modelName': '82GXARRS', + 'name': '[TV] Living Room', + 'networkType': 'wireless', + 'type': 'Samsung SmartTV', + 'wifiMac': 'aa:bb:aa:aa:aa:aa', + }), + 'id': 'uuid:be9554b9-c9fb-41f4-8920-22da015376a4', + }), + 'entry': dict({ + 'data': dict({ + 'host': 'fake_host', + 'ip_address': 'test', + 'mac': 'aa:bb:cc:dd:ee:ff', + 'method': 'websocket', + 'model': '82GXARRS', + 'name': 'fake', + 'port': 8002, + 'token': '**REDACTED**', + }), + 'disabled_by': None, + 'discovery_keys': dict({ + }), + 'domain': 'samsungtv', + 'entry_id': '123456', + 'minor_version': 2, + 'options': dict({ + }), + 'pref_disable_new_entities': False, + 'pref_disable_polling': False, + 'source': 'user', + 'subentries': list([ + ]), + 'title': 'Mock Title', + 'unique_id': 'be9554b9-c9fb-41f4-8920-22da015376a4', + 'version': 2, + }), + }) +# --- +# name: test_entry_diagnostics_encrypte_offline + dict({ + 'device_info': None, + 'entry': dict({ + 'data': dict({ + 'host': 'fake_host', + 'ip_address': 'test', + 'mac': 'aa:bb:cc:dd:ee:ff', + 'method': 'encrypted', + 'name': 'fake', + 'port': 8000, + 'session_id': '**REDACTED**', + 'token': '**REDACTED**', + }), + 'disabled_by': None, + 'discovery_keys': dict({ + }), + 'domain': 'samsungtv', + 'entry_id': '123456', + 'minor_version': 2, + 'options': dict({ + }), + 'pref_disable_new_entities': False, + 'pref_disable_polling': False, + 'source': 'user', + 'subentries': list([ + ]), + 'title': 'Mock Title', + 'unique_id': 'be9554b9-c9fb-41f4-8920-22da015376a4', + 'version': 2, + }), + }) +# --- +# name: test_entry_diagnostics_encrypted + dict({ + 'device_info': dict({ + 'device': dict({ + 'countryCode': 'AT', + 'description': 'Samsung DTV RCR', + 'developerIP': '', + 'developerMode': '0', + 'duid': 'uuid:223da676-497a-4e06-9507-5e27ec4f0fb3', + 'firmwareVersion': 'Unknown', + 'id': 'uuid:223da676-497a-4e06-9507-5e27ec4f0fb3', + 'ip': '1.2.3.4', + 'model': '15_HAWKM_UHD_2D', + 'modelName': 'UE48JU6400', + 'msfVersion': '2.0.25', + 'name': '[TV] TV-UE48JU6470', + 'networkType': 'wired', + 'resolution': '1920x1080', + 'smartHubAgreement': 'true', + 'ssid': '', + 'type': 'Samsung SmartTV', + 'udn': 'uuid:223da676-497a-4e06-9507-5e27ec4f0fb3', + 'wifiMac': 'aa:bb:aa:aa:aa:aa', + }), + 'id': 'uuid:223da676-497a-4e06-9507-5e27ec4f0fb3', + 'name': '[TV] TV-UE48JU6470', + 'type': 'Samsung SmartTV', + 'uri': 'https://1.2.3.4:8002/api/v2/', + 'version': '2.0.25', + }), + 'entry': dict({ + 'data': dict({ + 'host': 'fake_host', + 'ip_address': 'test', + 'mac': 'aa:bb:cc:dd:ee:ff', + 'method': 'encrypted', + 'model': 'UE48JU6400', + 'name': 'fake', + 'port': 8000, + 'session_id': '**REDACTED**', + 'token': '**REDACTED**', + }), + 'disabled_by': None, + 'discovery_keys': dict({ + }), + 'domain': 'samsungtv', + 'entry_id': '123456', + 'minor_version': 2, + 'options': dict({ + }), + 'pref_disable_new_entities': False, + 'pref_disable_polling': False, + 'source': 'user', + 'subentries': list([ + ]), + 'title': 'Mock Title', + 'unique_id': 'be9554b9-c9fb-41f4-8920-22da015376a4', + 'version': 2, + }), + }) +# --- diff --git a/tests/components/samsungtv/test_config_flow.py b/tests/components/samsungtv/test_config_flow.py index 5ff259c2120..12c222033e0 100644 --- a/tests/components/samsungtv/test_config_flow.py +++ b/tests/components/samsungtv/test_config_flow.py @@ -63,10 +63,9 @@ from .const import ( MOCK_ENTRYDATA_WS, MOCK_SSDP_DATA_MAIN_TV_AGENT_ST, MOCK_SSDP_DATA_RENDERING_CONTROL_ST, - SAMPLE_DEVICE_INFO_FRAME, ) -from tests.common import MockConfigEntry +from tests.common import MockConfigEntry, load_json_object_fixture RESULT_ALREADY_CONFIGURED = "already_configured" RESULT_ALREADY_IN_PROGRESS = "already_in_progress" @@ -956,7 +955,9 @@ async def test_dhcp_wireless(hass: HomeAssistant) -> None: async def test_dhcp_wired(hass: HomeAssistant, rest_api: Mock) -> None: """Test starting a flow from dhcp.""" # Even though it is named "wifiMac", it matches the mac of the wired connection - rest_api.rest_device_info.return_value = SAMPLE_DEVICE_INFO_FRAME + rest_api.rest_device_info.return_value = load_json_object_fixture( + "device_info_UE43LS003.json", DOMAIN + ) # confirm to add the entry result = await hass.config_entries.flow.async_init( DOMAIN, diff --git a/tests/components/samsungtv/test_diagnostics.py b/tests/components/samsungtv/test_diagnostics.py index 53d52456de5..3f40c51d5d0 100644 --- a/tests/components/samsungtv/test_diagnostics.py +++ b/tests/components/samsungtv/test_diagnostics.py @@ -4,138 +4,63 @@ from unittest.mock import Mock import pytest from samsungtvws.exceptions import HttpApiError +from syrupy.assertion import SnapshotAssertion +from syrupy.filters import props -from homeassistant.components.diagnostics import REDACTED +from homeassistant.components.samsungtv.const import DOMAIN from homeassistant.core import HomeAssistant from . import setup_samsungtv_entry -from .const import ( - MOCK_ENTRY_WS_WITH_MAC, - MOCK_ENTRYDATA_ENCRYPTED_WS, - SAMPLE_DEVICE_INFO_UE48JU6400, - SAMPLE_DEVICE_INFO_WIFI, -) +from .const import MOCK_ENTRY_WS_WITH_MAC, MOCK_ENTRYDATA_ENCRYPTED_WS -from tests.common import ANY +from tests.common import load_json_object_fixture from tests.components.diagnostics import get_diagnostics_for_config_entry from tests.typing import ClientSessionGenerator @pytest.mark.usefixtures("remotews", "rest_api") async def test_entry_diagnostics( - hass: HomeAssistant, hass_client: ClientSessionGenerator + hass: HomeAssistant, + hass_client: ClientSessionGenerator, + snapshot: SnapshotAssertion, ) -> None: """Test config entry diagnostics.""" config_entry = await setup_samsungtv_entry(hass, MOCK_ENTRY_WS_WITH_MAC) - assert await get_diagnostics_for_config_entry(hass, hass_client, config_entry) == { - "entry": { - "created_at": ANY, - "data": { - "host": "fake_host", - "ip_address": "test", - "mac": "aa:bb:cc:dd:ee:ff", - "method": "websocket", - "model": "82GXARRS", - "name": "fake", - "port": 8002, - "token": REDACTED, - }, - "disabled_by": None, - "discovery_keys": {}, - "domain": "samsungtv", - "entry_id": "123456", - "minor_version": 2, - "modified_at": ANY, - "options": {}, - "pref_disable_new_entities": False, - "pref_disable_polling": False, - "source": "user", - "subentries": [], - "title": "Mock Title", - "unique_id": "be9554b9-c9fb-41f4-8920-22da015376a4", - "version": 2, - }, - "device_info": SAMPLE_DEVICE_INFO_WIFI, - } + assert await get_diagnostics_for_config_entry( + hass, hass_client, config_entry + ) == snapshot(exclude=props("created_at", "modified_at")) @pytest.mark.usefixtures("remoteencws") async def test_entry_diagnostics_encrypted( - hass: HomeAssistant, rest_api: Mock, hass_client: ClientSessionGenerator + hass: HomeAssistant, + rest_api: Mock, + hass_client: ClientSessionGenerator, + snapshot: SnapshotAssertion, ) -> None: """Test config entry diagnostics.""" - rest_api.rest_device_info.return_value = SAMPLE_DEVICE_INFO_UE48JU6400 + rest_api.rest_device_info.return_value = load_json_object_fixture( + "device_info_UE48JU6400.json", DOMAIN + ) config_entry = await setup_samsungtv_entry(hass, MOCK_ENTRYDATA_ENCRYPTED_WS) - assert await get_diagnostics_for_config_entry(hass, hass_client, config_entry) == { - "entry": { - "created_at": ANY, - "data": { - "host": "fake_host", - "ip_address": "test", - "mac": "aa:bb:cc:dd:ee:ff", - "method": "encrypted", - "model": "UE48JU6400", - "name": "fake", - "port": 8000, - "token": REDACTED, - "session_id": REDACTED, - }, - "disabled_by": None, - "discovery_keys": {}, - "domain": "samsungtv", - "entry_id": "123456", - "minor_version": 2, - "modified_at": ANY, - "options": {}, - "pref_disable_new_entities": False, - "pref_disable_polling": False, - "source": "user", - "subentries": [], - "title": "Mock Title", - "unique_id": "be9554b9-c9fb-41f4-8920-22da015376a4", - "version": 2, - }, - "device_info": SAMPLE_DEVICE_INFO_UE48JU6400, - } + assert await get_diagnostics_for_config_entry( + hass, hass_client, config_entry + ) == snapshot(exclude=props("created_at", "modified_at")) @pytest.mark.usefixtures("remoteencws") async def test_entry_diagnostics_encrypte_offline( - hass: HomeAssistant, rest_api: Mock, hass_client: ClientSessionGenerator + hass: HomeAssistant, + rest_api: Mock, + hass_client: ClientSessionGenerator, + snapshot: SnapshotAssertion, ) -> None: """Test config entry diagnostics.""" rest_api.rest_device_info.side_effect = HttpApiError config_entry = await setup_samsungtv_entry(hass, MOCK_ENTRYDATA_ENCRYPTED_WS) - assert await get_diagnostics_for_config_entry(hass, hass_client, config_entry) == { - "entry": { - "created_at": ANY, - "data": { - "host": "fake_host", - "ip_address": "test", - "mac": "aa:bb:cc:dd:ee:ff", - "method": "encrypted", - "name": "fake", - "port": 8000, - "token": REDACTED, - "session_id": REDACTED, - }, - "disabled_by": None, - "discovery_keys": {}, - "domain": "samsungtv", - "entry_id": "123456", - "minor_version": 2, - "modified_at": ANY, - "options": {}, - "pref_disable_new_entities": False, - "pref_disable_polling": False, - "source": "user", - "subentries": [], - "title": "Mock Title", - "unique_id": "be9554b9-c9fb-41f4-8920-22da015376a4", - "version": 2, - }, - "device_info": None, - } + assert await get_diagnostics_for_config_entry( + hass, hass_client, config_entry + ) == snapshot(exclude=props("created_at", "modified_at")) diff --git a/tests/components/samsungtv/test_init.py b/tests/components/samsungtv/test_init.py index 9f1efc0f013..59dbfad0552 100644 --- a/tests/components/samsungtv/test_init.py +++ b/tests/components/samsungtv/test_init.py @@ -45,10 +45,9 @@ from .const import ( MOCK_ENTRYDATA_WS, MOCK_SSDP_DATA_MAIN_TV_AGENT_ST, MOCK_SSDP_DATA_RENDERING_CONTROL_ST, - SAMPLE_DEVICE_INFO_UE48JU6400, ) -from tests.common import MockConfigEntry +from tests.common import MockConfigEntry, load_json_object_fixture ENTITY_ID = f"{MP_DOMAIN}.fake_name" MOCK_CONFIG = { @@ -117,7 +116,9 @@ async def test_setup_h_j_model( hass: HomeAssistant, rest_api: Mock, caplog: pytest.LogCaptureFixture ) -> None: """Test Samsung TV integration is setup.""" - rest_api.rest_device_info.return_value = SAMPLE_DEVICE_INFO_UE48JU6400 + rest_api.rest_device_info.return_value = load_json_object_fixture( + "device_info_UE48JU6400.json", DOMAIN + ) await setup_samsungtv_entry(hass, MOCK_CONFIG) await hass.async_block_till_done() state = hass.states.get(ENTITY_ID) diff --git a/tests/components/samsungtv/test_media_player.py b/tests/components/samsungtv/test_media_player.py index 10e5249aac3..0a4587827d1 100644 --- a/tests/components/samsungtv/test_media_player.py +++ b/tests/components/samsungtv/test_media_player.py @@ -85,12 +85,14 @@ from .const import ( MOCK_CONFIG, MOCK_ENTRY_WS_WITH_MAC, MOCK_ENTRYDATA_ENCRYPTED_WS, - SAMPLE_DEVICE_INFO_FRAME, SAMPLE_DEVICE_INFO_WIFI, - SAMPLE_EVENT_ED_INSTALLED_APP, ) -from tests.common import MockConfigEntry, async_fire_time_changed +from tests.common import ( + MockConfigEntry, + async_fire_time_changed, + load_json_object_fixture, +) ENTITY_ID = f"{MP_DOMAIN}.fake" MOCK_CONFIGWS = { @@ -689,7 +691,9 @@ async def test_turn_off_websocket( hass: HomeAssistant, remotews: Mock, caplog: pytest.LogCaptureFixture ) -> None: """Test for turn_off.""" - remotews.app_list_data = SAMPLE_EVENT_ED_INSTALLED_APP + remotews.app_list_data = load_json_object_fixture( + "ws_installed_app_event.json", DOMAIN + ) with patch( "homeassistant.components.samsungtv.bridge.Remote", side_effect=[OSError("Boom"), DEFAULT_MOCK], @@ -728,7 +732,9 @@ async def test_turn_off_websocket_frame( hass: HomeAssistant, remotews: Mock, rest_api: Mock ) -> None: """Test for turn_off.""" - rest_api.rest_device_info.return_value = SAMPLE_DEVICE_INFO_FRAME + rest_api.rest_device_info.return_value = load_json_object_fixture( + "device_info_UE43LS003.json", DOMAIN + ) with patch( "homeassistant.components.samsungtv.bridge.Remote", side_effect=[OSError("Boom"), DEFAULT_MOCK], @@ -1136,7 +1142,9 @@ async def test_play_media_app(hass: HomeAssistant, remotews: Mock) -> None: @pytest.mark.usefixtures("rest_api") async def test_select_source_app(hass: HomeAssistant, remotews: Mock) -> None: """Test for select_source.""" - remotews.app_list_data = SAMPLE_EVENT_ED_INSTALLED_APP + remotews.app_list_data = load_json_object_fixture( + "ws_installed_app_event.json", DOMAIN + ) await setup_samsungtv_entry(hass, MOCK_CONFIGWS) remotews.send_commands.reset_mock() From 3af0d6e4841f5bfa438aba799dd36a70f852e4b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=2E=20Diego=20Rodr=C3=ADguez=20Royo?= Date: Fri, 2 May 2025 10:08:46 +0200 Subject: [PATCH 03/90] Use `is` instead of `==` on check against enum value at Home Connect (#144083) * Use `is` instead of `==` on check against enum value at Home Connect * Revert HTTP status checks --- homeassistant/components/home_connect/time.py | 4 +-- .../home_connect/test_binary_sensor.py | 10 +++---- tests/components/home_connect/test_button.py | 12 ++++---- .../home_connect/test_config_flow.py | 4 +-- .../home_connect/test_coordinator.py | 24 ++++++++-------- .../home_connect/test_diagnostics.py | 4 +-- tests/components/home_connect/test_entity.py | 8 +++--- tests/components/home_connect/test_init.py | 16 +++++------ tests/components/home_connect/test_light.py | 12 ++++---- tests/components/home_connect/test_number.py | 8 +++--- tests/components/home_connect/test_select.py | 10 +++---- tests/components/home_connect/test_sensor.py | 24 ++++++++-------- .../components/home_connect/test_services.py | 14 +++++----- tests/components/home_connect/test_switch.py | 28 +++++++++---------- tests/components/home_connect/test_time.py | 10 +++---- 15 files changed, 94 insertions(+), 94 deletions(-) diff --git a/homeassistant/components/home_connect/time.py b/homeassistant/components/home_connect/time.py index adf26d2d973..6a6e57c4dd3 100644 --- a/homeassistant/components/home_connect/time.py +++ b/homeassistant/components/home_connect/time.py @@ -79,7 +79,7 @@ class HomeConnectTimeEntity(HomeConnectEntity, TimeEntity): async def async_added_to_hass(self) -> None: """Call when entity is added to hass.""" await super().async_added_to_hass() - if self.bsh_key == SettingKey.BSH_COMMON_ALARM_CLOCK: + if self.bsh_key is SettingKey.BSH_COMMON_ALARM_CLOCK: automations = automations_with_entity(self.hass, self.entity_id) scripts = scripts_with_entity(self.hass, self.entity_id) items = automations + scripts @@ -123,7 +123,7 @@ class HomeConnectTimeEntity(HomeConnectEntity, TimeEntity): async def async_will_remove_from_hass(self) -> None: """Call when entity will be removed from hass.""" - if self.bsh_key == SettingKey.BSH_COMMON_ALARM_CLOCK: + if self.bsh_key is SettingKey.BSH_COMMON_ALARM_CLOCK: async_delete_issue( self.hass, DOMAIN, diff --git a/tests/components/home_connect/test_binary_sensor.py b/tests/components/home_connect/test_binary_sensor.py index 934b6103982..a88c8954c64 100644 --- a/tests/components/home_connect/test_binary_sensor.py +++ b/tests/components/home_connect/test_binary_sensor.py @@ -52,7 +52,7 @@ async def test_paired_depaired_devices_flow( ) -> None: """Test that removed devices are correctly removed from and added to hass on API events.""" assert await integration_setup(client) - assert config_entry.state == ConfigEntryState.LOADED + assert config_entry.state is ConfigEntryState.LOADED device = device_registry.async_get_device(identifiers={(DOMAIN, appliance.ha_id)}) assert device @@ -128,7 +128,7 @@ async def test_connected_devices( client.get_status = AsyncMock(side_effect=get_status_side_effect) assert await integration_setup(client) - assert config_entry.state == ConfigEntryState.LOADED + assert config_entry.state is ConfigEntryState.LOADED client.get_status = get_status_original_mock device = device_registry.async_get_device(identifiers={(DOMAIN, appliance.ha_id)}) @@ -178,7 +178,7 @@ async def test_binary_sensors_entity_availability( "binary_sensor.washer_remote_control", ] assert await integration_setup(client) - assert config_entry.state == ConfigEntryState.LOADED + assert config_entry.state is ConfigEntryState.LOADED for entity_id in entity_ids: state = hass.states.get(entity_id) @@ -277,7 +277,7 @@ async def test_binary_sensors_functionality( ) -> None: """Tests for Home Connect Fridge appliance door states.""" assert await integration_setup(client) - assert config_entry.state == ConfigEntryState.LOADED + assert config_entry.state is ConfigEntryState.LOADED await client.add_events( [ EventMessage( @@ -313,7 +313,7 @@ async def test_connected_sensor_functionality( """Test if the connected binary sensor reports the right values.""" entity_id = "binary_sensor.washer_connectivity" assert await integration_setup(client) - assert config_entry.state == ConfigEntryState.LOADED + assert config_entry.state is ConfigEntryState.LOADED assert hass.states.is_state(entity_id, STATE_ON) diff --git a/tests/components/home_connect/test_button.py b/tests/components/home_connect/test_button.py index 1aca781def6..ee4d5f1d729 100644 --- a/tests/components/home_connect/test_button.py +++ b/tests/components/home_connect/test_button.py @@ -44,7 +44,7 @@ async def test_paired_depaired_devices_flow( ) -> None: """Test that removed devices are correctly removed from and added to hass on API events.""" assert await integration_setup(client) - assert config_entry.state == ConfigEntryState.LOADED + assert config_entry.state is ConfigEntryState.LOADED device = device_registry.async_get_device(identifiers={(DOMAIN, appliance.ha_id)}) assert device @@ -131,7 +131,7 @@ async def test_connected_devices( ) client.get_all_programs = AsyncMock(side_effect=get_all_programs_side_effect) assert await integration_setup(client) - assert config_entry.state == ConfigEntryState.LOADED + assert config_entry.state is ConfigEntryState.LOADED client.get_available_commands = get_available_commands_original_mock client.get_all_programs = get_all_programs_mock @@ -182,7 +182,7 @@ async def test_button_entity_availability( "button.washer_stop_program", ] assert await integration_setup(client) - assert config_entry.state == ConfigEntryState.LOADED + assert config_entry.state is ConfigEntryState.LOADED for entity_id in entity_ids: state = hass.states.get(entity_id) @@ -244,7 +244,7 @@ async def test_button_functionality( ) -> None: """Test if button entities availability are based on the appliance connection state.""" assert await integration_setup(client) - assert config_entry.state == ConfigEntryState.LOADED + assert config_entry.state is ConfigEntryState.LOADED entity = hass.states.get(entity_id) assert entity @@ -279,7 +279,7 @@ async def test_command_button_exception( ) ) assert await integration_setup(client_with_exception) - assert config_entry.state == ConfigEntryState.LOADED + assert config_entry.state is ConfigEntryState.LOADED entity = hass.states.get(entity_id) assert entity @@ -304,7 +304,7 @@ async def test_stop_program_button_exception( entity_id = "button.washer_stop_program" assert await integration_setup(client_with_exception) - assert config_entry.state == ConfigEntryState.LOADED + assert config_entry.state is ConfigEntryState.LOADED entity = hass.states.get(entity_id) assert entity diff --git a/tests/components/home_connect/test_config_flow.py b/tests/components/home_connect/test_config_flow.py index d5a01d03258..a8929120acb 100644 --- a/tests/components/home_connect/test_config_flow.py +++ b/tests/components/home_connect/test_config_flow.py @@ -189,7 +189,7 @@ async def test_reauth_flow( assert entry.state is ConfigEntryState.LOADED assert len(mock_setup_entry.mock_calls) == 1 - assert result["type"] == FlowResultType.ABORT + assert result["type"] is FlowResultType.ABORT assert result["reason"] == "reauth_successful" @@ -239,5 +239,5 @@ async def test_reauth_flow_with_different_account( result = await hass.config_entries.flow.async_configure(result["flow_id"]) await hass.async_block_till_done() - assert result["type"] == FlowResultType.ABORT + assert result["type"] is FlowResultType.ABORT assert result["reason"] == "wrong_account" diff --git a/tests/components/home_connect/test_coordinator.py b/tests/components/home_connect/test_coordinator.py index 1a51e5980cd..40af64f9042 100644 --- a/tests/components/home_connect/test_coordinator.py +++ b/tests/components/home_connect/test_coordinator.py @@ -99,7 +99,7 @@ async def test_coordinator_failure_refresh_and_stream( entity_id_2 = "binary_sensor.washer_remote_start" await async_setup_component(hass, HA_DOMAIN, {}) await integration_setup(client) - assert config_entry.state == ConfigEntryState.LOADED + assert config_entry.state is ConfigEntryState.LOADED state = hass.states.get(entity_id_1) assert state assert state.state != STATE_UNAVAILABLE @@ -219,7 +219,7 @@ async def test_coordinator_not_fetching_on_disconnected_appliance( appliance.connected = False await integration_setup(client) - assert config_entry.state == ConfigEntryState.LOADED + assert config_entry.state is ConfigEntryState.LOADED for method in INITIAL_FETCH_CLIENT_METHODS: assert getattr(client, method).call_count == 0 @@ -242,7 +242,7 @@ async def test_coordinator_update_failing( setattr(client, mock_method, AsyncMock(side_effect=HomeConnectError())) await integration_setup(client) - assert config_entry.state == ConfigEntryState.LOADED + assert config_entry.state is ConfigEntryState.LOADED getattr(client, mock_method).assert_called() @@ -285,7 +285,7 @@ async def test_event_listener( ) -> None: """Test that the event listener works.""" await integration_setup(client) - assert config_entry.state == ConfigEntryState.LOADED + assert config_entry.state is ConfigEntryState.LOADED state = hass.states.get(entity_id) @@ -351,7 +351,7 @@ async def tests_receive_setting_and_status_for_first_time_at_events( client.get_status = AsyncMock(return_value=ArrayOfStatus([])) await integration_setup(client) - assert config_entry.state == ConfigEntryState.LOADED + assert config_entry.state is ConfigEntryState.LOADED await client.add_events( [ @@ -391,7 +391,7 @@ async def tests_receive_setting_and_status_for_first_time_at_events( ) await hass.async_block_till_done() assert len(config_entry._background_tasks) == 1 - assert config_entry.state == ConfigEntryState.LOADED + assert config_entry.state is ConfigEntryState.LOADED async def test_event_listener_error( @@ -467,7 +467,7 @@ async def test_event_listener_resilience( await integration_setup(client) await hass.async_block_till_done() - assert config_entry.state == ConfigEntryState.LOADED + assert config_entry.state is ConfigEntryState.LOADED assert len(config_entry._background_tasks) == 1 state = hass.states.get(entity_id) @@ -527,7 +527,7 @@ async def test_devices_updated_on_refresh( await async_setup_component(hass, HA_DOMAIN, {}) await integration_setup(client) - assert config_entry.state == ConfigEntryState.LOADED + assert config_entry.state is ConfigEntryState.LOADED for appliance in appliances[:2]: assert device_registry.async_get_device({(DOMAIN, appliance.ha_id)}) @@ -559,7 +559,7 @@ async def test_paired_disconnected_devices_not_fetching( """Test that Home Connect API is not fetched after pairing a disconnected device.""" client.get_home_appliances = AsyncMock(return_value=ArrayOfHomeAppliances([])) assert await integration_setup(client) - assert config_entry.state == ConfigEntryState.LOADED + assert config_entry.state is ConfigEntryState.LOADED appliance.connected = False await client.add_events( @@ -595,7 +595,7 @@ async def test_coordinator_disabling_updates_for_appliance( issue_id = f"home_connect_too_many_connected_paired_events_{appliance_ha_id}" assert await integration_setup(client) - assert config_entry.state == ConfigEntryState.LOADED + assert config_entry.state is ConfigEntryState.LOADED assert hass.states.is_state("switch.dishwasher_power", STATE_ON) @@ -685,7 +685,7 @@ async def test_coordinator_disabling_updates_for_appliance_is_gone_after_entry_r issue_id = f"home_connect_too_many_connected_paired_events_{appliance_ha_id}" assert await integration_setup(client) - assert config_entry.state == ConfigEntryState.LOADED + assert config_entry.state is ConfigEntryState.LOADED assert hass.states.is_state("switch.dishwasher_power", STATE_ON) @@ -710,7 +710,7 @@ async def test_coordinator_disabling_updates_for_appliance_is_gone_after_entry_r assert not issue_registry.async_get_issue(DOMAIN, issue_id) assert await integration_setup(client) - assert config_entry.state == ConfigEntryState.LOADED + assert config_entry.state is ConfigEntryState.LOADED get_settings_original_side_effect = client.get_settings.side_effect diff --git a/tests/components/home_connect/test_diagnostics.py b/tests/components/home_connect/test_diagnostics.py index 9aef9e0d157..858f331a33d 100644 --- a/tests/components/home_connect/test_diagnostics.py +++ b/tests/components/home_connect/test_diagnostics.py @@ -26,7 +26,7 @@ async def test_async_get_config_entry_diagnostics( ) -> None: """Test config entry diagnostics.""" assert await integration_setup(client) - assert config_entry.state == ConfigEntryState.LOADED + assert config_entry.state is ConfigEntryState.LOADED assert await async_get_config_entry_diagnostics(hass, config_entry) == snapshot @@ -41,7 +41,7 @@ async def test_async_get_device_diagnostics( ) -> None: """Test device config entry diagnostics.""" assert await integration_setup(client) - assert config_entry.state == ConfigEntryState.LOADED + assert config_entry.state is ConfigEntryState.LOADED device = device_registry.async_get_or_create( config_entry_id=config_entry.entry_id, diff --git a/tests/components/home_connect/test_entity.py b/tests/components/home_connect/test_entity.py index 84d8178d4b7..61a0c4005fb 100644 --- a/tests/components/home_connect/test_entity.py +++ b/tests/components/home_connect/test_entity.py @@ -158,7 +158,7 @@ async def test_program_options_retrieval( ) assert await integration_setup(client) - assert config_entry.state == ConfigEntryState.LOADED + assert config_entry.state is ConfigEntryState.LOADED for entity_id, (state, _) in zip( option_entity_id.values(), options_state_stage_1, strict=True @@ -276,7 +276,7 @@ async def test_no_options_retrieval_on_unknown_program( client.get_all_programs = AsyncMock(side_effect=get_all_programs_with_options_mock) assert await integration_setup(client) - assert config_entry.state == ConfigEntryState.LOADED + assert config_entry.state is ConfigEntryState.LOADED assert client.get_available_program.call_count == 0 @@ -356,7 +356,7 @@ async def test_program_options_retrieval_after_appliance_connection( ) assert await integration_setup(client) - assert config_entry.state == ConfigEntryState.LOADED + assert config_entry.state is ConfigEntryState.LOADED assert not hass.states.get(option_entity_id) @@ -467,7 +467,7 @@ async def test_option_entity_functionality_exception( ) assert await integration_setup(client) - assert config_entry.state == ConfigEntryState.LOADED + assert config_entry.state is ConfigEntryState.LOADED assert hass.states.get(entity_id) diff --git a/tests/components/home_connect/test_init.py b/tests/components/home_connect/test_init.py index 9bd4eaeca0e..2820eea3031 100644 --- a/tests/components/home_connect/test_init.py +++ b/tests/components/home_connect/test_init.py @@ -47,12 +47,12 @@ async def test_entry_setup( ) -> None: """Test setup and unload.""" assert await integration_setup(client) - assert config_entry.state == ConfigEntryState.LOADED + assert config_entry.state is ConfigEntryState.LOADED assert await hass.config_entries.async_unload(config_entry.entry_id) await hass.async_block_till_done() - assert config_entry.state == ConfigEntryState.NOT_LOADED + assert config_entry.state is ConfigEntryState.NOT_LOADED @pytest.mark.parametrize("token_expiration_time", [12345]) @@ -85,7 +85,7 @@ async def test_token_refresh_success( client._auth = auth return client - assert config_entry.state == ConfigEntryState.NOT_LOADED + assert config_entry.state is ConfigEntryState.NOT_LOADED with ( patch("homeassistant.components.home_connect.PLATFORMS", platforms), patch("homeassistant.components.home_connect.HomeConnectClient") as client_mock, @@ -93,7 +93,7 @@ async def test_token_refresh_success( client_mock.side_effect = MagicMock(side_effect=init_side_effect) assert await hass.config_entries.async_setup(config_entry.entry_id) await hass.async_block_till_done() - assert config_entry.state == ConfigEntryState.LOADED + assert config_entry.state is ConfigEntryState.LOADED # Verify token request assert aioclient_mock.call_count == 1 @@ -154,7 +154,7 @@ async def test_token_refresh_error( **aioclient_mock_args, ) - assert config_entry.state == ConfigEntryState.NOT_LOADED + assert config_entry.state is ConfigEntryState.NOT_LOADED with patch( "homeassistant.components.home_connect.HomeConnectClient", return_value=client ): @@ -216,12 +216,12 @@ async def test_client_rate_limit_error( mock.side_effect = side_effect setattr(client, raising_exception_method, mock) - assert config_entry.state == ConfigEntryState.NOT_LOADED + assert config_entry.state is ConfigEntryState.NOT_LOADED with patch( "homeassistant.components.home_connect.coordinator.asyncio_sleep", ) as asyncio_sleep_mock: assert await integration_setup(client) - assert config_entry.state == ConfigEntryState.LOADED + assert config_entry.state is ConfigEntryState.LOADED assert mock.call_count >= 2 asyncio_sleep_mock.assert_called_once_with(retry_after) @@ -238,7 +238,7 @@ async def test_required_program_or_at_least_an_option( "Test that the set_program_and_options does raise an exception if no program nor options are set." assert await integration_setup(client) - assert config_entry.state == ConfigEntryState.LOADED + assert config_entry.state is ConfigEntryState.LOADED device_entry = device_registry.async_get_or_create( config_entry_id=config_entry.entry_id, diff --git a/tests/components/home_connect/test_light.py b/tests/components/home_connect/test_light.py index abffa491ce4..b467dd2a7d2 100644 --- a/tests/components/home_connect/test_light.py +++ b/tests/components/home_connect/test_light.py @@ -65,7 +65,7 @@ async def test_paired_depaired_devices_flow( ) -> None: """Test that removed devices are correctly removed from and added to hass on API events.""" assert await integration_setup(client) - assert config_entry.state == ConfigEntryState.LOADED + assert config_entry.state is ConfigEntryState.LOADED device = device_registry.async_get_device(identifiers={(DOMAIN, appliance.ha_id)}) assert device @@ -141,7 +141,7 @@ async def test_connected_devices( client.get_settings = AsyncMock(side_effect=get_settings_side_effect) assert await integration_setup(client) - assert config_entry.state == ConfigEntryState.LOADED + assert config_entry.state is ConfigEntryState.LOADED client.get_settings = get_settings_original_mock device = device_registry.async_get_device(identifiers={(DOMAIN, appliance.ha_id)}) @@ -185,7 +185,7 @@ async def test_light_availability( "light.hood_functional_light", ] assert await integration_setup(client) - assert config_entry.state == ConfigEntryState.LOADED + assert config_entry.state is ConfigEntryState.LOADED for entity_id in entity_ids: state = hass.states.get(entity_id) @@ -351,7 +351,7 @@ async def test_light_functionality( ) -> None: """Test light functionality.""" assert await integration_setup(client) - assert config_entry.state == ConfigEntryState.LOADED + assert config_entry.state is ConfigEntryState.LOADED service_data = exprected_attributes.copy() service_data[ATTR_ENTITY_ID] = entity_id @@ -402,7 +402,7 @@ async def test_light_color_different_than_custom( ) -> None: """Test that light color attributes are not set if color is different than custom.""" assert await integration_setup(client) - assert config_entry.state == ConfigEntryState.LOADED + assert config_entry.state is ConfigEntryState.LOADED await hass.services.async_call( LIGHT_DOMAIN, SERVICE_TURN_ON, @@ -582,7 +582,7 @@ async def test_light_exception_handling( exception() if exception else None for exception in attr_side_effect ] assert await integration_setup(client_with_exception) - assert config_entry.state == ConfigEntryState.LOADED + assert config_entry.state is ConfigEntryState.LOADED # Assert that an exception is called. with pytest.raises(HomeConnectError): diff --git a/tests/components/home_connect/test_number.py b/tests/components/home_connect/test_number.py index 1f2a9b8d73f..58d6dae2900 100644 --- a/tests/components/home_connect/test_number.py +++ b/tests/components/home_connect/test_number.py @@ -81,7 +81,7 @@ async def test_paired_depaired_devices_flow( ) ) assert await integration_setup(client) - assert config_entry.state == ConfigEntryState.LOADED + assert config_entry.state is ConfigEntryState.LOADED device = device_registry.async_get_device(identifiers={(DOMAIN, appliance.ha_id)}) assert device @@ -159,7 +159,7 @@ async def test_connected_devices( client.get_settings = AsyncMock(side_effect=get_settings_side_effect) assert await integration_setup(client) - assert config_entry.state == ConfigEntryState.LOADED + assert config_entry.state is ConfigEntryState.LOADED client.get_settings = get_settings_original_mock device = device_registry.async_get_device(identifiers={(DOMAIN, appliance.ha_id)}) @@ -208,7 +208,7 @@ async def test_number_entity_availability( # so we rise an error to easily test the availability client.get_setting = AsyncMock(side_effect=HomeConnectError()) assert await integration_setup(client) - assert config_entry.state == ConfigEntryState.LOADED + assert config_entry.state is ConfigEntryState.LOADED for entity_id in entity_ids: state = hass.states.get(entity_id) @@ -594,7 +594,7 @@ async def test_options_functionality( ) assert await integration_setup(client) - assert config_entry.state == ConfigEntryState.LOADED + assert config_entry.state is ConfigEntryState.LOADED entity_state = hass.states.get(entity_id) assert entity_state assert entity_state.attributes["unit_of_measurement"] == unit diff --git a/tests/components/home_connect/test_select.py b/tests/components/home_connect/test_select.py index 11f6b3ce94b..a4263808276 100644 --- a/tests/components/home_connect/test_select.py +++ b/tests/components/home_connect/test_select.py @@ -85,7 +85,7 @@ async def test_paired_depaired_devices_flow( ) ) assert await integration_setup(client) - assert config_entry.state == ConfigEntryState.LOADED + assert config_entry.state is ConfigEntryState.LOADED device = device_registry.async_get_device(identifiers={(DOMAIN, appliance.ha_id)}) assert device @@ -174,7 +174,7 @@ async def test_connected_devices( client.get_settings = AsyncMock(side_effect=get_settings_side_effect) client.get_all_programs = AsyncMock(side_effect=get_all_programs_side_effect) assert await integration_setup(client) - assert config_entry.state == ConfigEntryState.LOADED + assert config_entry.state is ConfigEntryState.LOADED client.get_settings = get_settings_original_mock client.get_all_programs = get_all_programs_mock @@ -219,7 +219,7 @@ async def test_select_entity_availability( "select.washer_active_program", ] assert await integration_setup(client) - assert config_entry.state == ConfigEntryState.LOADED + assert config_entry.state is ConfigEntryState.LOADED for entity_id in entity_ids: state = hass.states.get(entity_id) @@ -489,7 +489,7 @@ async def test_programs_updated_on_connect( client.get_all_programs = AsyncMock(side_effect=get_all_programs_side_effect) assert await integration_setup(client) - assert config_entry.state == ConfigEntryState.LOADED + assert config_entry.state is ConfigEntryState.LOADED client.get_all_programs = get_all_programs_mock state = hass.states.get("select.washer_active_program") @@ -941,7 +941,7 @@ async def test_options_functionality( ) assert await integration_setup(client) - assert config_entry.state == ConfigEntryState.LOADED + assert config_entry.state is ConfigEntryState.LOADED entity_state = hass.states.get(entity_id) assert entity_state assert set(entity_state.attributes[ATTR_OPTIONS]) == expected_options diff --git a/tests/components/home_connect/test_sensor.py b/tests/components/home_connect/test_sensor.py index 33cb8d2c804..47badd8d06d 100644 --- a/tests/components/home_connect/test_sensor.py +++ b/tests/components/home_connect/test_sensor.py @@ -101,7 +101,7 @@ async def test_paired_depaired_devices_flow( ) -> None: """Test that removed devices are correctly removed from and added to hass on API events.""" assert await integration_setup(client) - assert config_entry.state == ConfigEntryState.LOADED + assert config_entry.state is ConfigEntryState.LOADED device = device_registry.async_get_device(identifiers={(DOMAIN, appliance.ha_id)}) assert device @@ -200,7 +200,7 @@ async def test_connected_devices( client.get_status = AsyncMock(side_effect=get_status_side_effect) assert await integration_setup(client) - assert config_entry.state == ConfigEntryState.LOADED + assert config_entry.state is ConfigEntryState.LOADED client.get_status = get_status_original_mock device = device_registry.async_get_device(identifiers={(DOMAIN, appliance.ha_id)}) @@ -245,7 +245,7 @@ async def test_sensor_entity_availability( "sensor.dishwasher_salt_nearly_empty", ] assert await integration_setup(client) - assert config_entry.state == ConfigEntryState.LOADED + assert config_entry.state is ConfigEntryState.LOADED await client.add_events( [ @@ -367,7 +367,7 @@ async def test_program_sensors( time_to_freeze = "2021-01-09 12:00:00+00:00" freezer.move_to(time_to_freeze) - assert config_entry.state == ConfigEntryState.NOT_LOADED + assert config_entry.state is ConfigEntryState.NOT_LOADED client.get_status.return_value.status.extend( Status( key=StatusKey(event_key.value), @@ -377,7 +377,7 @@ async def test_program_sensors( for event_key, value in EVENT_PROG_DELAYED_START[EventType.STATUS].items() ) assert await integration_setup(client) - assert config_entry.state == ConfigEntryState.LOADED + assert config_entry.state is ConfigEntryState.LOADED await client.add_events( [ @@ -450,7 +450,7 @@ async def test_program_sensor_edge_case( ) assert await integration_setup(client) - assert config_entry.state == ConfigEntryState.LOADED + assert config_entry.state is ConfigEntryState.LOADED assert hass.states.is_state(entity_id, initial_state) @@ -512,7 +512,7 @@ async def test_remaining_prog_time_edge_cases( freezer.move_to(time_to_freeze) assert await integration_setup(client) - assert config_entry.state == ConfigEntryState.LOADED + assert config_entry.state is ConfigEntryState.LOADED for ( event, @@ -587,7 +587,7 @@ async def test_sensors_states( ) -> None: """Tests for appliance sensors.""" assert await integration_setup(client) - assert config_entry.state == ConfigEntryState.LOADED + assert config_entry.state is ConfigEntryState.LOADED for value, expected_state in value_expected_state: await client.add_events( @@ -648,7 +648,7 @@ async def test_event_sensors_states( """Tests for appliance event sensors.""" caplog.set_level(logging.ERROR) assert await integration_setup(client) - assert config_entry.state == ConfigEntryState.LOADED + assert config_entry.state is ConfigEntryState.LOADED assert not hass.states.get(entity_id) @@ -757,7 +757,7 @@ async def test_sensor_unit_fetching( ) assert await integration_setup(client) - assert config_entry.state == ConfigEntryState.LOADED + assert config_entry.state is ConfigEntryState.LOADED entity_state = hass.states.get(entity_id) assert entity_state @@ -812,7 +812,7 @@ async def test_sensor_unit_fetching_error( client.get_status_value = AsyncMock(side_effect=HomeConnectError()) assert await integration_setup(client) - assert config_entry.state == ConfigEntryState.LOADED + assert config_entry.state is ConfigEntryState.LOADED assert hass.states.get(entity_id) @@ -875,7 +875,7 @@ async def test_sensor_unit_fetching_after_rate_limit_error( assert await integration_setup(client) async_fire_time_changed(hass) await hass.async_block_till_done() - assert config_entry.state == ConfigEntryState.LOADED + assert config_entry.state is ConfigEntryState.LOADED assert client.get_status_value.call_count == 2 diff --git a/tests/components/home_connect/test_services.py b/tests/components/home_connect/test_services.py index 97c60a72237..33a7f7aee71 100644 --- a/tests/components/home_connect/test_services.py +++ b/tests/components/home_connect/test_services.py @@ -186,7 +186,7 @@ async def test_key_value_services( ) -> None: """Create and test services.""" assert await integration_setup(client) - assert config_entry.state == ConfigEntryState.LOADED + assert config_entry.state is ConfigEntryState.LOADED device_entry = device_registry.async_get_or_create( config_entry_id=config_entry.entry_id, @@ -236,7 +236,7 @@ async def test_programs_and_options_actions_deprecation( ) -> None: """Test deprecated service keys.""" assert await integration_setup(client) - assert config_entry.state == ConfigEntryState.LOADED + assert config_entry.state is ConfigEntryState.LOADED device_entry = device_registry.async_get_or_create( config_entry_id=config_entry.entry_id, @@ -304,7 +304,7 @@ async def test_set_program_and_options( ) -> None: """Test recognized options.""" assert await integration_setup(client) - assert config_entry.state == ConfigEntryState.LOADED + assert config_entry.state is ConfigEntryState.LOADED device_entry = device_registry.async_get_or_create( config_entry_id=config_entry.entry_id, @@ -345,7 +345,7 @@ async def test_set_program_and_options_exceptions( ) -> None: """Test recognized options.""" assert await integration_setup(client_with_exception) - assert config_entry.state == ConfigEntryState.LOADED + assert config_entry.state is ConfigEntryState.LOADED device_entry = device_registry.async_get_or_create( config_entry_id=config_entry.entry_id, @@ -373,7 +373,7 @@ async def test_services_exception_device_id( ) -> None: """Raise a HomeAssistantError when there is an API error.""" assert await integration_setup(client_with_exception) - assert config_entry.state == ConfigEntryState.LOADED + assert config_entry.state is ConfigEntryState.LOADED device_entry = device_registry.async_get_or_create( config_entry_id=config_entry.entry_id, @@ -395,7 +395,7 @@ async def test_services_appliance_not_found( ) -> None: """Raise a ServiceValidationError when device id does not match.""" assert await integration_setup(client) - assert config_entry.state == ConfigEntryState.LOADED + assert config_entry.state is ConfigEntryState.LOADED service_call = SERVICE_KV_CALL_PARAMS[0] @@ -443,7 +443,7 @@ async def test_services_exception( ) -> None: """Raise a ValueError when device id does not match.""" assert await integration_setup(client_with_exception) - assert config_entry.state == ConfigEntryState.LOADED + assert config_entry.state is ConfigEntryState.LOADED device_entry = device_registry.async_get_or_create( config_entry_id=config_entry.entry_id, diff --git a/tests/components/home_connect/test_switch.py b/tests/components/home_connect/test_switch.py index 404e3a5bcea..40d2468fb3e 100644 --- a/tests/components/home_connect/test_switch.py +++ b/tests/components/home_connect/test_switch.py @@ -92,7 +92,7 @@ async def test_paired_depaired_devices_flow( ) ) assert await integration_setup(client) - assert config_entry.state == ConfigEntryState.LOADED + assert config_entry.state is ConfigEntryState.LOADED device = device_registry.async_get_device(identifiers={(DOMAIN, appliance.ha_id)}) assert device @@ -181,7 +181,7 @@ async def test_connected_devices( client.get_settings = AsyncMock(side_effect=get_settings_side_effect) client.get_all_programs = AsyncMock(side_effect=get_all_programs_side_effect) assert await integration_setup(client) - assert config_entry.state == ConfigEntryState.LOADED + assert config_entry.state is ConfigEntryState.LOADED client.get_settings = get_settings_original_mock client.get_all_programs = get_all_programs_mock @@ -229,7 +229,7 @@ async def test_switch_entity_availability( "switch.dishwasher_program_eco50", ] assert await integration_setup(client) - assert config_entry.state == ConfigEntryState.LOADED + assert config_entry.state is ConfigEntryState.LOADED for entity_id in entity_ids: state = hass.states.get(entity_id) @@ -311,7 +311,7 @@ async def test_switch_functionality( """Test switch functionality.""" assert await integration_setup(client) - assert config_entry.state == ConfigEntryState.LOADED + assert config_entry.state is ConfigEntryState.LOADED await hass.services.async_call(SWITCH_DOMAIN, service, {ATTR_ENTITY_ID: entity_id}) await hass.async_block_till_done() @@ -377,7 +377,7 @@ async def test_program_switch_functionality( client.stop_program = AsyncMock(side_effect=mock_stop_program) assert await integration_setup(client) - assert config_entry.state == ConfigEntryState.LOADED + assert config_entry.state is ConfigEntryState.LOADED assert hass.states.is_state(entity_id, initial_state) await hass.services.async_call( @@ -484,7 +484,7 @@ async def test_switch_exception_handling( ) assert await integration_setup(client_with_exception) - assert config_entry.state == ConfigEntryState.LOADED + assert config_entry.state is ConfigEntryState.LOADED # Assert that an exception is called. with pytest.raises(HomeConnectError): @@ -527,7 +527,7 @@ async def test_ent_desc_switch_functionality( """Test switch functionality - entity description setup.""" assert await integration_setup(client) - assert config_entry.state == ConfigEntryState.LOADED + assert config_entry.state is ConfigEntryState.LOADED await hass.services.async_call(SWITCH_DOMAIN, service, {ATTR_ENTITY_ID: entity_id}) await hass.async_block_till_done() @@ -583,7 +583,7 @@ async def test_ent_desc_switch_exception_handling( ] ) assert await integration_setup(client_with_exception) - assert config_entry.state == ConfigEntryState.LOADED + assert config_entry.state is ConfigEntryState.LOADED # Assert that an exception is called. with pytest.raises(HomeConnectError): @@ -668,7 +668,7 @@ async def test_power_switch( ) assert await integration_setup(client) - assert config_entry.state == ConfigEntryState.LOADED + assert config_entry.state is ConfigEntryState.LOADED await hass.services.async_call(SWITCH_DOMAIN, service, {ATTR_ENTITY_ID: entity_id}) await hass.async_block_till_done() @@ -707,7 +707,7 @@ async def test_power_switch_fetch_off_state_from_current_value( ) assert await integration_setup(client) - assert config_entry.state == ConfigEntryState.LOADED + assert config_entry.state is ConfigEntryState.LOADED assert hass.states.is_state("switch.dishwasher_power", STATE_OFF) @@ -772,7 +772,7 @@ async def test_power_switch_service_validation_errors( client.get_setting = AsyncMock(return_value=setting) assert await integration_setup(client) - assert config_entry.state == ConfigEntryState.LOADED + assert config_entry.state is ConfigEntryState.LOADED with pytest.raises(HomeAssistantError, match=exception_match): await hass.services.async_call( @@ -832,7 +832,7 @@ async def test_create_program_switch_deprecation_issue( ) assert await integration_setup(client) - assert config_entry.state == ConfigEntryState.LOADED + assert config_entry.state is ConfigEntryState.LOADED await hass.services.async_call( SWITCH_DOMAIN, @@ -912,7 +912,7 @@ async def test_program_switch_deprecation_issue_fix( ) assert await integration_setup(client) - assert config_entry.state == ConfigEntryState.LOADED + assert config_entry.state is ConfigEntryState.LOADED await hass.services.async_call( SWITCH_DOMAIN, @@ -1006,7 +1006,7 @@ async def test_options_functionality( ) assert await integration_setup(client) - assert config_entry.state == ConfigEntryState.LOADED + assert config_entry.state is ConfigEntryState.LOADED assert hass.states.get(entity_id) await hass.services.async_call( diff --git a/tests/components/home_connect/test_time.py b/tests/components/home_connect/test_time.py index c94f3affc41..9e114768b6f 100644 --- a/tests/components/home_connect/test_time.py +++ b/tests/components/home_connect/test_time.py @@ -58,7 +58,7 @@ async def test_paired_depaired_devices_flow( ) -> None: """Test that removed devices are correctly removed from and added to hass on API events.""" assert await integration_setup(client) - assert config_entry.state == ConfigEntryState.LOADED + assert config_entry.state is ConfigEntryState.LOADED device = device_registry.async_get_device(identifiers={(DOMAIN, appliance.ha_id)}) assert device @@ -135,7 +135,7 @@ async def test_connected_devices( client.get_settings = AsyncMock(side_effect=get_settings_side_effect) assert await integration_setup(client) - assert config_entry.state == ConfigEntryState.LOADED + assert config_entry.state is ConfigEntryState.LOADED client.get_settings = get_settings_original_mock device = device_registry.async_get_device(identifiers={(DOMAIN, appliance.ha_id)}) @@ -180,7 +180,7 @@ async def test_time_entity_availability( "time.oven_alarm_clock", ] assert await integration_setup(client) - assert config_entry.state == ConfigEntryState.LOADED + assert config_entry.state is ConfigEntryState.LOADED for entity_id in entity_ids: state = hass.states.get(entity_id) @@ -363,7 +363,7 @@ async def test_create_alarm_clock_deprecation_issue( ) assert await integration_setup(client) - assert config_entry.state == ConfigEntryState.LOADED + assert config_entry.state is ConfigEntryState.LOADED await hass.services.async_call( TIME_DOMAIN, @@ -442,7 +442,7 @@ async def test_alarm_clock_deprecation_issue_fix( ) assert await integration_setup(client) - assert config_entry.state == ConfigEntryState.LOADED + assert config_entry.state is ConfigEntryState.LOADED await hass.services.async_call( TIME_DOMAIN, From 86b845f04acb6f4368c46cd4b912fd2053f38bae Mon Sep 17 00:00:00 2001 From: Shay Levy Date: Fri, 2 May 2025 12:32:41 +0300 Subject: [PATCH 04/90] Mark exception-translations done in Shelly (#144073) --- homeassistant/components/shelly/quality_scale.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/homeassistant/components/shelly/quality_scale.yaml b/homeassistant/components/shelly/quality_scale.yaml index 83c3739a208..601170879d1 100644 --- a/homeassistant/components/shelly/quality_scale.yaml +++ b/homeassistant/components/shelly/quality_scale.yaml @@ -56,7 +56,7 @@ rules: entity-device-class: done entity-disabled-by-default: done entity-translations: todo - exception-translations: todo + exception-translations: done icon-translations: todo reconfiguration-flow: done repair-issues: done From b0f1c71129dbb04418c60498cdd9267af544355b Mon Sep 17 00:00:00 2001 From: Simone Chemelli Date: Fri, 2 May 2025 12:39:28 +0300 Subject: [PATCH 05/90] Handle missing action exceptions in SamsungTV (#143630) Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> --- homeassistant/components/samsungtv/bridge.py | 10 +++++-- .../components/samsungtv/media_player.py | 10 +++++-- .../components/samsungtv/strings.json | 6 ++++ .../components/samsungtv/test_media_player.py | 30 +++++++++---------- 4 files changed, 37 insertions(+), 19 deletions(-) diff --git a/homeassistant/components/samsungtv/bridge.py b/homeassistant/components/samsungtv/bridge.py index e782b1dfcd9..11da83219c7 100644 --- a/homeassistant/components/samsungtv/bridge.py +++ b/homeassistant/components/samsungtv/bridge.py @@ -46,6 +46,7 @@ from homeassistant.const import ( CONF_TOKEN, ) from homeassistant.core import CALLBACK_TYPE, HomeAssistant +from homeassistant.exceptions import HomeAssistantError from homeassistant.helpers import entity_component from homeassistant.helpers.aiohttp_client import async_get_clientsession from homeassistant.helpers.device_registry import format_mac @@ -53,6 +54,7 @@ from homeassistant.util import dt as dt_util from .const import ( CONF_SESSION_ID, + DOMAIN, ENCRYPTED_WEBSOCKET_PORT, LEGACY_PORT, LOGGER, @@ -371,9 +373,13 @@ class SamsungTVLegacyBridge(SamsungTVBridge): except (ConnectionClosed, BrokenPipeError): # BrokenPipe can occur when the commands is sent to fast self._remote = None - except (UnhandledResponse, AccessDenied): + except (UnhandledResponse, AccessDenied) as err: # We got a response so it's on. - LOGGER.debug("Failed sending command %s", key, exc_info=True) + raise HomeAssistantError( + translation_domain=DOMAIN, + translation_key="error_sending_command", + translation_placeholders={"error": repr(err), "host": self.host}, + ) from err except OSError: # Different reasons, e.g. hostname not resolveable pass diff --git a/homeassistant/components/samsungtv/media_player.py b/homeassistant/components/samsungtv/media_player.py index 4fb2e6bd1a2..cc3ca5f142e 100644 --- a/homeassistant/components/samsungtv/media_player.py +++ b/homeassistant/components/samsungtv/media_player.py @@ -29,13 +29,14 @@ from homeassistant.components.media_player import ( MediaType, ) from homeassistant.core import HomeAssistant, callback +from homeassistant.exceptions import HomeAssistantError from homeassistant.helpers import config_validation as cv from homeassistant.helpers.aiohttp_client import async_get_clientsession from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback from homeassistant.util.async_ import create_eager_task from .bridge import SamsungTVWSBridge -from .const import CONF_SSDP_RENDERING_CONTROL_LOCATION, LOGGER +from .const import CONF_SSDP_RENDERING_CONTROL_LOCATION, DOMAIN, LOGGER from .coordinator import SamsungTVConfigEntry, SamsungTVDataUpdateCoordinator from .entity import SamsungTVEntity @@ -308,7 +309,12 @@ class SamsungTVDevice(SamsungTVEntity, MediaPlayerEntity): try: await dmr_device.async_set_volume_level(volume) except UpnpActionResponseError as err: - LOGGER.warning("Unable to set volume level on %s: %r", self._host, err) + assert self._host + raise HomeAssistantError( + translation_domain=DOMAIN, + translation_key="error_set_volume", + translation_placeholders={"error": repr(err), "host": self._host}, + ) from err async def async_volume_up(self) -> None: """Volume up the media player.""" diff --git a/homeassistant/components/samsungtv/strings.json b/homeassistant/components/samsungtv/strings.json index 84e5fded03f..fc3be3fcc19 100644 --- a/homeassistant/components/samsungtv/strings.json +++ b/homeassistant/components/samsungtv/strings.json @@ -68,6 +68,12 @@ "service_unsupported": { "message": "Entity {entity} does not support this action." }, + "error_set_volume": { + "message": "Unable to set volume level on {host}: {error}" + }, + "error_sending_command": { + "message": "Unable to send command to {host}: {error}" + }, "encrypted_mode_auth_failed": { "message": "Token and session ID are required in encrypted mode." }, diff --git a/tests/components/samsungtv/test_media_player.py b/tests/components/samsungtv/test_media_player.py index 0a4587827d1..7dc5c6489d8 100644 --- a/tests/components/samsungtv/test_media_player.py +++ b/tests/components/samsungtv/test_media_player.py @@ -77,7 +77,7 @@ from homeassistant.const import ( STATE_UNAVAILABLE, ) from homeassistant.core import HomeAssistant -from homeassistant.exceptions import ServiceNotSupported +from homeassistant.exceptions import HomeAssistantError, ServiceNotSupported from homeassistant.setup import async_setup_component from . import setup_samsungtv_entry @@ -563,9 +563,11 @@ async def test_send_key_unhandled_response(hass: HomeAssistant, remote: Mock) -> """Testing unhandled response exception.""" await setup_samsungtv_entry(hass, MOCK_CONFIG) remote.control = Mock(side_effect=exceptions.UnhandledResponse("Boom")) - await hass.services.async_call( - MP_DOMAIN, SERVICE_VOLUME_UP, {ATTR_ENTITY_ID: ENTITY_ID}, True - ) + with pytest.raises(HomeAssistantError) as err: + await hass.services.async_call( + MP_DOMAIN, SERVICE_VOLUME_UP, {ATTR_ENTITY_ID: ENTITY_ID}, True + ) + assert err.value.translation_key == "error_sending_command" state = hass.states.get(ENTITY_ID) assert state.state == STATE_ON @@ -1219,9 +1221,7 @@ async def test_websocket_unsupported_remote_control( @pytest.mark.usefixtures("remotews", "rest_api", "upnp_notify_server") -async def test_volume_control_upnp( - hass: HomeAssistant, dmr_device: Mock, caplog: pytest.LogCaptureFixture -) -> None: +async def test_volume_control_upnp(hass: HomeAssistant, dmr_device: Mock) -> None: """Test for Upnp volume control.""" await setup_samsungtv_entry(hass, MOCK_ENTRY_WS) @@ -1237,21 +1237,21 @@ async def test_volume_control_upnp( True, ) dmr_device.async_set_volume_level.assert_called_once_with(0.5) - assert "Unable to set volume level on" not in caplog.text # Upnp action failed dmr_device.async_set_volume_level.reset_mock() dmr_device.async_set_volume_level.side_effect = UpnpActionResponseError( status=500, error_code=501, error_desc="Action Failed" ) - await hass.services.async_call( - MP_DOMAIN, - SERVICE_VOLUME_SET, - {ATTR_ENTITY_ID: ENTITY_ID, ATTR_MEDIA_VOLUME_LEVEL: 0.6}, - True, - ) + with pytest.raises(HomeAssistantError) as err: + await hass.services.async_call( + MP_DOMAIN, + SERVICE_VOLUME_SET, + {ATTR_ENTITY_ID: ENTITY_ID, ATTR_MEDIA_VOLUME_LEVEL: 0.6}, + True, + ) + assert err.value.translation_key == "error_set_volume" dmr_device.async_set_volume_level.assert_called_once_with(0.6) - assert "Unable to set volume level on" in caplog.text @pytest.mark.usefixtures("remotews", "rest_api") From 9861bd88b9b773ec314b97228f2bf08b410df170 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Fri, 2 May 2025 04:44:38 -0500 Subject: [PATCH 06/90] Avoid working out suggested id in entity_platform when already registered (#144079) If the entity is already registered, avoid trying to work out the suggested_entity_id and suggested_object_id as async_get_or_create will discard them anyways. --- homeassistant/helpers/entity_platform.py | 41 ++++++++++++++---------- 1 file changed, 24 insertions(+), 17 deletions(-) diff --git a/homeassistant/helpers/entity_platform.py b/homeassistant/helpers/entity_platform.py index d4fa567e929..f543891d3f3 100644 --- a/homeassistant/helpers/entity_platform.py +++ b/homeassistant/helpers/entity_platform.py @@ -843,24 +843,31 @@ class EntityPlatform: else: device = None - # An entity may suggest the entity_id by setting entity_id itself - suggested_entity_id: str | None = entity.entity_id - if suggested_entity_id is not None: - suggested_object_id = split_entity_id(entity.entity_id)[1] - else: - if device and entity.has_entity_name: - device_name = device.name_by_user or device.name - if entity.use_device_name: - suggested_object_id = device_name - else: - suggested_object_id = ( - f"{device_name} {entity.suggested_object_id}" - ) - if not suggested_object_id: - suggested_object_id = entity.suggested_object_id + if not registered_entity_id: + # Do not bother working out a suggested_object_id + # if the entity is already registered as it will + # be ignored. + # + # An entity may suggest the entity_id by setting entity_id itself + suggested_entity_id: str | None = entity.entity_id + if suggested_entity_id is not None: + suggested_object_id = split_entity_id(entity.entity_id)[1] + else: + if device and entity.has_entity_name: + device_name = device.name_by_user or device.name + if entity.use_device_name: + suggested_object_id = device_name + else: + suggested_object_id = ( + f"{device_name} {entity.suggested_object_id}" + ) + if not suggested_object_id: + suggested_object_id = entity.suggested_object_id - if self.entity_namespace is not None: - suggested_object_id = f"{self.entity_namespace} {suggested_object_id}" + if self.entity_namespace is not None: + suggested_object_id = ( + f"{self.entity_namespace} {suggested_object_id}" + ) disabled_by: RegistryEntryDisabler | None = None if not entity.entity_registry_enabled_default: From 81444c8f4a500d085d93d6142958c7a84049285d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Bed=C5=99ich?= Date: Fri, 2 May 2025 13:49:33 +0200 Subject: [PATCH 07/90] Disable S3 checksums (#144092) Disable S3 checksums (#143995) --- homeassistant/components/s3/__init__.py | 7 +++++++ tests/components/s3/test_init.py | 17 +++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/homeassistant/components/s3/__init__.py b/homeassistant/components/s3/__init__.py index 95e5e7d738c..ea6b8e244b1 100644 --- a/homeassistant/components/s3/__init__.py +++ b/homeassistant/components/s3/__init__.py @@ -7,6 +7,7 @@ from typing import cast from aiobotocore.client import AioBaseClient as S3Client from aiobotocore.session import AioSession +from botocore.config import Config from botocore.exceptions import ClientError, ConnectionError, ParamValidationError from homeassistant.config_entries import ConfigEntry @@ -32,6 +33,11 @@ async def async_setup_entry(hass: HomeAssistant, entry: S3ConfigEntry) -> bool: """Set up S3 from a config entry.""" data = cast(dict, entry.data) + # due to https://github.com/home-assistant/core/issues/143995 + config = Config( + request_checksum_calculation="when_required", + response_checksum_validation="when_required", + ) try: session = AioSession() # pylint: disable-next=unnecessary-dunder-call @@ -40,6 +46,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: S3ConfigEntry) -> bool: endpoint_url=data.get(CONF_ENDPOINT_URL), aws_secret_access_key=data[CONF_SECRET_ACCESS_KEY], aws_access_key_id=data[CONF_ACCESS_KEY_ID], + config=config, ).__aenter__() await client.head_bucket(Bucket=data[CONF_BUCKET]) except ClientError as err: diff --git a/tests/components/s3/test_init.py b/tests/components/s3/test_init.py index afa11f5cf72..8255bbd0c66 100644 --- a/tests/components/s3/test_init.py +++ b/tests/components/s3/test_init.py @@ -2,6 +2,7 @@ from unittest.mock import AsyncMock, patch +from botocore.config import Config from botocore.exceptions import ( ClientError, EndpointConnectionError, @@ -73,3 +74,19 @@ async def test_setup_entry_head_bucket_error( ) await setup_integration(hass, mock_config_entry) assert mock_config_entry.state is ConfigEntryState.SETUP_ERROR + + +async def test_checksum_settings_present( + hass: HomeAssistant, mock_config_entry: MockConfigEntry +) -> None: + """Test that checksum validation is set to be compatible with third-party S3 providers.""" + # due to https://github.com/home-assistant/core/issues/143995 + with patch( + "homeassistant.components.s3.AioSession.create_client" + ) as mock_create_client: + await setup_integration(hass, mock_config_entry) + + config_arg = mock_create_client.call_args[1]["config"] + assert isinstance(config_arg, Config) + assert config_arg.request_checksum_calculation == "when_required" + assert config_arg.response_checksum_validation == "when_required" From cbf4676ae405da3b4f9689a23ad30f43336ea0ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=85ke=20Strandberg?= Date: Fri, 2 May 2025 17:31:11 +0200 Subject: [PATCH 08/90] Improve handling of missing miele program codes (#144093) * Use device class transation * Improve handling of unknown program codes * Address review comment --- homeassistant/components/miele/const.py | 20 ++++++++++------ homeassistant/components/miele/sensor.py | 24 +++---------------- .../miele/snapshots/test_sensor.ambr | 2 ++ 3 files changed, 18 insertions(+), 28 deletions(-) diff --git a/homeassistant/components/miele/const.py b/homeassistant/components/miele/const.py index e77afe02e00..1802c6c9cd0 100644 --- a/homeassistant/components/miele/const.py +++ b/homeassistant/components/miele/const.py @@ -2,6 +2,8 @@ from enum import IntEnum +from pymiele import MieleEnum + DOMAIN = "miele" MANUFACTURER = "Miele" @@ -325,13 +327,17 @@ STATE_PROGRAM_PHASE: dict[int, dict[int, str]] = { MieleAppliance.ROBOT_VACUUM_CLEANER: STATE_PROGRAM_PHASE_ROBOT_VACUUM_CLEANER, } -STATE_PROGRAM_TYPE = { - 0: "normal_operation_mode", - 1: "own_program", - 2: "automatic_program", - 3: "cleaning_care_program", - 4: "maintenance_program", -} + +class StateProgramType(MieleEnum): + """Defines program types.""" + + normal_operation_mode = 0 + own_program = 1 + automatic_program = 2 + cleaning_care_program = 3 + maintenance_program = 4 + unknown = -9999 + WASHING_MACHINE_PROGRAM_ID: dict[int, str] = { -1: "no_program", # Extrapolated from other device types. diff --git a/homeassistant/components/miele/sensor.py b/homeassistant/components/miele/sensor.py index b2ddd695042..867de3d814b 100644 --- a/homeassistant/components/miele/sensor.py +++ b/homeassistant/components/miele/sensor.py @@ -30,9 +30,9 @@ from homeassistant.helpers.typing import StateType from .const import ( STATE_PROGRAM_ID, STATE_PROGRAM_PHASE, - STATE_PROGRAM_TYPE, STATE_STATUS_TAGS, MieleAppliance, + StateProgramType, StateStatus, ) from .coordinator import MieleConfigEntry, MieleDataUpdateCoordinator @@ -181,10 +181,10 @@ SENSOR_TYPES: Final[tuple[MieleSensorDefinition, ...]] = ( description=MieleSensorDescription( key="state_program_type", translation_key="program_type", - value_fn=lambda value: value.state_program_type, + value_fn=lambda value: StateProgramType(value.state_program_type).name, entity_category=EntityCategory.DIAGNOSTIC, device_class=SensorDeviceClass.ENUM, - options=sorted(set(STATE_PROGRAM_TYPE.values())), + options=sorted(set(StateProgramType.keys())), ), ), MieleSensorDefinition( @@ -440,8 +440,6 @@ async def async_setup_entry( entity_class = MieleProgramIdSensor case "state_program_phase": entity_class = MielePhaseSensor - case "state_program_type": - entity_class = MieleTypeSensor case _: entity_class = MieleSensor if ( @@ -553,22 +551,6 @@ class MielePhaseSensor(MieleSensor): ) -class MieleTypeSensor(MieleSensor): - """Representation of the program type sensor.""" - - @property - def native_value(self) -> StateType: - """Return the state of the sensor.""" - ret_val = STATE_PROGRAM_TYPE.get(int(self.device.state_program_type)) - if ret_val is None: - _LOGGER.debug( - "Unknown program type: %s on device type: %s", - self.device.state_program_type, - self.device.device_type, - ) - return ret_val - - class MieleProgramIdSensor(MieleSensor): """Representation of the program id sensor.""" diff --git a/tests/components/miele/snapshots/test_sensor.ambr b/tests/components/miele/snapshots/test_sensor.ambr index 9cc2aa83b01..bd9c305fe18 100644 --- a/tests/components/miele/snapshots/test_sensor.ambr +++ b/tests/components/miele/snapshots/test_sensor.ambr @@ -788,6 +788,7 @@ 'maintenance_program', 'normal_operation_mode', 'own_program', + 'unknown', ]), }), 'config_entry_id': , @@ -829,6 +830,7 @@ 'maintenance_program', 'normal_operation_mode', 'own_program', + 'unknown', ]), }), 'context': , From 5e463d6af49374a97acd6da6f2adbeed8584e344 Mon Sep 17 00:00:00 2001 From: Pete Sage <76050312+PeteRager@users.noreply.github.com> Date: Fri, 2 May 2025 11:34:58 -0400 Subject: [PATCH 09/90] bump aiokem to 0.5.9 (#144098) fix: bump aiokem to 0.5.9 --- homeassistant/components/rehlko/manifest.json | 2 +- requirements_all.txt | 2 +- requirements_test_all.txt | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/rehlko/manifest.json b/homeassistant/components/rehlko/manifest.json index 93e284167f5..0c9f0c20e6f 100644 --- a/homeassistant/components/rehlko/manifest.json +++ b/homeassistant/components/rehlko/manifest.json @@ -13,5 +13,5 @@ "iot_class": "cloud_polling", "loggers": ["aiokem"], "quality_scale": "silver", - "requirements": ["aiokem==0.5.6"] + "requirements": ["aiokem==0.5.9"] } diff --git a/requirements_all.txt b/requirements_all.txt index 593ba8bdacd..2c4eb978684 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -286,7 +286,7 @@ aiokafka==0.10.0 aiokef==0.2.16 # homeassistant.components.rehlko -aiokem==0.5.6 +aiokem==0.5.9 # homeassistant.components.lifx aiolifx-effects==0.3.2 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index 5b3bb6d0a40..ca4a2107cdb 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -268,7 +268,7 @@ aioimaplib==2.0.1 aiokafka==0.10.0 # homeassistant.components.rehlko -aiokem==0.5.6 +aiokem==0.5.9 # homeassistant.components.lifx aiolifx-effects==0.3.2 From 4967c287f87ee5ef9c11bce981f619684d59423b Mon Sep 17 00:00:00 2001 From: Joost Lekkerkerker Date: Fri, 2 May 2025 18:34:09 +0200 Subject: [PATCH 10/90] Add DHCP discovery to Knocki (#144048) * Add DHCP discovery to Knocki * Update homeassistant/components/knocki/quality_scale.yaml Co-authored-by: Josef Zweck --------- Co-authored-by: Josef Zweck --- .../components/knocki/config_flow.py | 18 +++++ homeassistant/components/knocki/manifest.json | 5 ++ .../components/knocki/quality_scale.yaml | 6 +- homeassistant/generated/dhcp.py | 4 + tests/components/knocki/__init__.py | 1 + tests/components/knocki/test_config_flow.py | 75 ++++++++++++++++++- 6 files changed, 104 insertions(+), 5 deletions(-) diff --git a/homeassistant/components/knocki/config_flow.py b/homeassistant/components/knocki/config_flow.py index 654dd4a4d1f..7818c752a87 100644 --- a/homeassistant/components/knocki/config_flow.py +++ b/homeassistant/components/knocki/config_flow.py @@ -10,7 +10,9 @@ import voluptuous as vol from homeassistant.config_entries import ConfigFlow, ConfigFlowResult from homeassistant.const import CONF_PASSWORD, CONF_TOKEN, CONF_USERNAME from homeassistant.exceptions import HomeAssistantError +from homeassistant.helpers import device_registry as dr from homeassistant.helpers.aiohttp_client import async_get_clientsession +from homeassistant.helpers.service_info.dhcp import DhcpServiceInfo from .const import DOMAIN, LOGGER @@ -62,3 +64,19 @@ class KnockiConfigFlow(ConfigFlow, domain=DOMAIN): errors=errors, data_schema=DATA_SCHEMA, ) + + async def async_step_dhcp( + self, discovery_info: DhcpServiceInfo + ) -> ConfigFlowResult: + """Handle a DHCP discovery.""" + device_registry = dr.async_get(self.hass) + if device_entry := device_registry.async_get_device( + identifiers={(DOMAIN, discovery_info.hostname)} + ): + device_registry.async_update_device( + device_entry.id, + new_connections={ + (dr.CONNECTION_NETWORK_MAC, discovery_info.macaddress) + }, + ) + return await super().async_step_dhcp(discovery_info) diff --git a/homeassistant/components/knocki/manifest.json b/homeassistant/components/knocki/manifest.json index a91119ca831..18f25f0ab0e 100644 --- a/homeassistant/components/knocki/manifest.json +++ b/homeassistant/components/knocki/manifest.json @@ -3,6 +3,11 @@ "name": "Knocki", "codeowners": ["@joostlek", "@jgatto1", "@JakeBosh"], "config_flow": true, + "dhcp": [ + { + "hostname": "knc*" + } + ], "documentation": "https://www.home-assistant.io/integrations/knocki", "integration_type": "hub", "iot_class": "cloud_push", diff --git a/homeassistant/components/knocki/quality_scale.yaml b/homeassistant/components/knocki/quality_scale.yaml index 45b3764d786..d1c5994b277 100644 --- a/homeassistant/components/knocki/quality_scale.yaml +++ b/homeassistant/components/knocki/quality_scale.yaml @@ -50,10 +50,8 @@ rules: # Gold devices: done diagnostics: todo - discovery-update-info: - status: exempt - comment: This is a cloud service and does not benefit from device updates. - discovery: todo + discovery-update-info: done + discovery: done docs-data-update: todo docs-examples: todo docs-known-limitations: todo diff --git a/homeassistant/generated/dhcp.py b/homeassistant/generated/dhcp.py index 53506ed1748..88fb8e06d02 100644 --- a/homeassistant/generated/dhcp.py +++ b/homeassistant/generated/dhcp.py @@ -311,6 +311,10 @@ DHCP: Final[list[dict[str, str | bool]]] = [ "hostname": "polisy*", "macaddress": "000DB9*", }, + { + "domain": "knocki", + "hostname": "knc*", + }, { "domain": "lamarzocco", "registered_devices": True, diff --git a/tests/components/knocki/__init__.py b/tests/components/knocki/__init__.py index 4ebf6b0dd01..3de1e80d9e4 100644 --- a/tests/components/knocki/__init__.py +++ b/tests/components/knocki/__init__.py @@ -10,3 +10,4 @@ async def setup_integration(hass: HomeAssistant, config_entry: MockConfigEntry) config_entry.add_to_hass(hass) await hass.config_entries.async_setup(config_entry.entry_id) + await hass.async_block_till_done() diff --git a/tests/components/knocki/test_config_flow.py b/tests/components/knocki/test_config_flow.py index 188175035da..4affbd2a197 100644 --- a/tests/components/knocki/test_config_flow.py +++ b/tests/components/knocki/test_config_flow.py @@ -6,13 +6,23 @@ from knocki import KnockiConnectionError, KnockiInvalidAuthError import pytest from homeassistant.components.knocki.const import DOMAIN -from homeassistant.config_entries import SOURCE_USER +from homeassistant.config_entries import SOURCE_DHCP, SOURCE_USER from homeassistant.const import CONF_PASSWORD, CONF_TOKEN, CONF_USERNAME from homeassistant.core import HomeAssistant from homeassistant.data_entry_flow import FlowResultType +from homeassistant.helpers import device_registry as dr +from homeassistant.helpers.service_info.dhcp import DhcpServiceInfo + +from . import setup_integration from tests.common import MockConfigEntry +DHCP_DISCOVERY = DhcpServiceInfo( + ip="1.1.1.1", + hostname="KNC1-W-00000214", + macaddress="aa:bb:cc:dd:ee:ff", +) + async def test_full_flow( hass: HomeAssistant, @@ -111,3 +121,66 @@ async def test_exceptions( }, ) assert result["type"] is FlowResultType.CREATE_ENTRY + + +async def test_dhcp( + hass: HomeAssistant, + mock_knocki_client: AsyncMock, + mock_setup_entry: AsyncMock, +) -> None: + """Test DHCP discovery.""" + result = await hass.config_entries.flow.async_init( + DOMAIN, context={"source": SOURCE_DHCP}, data=DHCP_DISCOVERY + ) + assert result["type"] is FlowResultType.FORM + assert not result["errors"] + + result = await hass.config_entries.flow.async_configure( + result["flow_id"], + { + CONF_USERNAME: "test-username", + CONF_PASSWORD: "test-password", + }, + ) + + assert result["type"] is FlowResultType.CREATE_ENTRY + assert result["result"].unique_id == "test-id" + + +async def test_dhcp_mac( + hass: HomeAssistant, + mock_knocki_client: AsyncMock, + mock_config_entry: MockConfigEntry, + device_registry: dr.DeviceRegistry, +) -> None: + """Test updating the mac address in the DHCP discovery.""" + await setup_integration(hass, mock_config_entry) + + device = device_registry.async_get_device(identifiers={(DOMAIN, "KNC1-W-00000214")}) + assert device + assert device.connections == set() + + result = await hass.config_entries.flow.async_init( + DOMAIN, context={"source": SOURCE_DHCP}, data=DHCP_DISCOVERY + ) + assert result["type"] is FlowResultType.ABORT + assert result["reason"] == "already_configured" + + device = device_registry.async_get_device(identifiers={(DOMAIN, "KNC1-W-00000214")}) + assert device + assert device.connections == {(dr.CONNECTION_NETWORK_MAC, "aa:bb:cc:dd:ee:ff")} + + +async def test_dhcp_already_setup( + hass: HomeAssistant, + mock_knocki_client: AsyncMock, + mock_config_entry: MockConfigEntry, +) -> None: + """Test DHCP discovery with already setup device.""" + mock_config_entry.add_to_hass(hass) + + result = await hass.config_entries.flow.async_init( + DOMAIN, context={"source": SOURCE_DHCP}, data=DHCP_DISCOVERY + ) + assert result["type"] is FlowResultType.ABORT + assert result["reason"] == "already_configured" From 762d284102ce6faa4f02e1e5e96baa6bd8db11fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=85ke=20Strandberg?= Date: Fri, 2 May 2025 19:31:56 +0200 Subject: [PATCH 11/90] Improve naming of miele freezers and fridges (#144062) * Use device class transation * Improve naming of miele freezers and fridges * Address review * Address review comment * Simplify --- homeassistant/components/miele/climate.py | 8 +++++-- .../miele/snapshots/test_climate.ambr | 24 +++++++++---------- tests/components/miele/test_climate.py | 2 +- 3 files changed, 19 insertions(+), 15 deletions(-) diff --git a/homeassistant/components/miele/climate.py b/homeassistant/components/miele/climate.py index 054ab227ca6..22257448e3a 100644 --- a/homeassistant/components/miele/climate.py +++ b/homeassistant/components/miele/climate.py @@ -174,6 +174,11 @@ class MieleClimate(MieleEntity, ClimateEntity): t_key = ZONE1_DEVICES.get( cast(MieleAppliance, self.device.device_type), "zone_1" ) + if self.device.device_type in ( + MieleAppliance.FRIDGE, + MieleAppliance.FREEZER, + ): + self._attr_name = None if description.zone == 2: if self.device.device_type in ( @@ -192,8 +197,7 @@ class MieleClimate(MieleEntity, ClimateEntity): @property def target_temperature(self) -> float | None: """Return the target temperature.""" - if self.entity_description.target_fn(self.device) is None: - return None + return cast(float | None, self.entity_description.target_fn(self.device)) @property diff --git a/tests/components/miele/snapshots/test_climate.ambr b/tests/components/miele/snapshots/test_climate.ambr index 15490047d36..85f7bf212f5 100644 --- a/tests/components/miele/snapshots/test_climate.ambr +++ b/tests/components/miele/snapshots/test_climate.ambr @@ -1,5 +1,5 @@ # serializer version: 1 -# name: test_climate_states[platforms0-freezer][climate.freezer_freezer-entry] +# name: test_climate_states[platforms0-freezer][climate.freezer-entry] EntityRegistryEntrySnapshot({ 'aliases': set({ }), @@ -19,7 +19,7 @@ 'disabled_by': None, 'domain': 'climate', 'entity_category': None, - 'entity_id': 'climate.freezer_freezer', + 'entity_id': 'climate.freezer', 'has_entity_name': True, 'hidden_by': None, 'icon': None, @@ -31,7 +31,7 @@ }), 'original_device_class': None, 'original_icon': None, - 'original_name': 'Freezer', + 'original_name': None, 'platform': 'miele', 'previous_unique_id': None, 'supported_features': , @@ -40,11 +40,11 @@ 'unit_of_measurement': None, }) # --- -# name: test_climate_states[platforms0-freezer][climate.freezer_freezer-state] +# name: test_climate_states[platforms0-freezer][climate.freezer-state] StateSnapshot({ 'attributes': ReadOnlyDict({ 'current_temperature': -18, - 'friendly_name': 'Freezer Freezer', + 'friendly_name': 'Freezer', 'hvac_modes': list([ , ]), @@ -55,14 +55,14 @@ 'temperature': -18, }), 'context': , - 'entity_id': 'climate.freezer_freezer', + 'entity_id': 'climate.freezer', 'last_changed': , 'last_reported': , 'last_updated': , 'state': 'cool', }) # --- -# name: test_climate_states[platforms0-freezer][climate.refrigerator_refrigerator-entry] +# name: test_climate_states[platforms0-freezer][climate.refrigerator-entry] EntityRegistryEntrySnapshot({ 'aliases': set({ }), @@ -82,7 +82,7 @@ 'disabled_by': None, 'domain': 'climate', 'entity_category': None, - 'entity_id': 'climate.refrigerator_refrigerator', + 'entity_id': 'climate.refrigerator', 'has_entity_name': True, 'hidden_by': None, 'icon': None, @@ -94,7 +94,7 @@ }), 'original_device_class': None, 'original_icon': None, - 'original_name': 'Refrigerator', + 'original_name': None, 'platform': 'miele', 'previous_unique_id': None, 'supported_features': , @@ -103,11 +103,11 @@ 'unit_of_measurement': None, }) # --- -# name: test_climate_states[platforms0-freezer][climate.refrigerator_refrigerator-state] +# name: test_climate_states[platforms0-freezer][climate.refrigerator-state] StateSnapshot({ 'attributes': ReadOnlyDict({ 'current_temperature': 4, - 'friendly_name': 'Refrigerator Refrigerator', + 'friendly_name': 'Refrigerator', 'hvac_modes': list([ , ]), @@ -118,7 +118,7 @@ 'temperature': 4, }), 'context': , - 'entity_id': 'climate.refrigerator_refrigerator', + 'entity_id': 'climate.refrigerator', 'last_changed': , 'last_reported': , 'last_updated': , diff --git a/tests/components/miele/test_climate.py b/tests/components/miele/test_climate.py index 73e530eb87c..f03edada841 100644 --- a/tests/components/miele/test_climate.py +++ b/tests/components/miele/test_climate.py @@ -26,7 +26,7 @@ pytestmark = [ ), ] -ENTITY_ID = "climate.freezer_freezer" +ENTITY_ID = "climate.freezer" SERVICE_SET_TEMPERATURE = "set_temperature" From 97be2c4ac9c7a344812ab19a06167a3d0e700e12 Mon Sep 17 00:00:00 2001 From: Ian Date: Fri, 2 May 2025 11:17:58 -0700 Subject: [PATCH 12/90] Bump py-nextbusnext to 2.1.2 (#144081)r Bump py-nextbusnext version Fixes #144059 --- homeassistant/components/nextbus/manifest.json | 2 +- requirements_all.txt | 2 +- requirements_test_all.txt | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/nextbus/manifest.json b/homeassistant/components/nextbus/manifest.json index 6300dc1cdc9..a4f6d54f58c 100644 --- a/homeassistant/components/nextbus/manifest.json +++ b/homeassistant/components/nextbus/manifest.json @@ -6,5 +6,5 @@ "documentation": "https://www.home-assistant.io/integrations/nextbus", "iot_class": "cloud_polling", "loggers": ["py_nextbus"], - "requirements": ["py-nextbusnext==2.0.5"] + "requirements": ["py-nextbusnext==2.1.2"] } diff --git a/requirements_all.txt b/requirements_all.txt index 2c4eb978684..7a9addb66a5 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -1759,7 +1759,7 @@ py-madvr2==1.6.32 py-melissa-climate==2.1.4 # homeassistant.components.nextbus -py-nextbusnext==2.0.5 +py-nextbusnext==2.1.2 # homeassistant.components.nightscout py-nightscout==1.2.2 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index ca4a2107cdb..a01ecdd406c 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -1461,7 +1461,7 @@ py-madvr2==1.6.32 py-melissa-climate==2.1.4 # homeassistant.components.nextbus -py-nextbusnext==2.0.5 +py-nextbusnext==2.1.2 # homeassistant.components.nightscout py-nightscout==1.2.2 From 2890fc7dd2d47e486e369a6ea3574bb9daadbfc4 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Fri, 2 May 2025 13:43:06 -0500 Subject: [PATCH 13/90] Only create a single resolver object if there are multiple aiohttp sessions (#144090) --- homeassistant/helpers/aiohttp_client.py | 36 ++++++++++++++++++++++--- tests/conftest.py | 4 ++- tests/helpers/test_aiohttp_client.py | 12 +++++++++ 3 files changed, 48 insertions(+), 4 deletions(-) diff --git a/homeassistant/helpers/aiohttp_client.py b/homeassistant/helpers/aiohttp_client.py index 3d8dc247857..a9976cf7e32 100644 --- a/homeassistant/helpers/aiohttp_client.py +++ b/homeassistant/helpers/aiohttp_client.py @@ -28,6 +28,7 @@ from homeassistant.util.json import json_loads from .frame import warn_use from .json import json_dumps +from .singleton import singleton if TYPE_CHECKING: from aiohttp.typedefs import JSONDecoder @@ -39,6 +40,7 @@ DATA_CONNECTOR: HassKey[dict[tuple[bool, int, str], aiohttp.BaseConnector]] = Ha DATA_CLIENTSESSION: HassKey[dict[tuple[bool, int, str], aiohttp.ClientSession]] = ( HassKey("aiohttp_clientsession") ) +DATA_RESOLVER: HassKey[HassAsyncDNSResolver] = HassKey("aiohttp_resolver") SERVER_SOFTWARE = ( f"{APPLICATION_NAME}/{__version__} " @@ -70,6 +72,21 @@ MAXIMUM_CONNECTIONS = 4096 MAXIMUM_CONNECTIONS_PER_HOST = 100 +class HassAsyncDNSResolver(AsyncDualMDNSResolver): + """Home Assistant AsyncDNSResolver. + + This is a wrapper around the AsyncDualMDNSResolver to only + close the resolver when the Home Assistant instance is closed. + """ + + async def real_close(self) -> None: + """Close the resolver.""" + await super().close() + + async def close(self) -> None: + """Close the resolver.""" + + class HassClientResponse(aiohttp.ClientResponse): """aiohttp.ClientResponse with a json method that uses json_loads by default.""" @@ -363,7 +380,7 @@ def _async_get_connector( ssl=ssl_context, limit=MAXIMUM_CONNECTIONS, limit_per_host=MAXIMUM_CONNECTIONS_PER_HOST, - resolver=_async_make_resolver(hass), + resolver=_async_get_or_create_resolver(hass), ) connectors[connector_key] = connector @@ -376,6 +393,19 @@ def _async_get_connector( return connector +@singleton(DATA_RESOLVER) @callback -def _async_make_resolver(hass: HomeAssistant) -> AsyncDualMDNSResolver: - return AsyncDualMDNSResolver(async_zeroconf=zeroconf.async_get_async_zeroconf(hass)) +def _async_get_or_create_resolver(hass: HomeAssistant) -> HassAsyncDNSResolver: + """Return the HassAsyncDNSResolver.""" + resolver = _async_make_resolver(hass) + + async def _async_close_resolver(event: Event) -> None: + await resolver.real_close() + + hass.bus.async_listen_once(EVENT_HOMEASSISTANT_CLOSE, _async_close_resolver) + return resolver + + +@callback +def _async_make_resolver(hass: HomeAssistant) -> HassAsyncDNSResolver: + return HassAsyncDNSResolver(async_zeroconf=zeroconf.async_get_async_zeroconf(hass)) diff --git a/tests/conftest.py b/tests/conftest.py index ff4a09096e0..9b861d5bde5 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1319,9 +1319,11 @@ def disable_translations_once( @pytest_asyncio.fixture(autouse=True, scope="session", loop_scope="session") async def mock_zeroconf_resolver() -> AsyncGenerator[_patch]: """Mock out the zeroconf resolver.""" + resolver = AsyncResolver() + resolver.real_close = resolver.close patcher = patch( "homeassistant.helpers.aiohttp_client._async_make_resolver", - return_value=AsyncResolver(), + return_value=resolver, ) patcher.start() try: diff --git a/tests/helpers/test_aiohttp_client.py b/tests/helpers/test_aiohttp_client.py index 6d2a7e7a8bb..e44111634d1 100644 --- a/tests/helpers/test_aiohttp_client.py +++ b/tests/helpers/test_aiohttp_client.py @@ -401,3 +401,15 @@ async def test_async_mdnsresolver( resp = await session.post("http://localhost/xyz", json={"x": 1}) assert resp.status == 200 assert await resp.json() == {"x": 1} + + +async def test_resolver_is_singleton(hass: HomeAssistant) -> None: + """Test that the resolver is a singleton.""" + session = client.async_get_clientsession(hass) + session2 = client.async_get_clientsession(hass) + session3 = client.async_create_clientsession(hass) + assert isinstance(session._connector, aiohttp.TCPConnector) + assert isinstance(session2._connector, aiohttp.TCPConnector) + assert isinstance(session3._connector, aiohttp.TCPConnector) + assert session._connector._resolver is session2._connector._resolver + assert session._connector._resolver is session3._connector._resolver From 4c2e9fc7590bb242e602b45db84582daa72d89ad Mon Sep 17 00:00:00 2001 From: Brett Adams Date: Sat, 3 May 2025 05:13:12 +1000 Subject: [PATCH 14/90] Bump teslemetry-stream to 0.7.7 (#144085) --- homeassistant/components/teslemetry/manifest.json | 2 +- requirements_all.txt | 2 +- requirements_test_all.txt | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/teslemetry/manifest.json b/homeassistant/components/teslemetry/manifest.json index 8194fb3d6db..5b7454b87b6 100644 --- a/homeassistant/components/teslemetry/manifest.json +++ b/homeassistant/components/teslemetry/manifest.json @@ -6,5 +6,5 @@ "documentation": "https://www.home-assistant.io/integrations/teslemetry", "iot_class": "cloud_polling", "loggers": ["tesla-fleet-api"], - "requirements": ["tesla-fleet-api==1.0.17", "teslemetry-stream==0.7.5"] + "requirements": ["tesla-fleet-api==1.0.17", "teslemetry-stream==0.7.7"] } diff --git a/requirements_all.txt b/requirements_all.txt index 7a9addb66a5..2beb7ab9632 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -2897,7 +2897,7 @@ tesla-powerwall==0.5.2 tesla-wall-connector==1.0.2 # homeassistant.components.teslemetry -teslemetry-stream==0.7.5 +teslemetry-stream==0.7.7 # homeassistant.components.tessie tessie-api==0.1.1 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index a01ecdd406c..c6b808f4818 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -2341,7 +2341,7 @@ tesla-powerwall==0.5.2 tesla-wall-connector==1.0.2 # homeassistant.components.teslemetry -teslemetry-stream==0.7.5 +teslemetry-stream==0.7.7 # homeassistant.components.tessie tessie-api==0.1.1 From df4297be62408714d49c6d36bd04b015cdf4fc88 Mon Sep 17 00:00:00 2001 From: Josef Zweck Date: Fri, 2 May 2025 22:29:54 +0200 Subject: [PATCH 15/90] Fix intermittent unavailability for lamarzocco brew active sensor (#144120) * Fix brew active intermittent unavailability for lamarzocco * Whitespaces --- .../components/lamarzocco/binary_sensor.py | 2 +- .../components/lamarzocco/coordinator.py | 26 ++++++++++++++----- homeassistant/components/lamarzocco/entity.py | 5 ++-- homeassistant/components/lamarzocco/number.py | 14 +++++----- .../lamarzocco/test_binary_sensor.py | 11 ++++++++ 5 files changed, 41 insertions(+), 17 deletions(-) diff --git a/homeassistant/components/lamarzocco/binary_sensor.py b/homeassistant/components/lamarzocco/binary_sensor.py index 98cf7cf222e..9bf04129095 100644 --- a/homeassistant/components/lamarzocco/binary_sensor.py +++ b/homeassistant/components/lamarzocco/binary_sensor.py @@ -52,7 +52,7 @@ ENTITIES: tuple[LaMarzoccoBinarySensorEntityDescription, ...] = ( ).status is MachineState.BREWING ), - available_fn=lambda device: device.websocket.connected, + available_fn=lambda coordinator: not coordinator.websocket_terminated, entity_category=EntityCategory.DIAGNOSTIC, ), LaMarzoccoBinarySensorEntityDescription( diff --git a/homeassistant/components/lamarzocco/coordinator.py b/homeassistant/components/lamarzocco/coordinator.py index 751ef550516..f0f64e02c28 100644 --- a/homeassistant/components/lamarzocco/coordinator.py +++ b/homeassistant/components/lamarzocco/coordinator.py @@ -44,6 +44,7 @@ class LaMarzoccoUpdateCoordinator(DataUpdateCoordinator[None]): _default_update_interval = SCAN_INTERVAL config_entry: LaMarzoccoConfigEntry + websocket_terminated = True def __init__( self, @@ -92,15 +93,9 @@ class LaMarzoccoConfigUpdateCoordinator(LaMarzoccoUpdateCoordinator): await self.device.get_dashboard() _LOGGER.debug("Current status: %s", self.device.dashboard.to_dict()) - _LOGGER.debug("Init WebSocket in background task") - self.config_entry.async_create_background_task( hass=self.hass, - target=self.device.connect_dashboard_websocket( - update_callback=lambda _: self.async_set_updated_data(None), - connect_callback=self.async_update_listeners, - disconnect_callback=self.async_update_listeners, - ), + target=self.connect_websocket(), name="lm_websocket_task", ) @@ -112,6 +107,23 @@ class LaMarzoccoConfigUpdateCoordinator(LaMarzoccoUpdateCoordinator): ) self.config_entry.async_on_unload(websocket_close) + async def connect_websocket(self) -> None: + """Connect to the websocket.""" + + _LOGGER.debug("Init WebSocket in background task") + + self.websocket_terminated = False + self.async_update_listeners() + + await self.device.connect_dashboard_websocket( + update_callback=lambda _: self.async_set_updated_data(None), + connect_callback=self.async_update_listeners, + disconnect_callback=self.async_update_listeners, + ) + + self.websocket_terminated = True + self.async_update_listeners() + class LaMarzoccoSettingsUpdateCoordinator(LaMarzoccoUpdateCoordinator): """Coordinator for La Marzocco settings.""" diff --git a/homeassistant/components/lamarzocco/entity.py b/homeassistant/components/lamarzocco/entity.py index 2e3a7f2ce83..6dc024645ce 100644 --- a/homeassistant/components/lamarzocco/entity.py +++ b/homeassistant/components/lamarzocco/entity.py @@ -3,7 +3,6 @@ from collections.abc import Callable from dataclasses import dataclass -from pylamarzocco import LaMarzoccoMachine from pylamarzocco.const import FirmwareType from homeassistant.const import CONF_ADDRESS, CONF_MAC @@ -23,7 +22,7 @@ from .coordinator import LaMarzoccoUpdateCoordinator class LaMarzoccoEntityDescription(EntityDescription): """Description for all LM entities.""" - available_fn: Callable[[LaMarzoccoMachine], bool] = lambda _: True + available_fn: Callable[[LaMarzoccoUpdateCoordinator], bool] = lambda _: True supported_fn: Callable[[LaMarzoccoUpdateCoordinator], bool] = lambda _: True @@ -74,7 +73,7 @@ class LaMarzoccoEntity(LaMarzoccoBaseEntity): def available(self) -> bool: """Return True if entity is available.""" if super().available: - return self.entity_description.available_fn(self.coordinator.device) + return self.entity_description.available_fn(self.coordinator) return False def __init__( diff --git a/homeassistant/components/lamarzocco/number.py b/homeassistant/components/lamarzocco/number.py index 81a03b4d6ee..7c4fe33a041 100644 --- a/homeassistant/components/lamarzocco/number.py +++ b/homeassistant/components/lamarzocco/number.py @@ -100,8 +100,9 @@ ENTITIES: tuple[LaMarzoccoNumberEntityDescription, ...] = ( .seconds.seconds_out ), available_fn=( - lambda machine: cast( - PreBrewing, machine.dashboard.config[WidgetType.CM_PRE_BREWING] + lambda coordinator: cast( + PreBrewing, + coordinator.device.dashboard.config[WidgetType.CM_PRE_BREWING], ).mode is PreExtractionMode.PREINFUSION ), @@ -140,8 +141,8 @@ ENTITIES: tuple[LaMarzoccoNumberEntityDescription, ...] = ( .times.pre_brewing[0] .seconds.seconds_in ), - available_fn=lambda machine: cast( - PreBrewing, machine.dashboard.config[WidgetType.CM_PRE_BREWING] + available_fn=lambda coordinator: cast( + PreBrewing, coordinator.device.dashboard.config[WidgetType.CM_PRE_BREWING] ).mode is PreExtractionMode.PREBREWING, supported_fn=( @@ -180,8 +181,9 @@ ENTITIES: tuple[LaMarzoccoNumberEntityDescription, ...] = ( .seconds.seconds_out ), available_fn=( - lambda machine: cast( - PreBrewing, machine.dashboard.config[WidgetType.CM_PRE_BREWING] + lambda coordinator: cast( + PreBrewing, + coordinator.device.dashboard.config[WidgetType.CM_PRE_BREWING], ).mode is PreExtractionMode.PREBREWING ), diff --git a/tests/components/lamarzocco/test_binary_sensor.py b/tests/components/lamarzocco/test_binary_sensor.py index 8e92c9bbba9..570b5aef8ec 100644 --- a/tests/components/lamarzocco/test_binary_sensor.py +++ b/tests/components/lamarzocco/test_binary_sensor.py @@ -1,5 +1,6 @@ """Tests for La Marzocco binary sensors.""" +from collections.abc import Generator from datetime import timedelta from unittest.mock import MagicMock, patch @@ -33,6 +34,16 @@ async def test_binary_sensors( await snapshot_platform(hass, entity_registry, snapshot, mock_config_entry.entry_id) +@pytest.fixture(autouse=True) +def mock_websocket_terminated() -> Generator[bool]: + """Mock websocket terminated.""" + with patch( + "homeassistant.components.lamarzocco.coordinator.LaMarzoccoUpdateCoordinator.websocket_terminated", + new=False, + ) as mock_websocket_terminated: + yield mock_websocket_terminated + + async def test_brew_active_unavailable( hass: HomeAssistant, mock_lamarzocco: MagicMock, From 32b7edb6085cab955c3893293906d7da7efa40fc Mon Sep 17 00:00:00 2001 From: Bram Kragten Date: Fri, 2 May 2025 23:33:39 +0300 Subject: [PATCH 16/90] Update frontend to 20250502.0 (#144114) --- homeassistant/components/frontend/manifest.json | 2 +- homeassistant/package_constraints.txt | 2 +- requirements_all.txt | 2 +- requirements_test_all.txt | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/homeassistant/components/frontend/manifest.json b/homeassistant/components/frontend/manifest.json index 28b01aff616..2cfa9572ff3 100644 --- a/homeassistant/components/frontend/manifest.json +++ b/homeassistant/components/frontend/manifest.json @@ -20,5 +20,5 @@ "documentation": "https://www.home-assistant.io/integrations/frontend", "integration_type": "system", "quality_scale": "internal", - "requirements": ["home-assistant-frontend==20250430.2"] + "requirements": ["home-assistant-frontend==20250502.0"] } diff --git a/homeassistant/package_constraints.txt b/homeassistant/package_constraints.txt index c484a526374..6bcd21f4d99 100644 --- a/homeassistant/package_constraints.txt +++ b/homeassistant/package_constraints.txt @@ -38,7 +38,7 @@ habluetooth==3.45.0 hass-nabucasa==0.96.0 hassil==2.2.3 home-assistant-bluetooth==1.13.1 -home-assistant-frontend==20250430.2 +home-assistant-frontend==20250502.0 home-assistant-intents==2025.4.30 httpx==0.28.1 ifaddr==0.2.0 diff --git a/requirements_all.txt b/requirements_all.txt index 2beb7ab9632..8f452b7d29f 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -1161,7 +1161,7 @@ hole==0.8.0 holidays==0.70 # homeassistant.components.frontend -home-assistant-frontend==20250430.2 +home-assistant-frontend==20250502.0 # homeassistant.components.conversation home-assistant-intents==2025.4.30 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index c6b808f4818..8b317d0369e 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -991,7 +991,7 @@ hole==0.8.0 holidays==0.70 # homeassistant.components.frontend -home-assistant-frontend==20250430.2 +home-assistant-frontend==20250502.0 # homeassistant.components.conversation home-assistant-intents==2025.4.30 From 247d2e7efdb5dd95737031f7571203c9cc834e51 Mon Sep 17 00:00:00 2001 From: Thomas55555 <59625598+Thomas55555@users.noreply.github.com> Date: Fri, 2 May 2025 22:35:34 +0200 Subject: [PATCH 17/90] Bump aioautomower to 2025.5.1 (#144118) --- homeassistant/components/husqvarna_automower/manifest.json | 2 +- requirements_all.txt | 2 +- requirements_test_all.txt | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/husqvarna_automower/manifest.json b/homeassistant/components/husqvarna_automower/manifest.json index 8e4be4c71f3..705975bb966 100644 --- a/homeassistant/components/husqvarna_automower/manifest.json +++ b/homeassistant/components/husqvarna_automower/manifest.json @@ -8,5 +8,5 @@ "iot_class": "cloud_push", "loggers": ["aioautomower"], "quality_scale": "silver", - "requirements": ["aioautomower==2025.4.4"] + "requirements": ["aioautomower==2025.5.1"] } diff --git a/requirements_all.txt b/requirements_all.txt index 8f452b7d29f..6b6da010f8a 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -201,7 +201,7 @@ aioaseko==1.0.0 aioasuswrt==1.4.0 # homeassistant.components.husqvarna_automower -aioautomower==2025.4.4 +aioautomower==2025.5.1 # homeassistant.components.azure_devops aioazuredevops==2.2.1 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index 8b317d0369e..77df15a6272 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -189,7 +189,7 @@ aioaseko==1.0.0 aioasuswrt==1.4.0 # homeassistant.components.husqvarna_automower -aioautomower==2025.4.4 +aioautomower==2025.5.1 # homeassistant.components.azure_devops aioazuredevops==2.2.1 From e74f9183825d896339c338cc545727ed1985f231 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Fri, 2 May 2025 15:53:19 -0500 Subject: [PATCH 18/90] Bump aiodns to 3.3.0 (#144115) --- homeassistant/components/dnsip/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/dnsip/test_config_flow.py | 24 ++++++++++++-------- 7 files changed, 20 insertions(+), 16 deletions(-) diff --git a/homeassistant/components/dnsip/manifest.json b/homeassistant/components/dnsip/manifest.json index d25459b95b7..35802adb7f3 100644 --- a/homeassistant/components/dnsip/manifest.json +++ b/homeassistant/components/dnsip/manifest.json @@ -5,5 +5,5 @@ "config_flow": true, "documentation": "https://www.home-assistant.io/integrations/dnsip", "iot_class": "cloud_polling", - "requirements": ["aiodns==3.2.0"] + "requirements": ["aiodns==3.3.0"] } diff --git a/homeassistant/package_constraints.txt b/homeassistant/package_constraints.txt index 6bcd21f4d99..de493201acd 100644 --- a/homeassistant/package_constraints.txt +++ b/homeassistant/package_constraints.txt @@ -2,7 +2,7 @@ aiodhcpwatcher==1.1.1 aiodiscover==2.6.1 -aiodns==3.2.0 +aiodns==3.3.0 aiohasupervisor==0.3.1 aiohttp-asyncmdnsresolver==0.1.1 aiohttp-fast-zlib==0.2.3 diff --git a/pyproject.toml b/pyproject.toml index fcfe8e3448d..c71cf0dbaf2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -23,7 +23,7 @@ classifiers = [ ] requires-python = ">=3.13.2" dependencies = [ - "aiodns==3.2.0", + "aiodns==3.3.0", # Integrations may depend on hassio integration without listing it to # change behavior based on presence of supervisor. Deprecated with #127228 # Lib can be removed with 2025.11 diff --git a/requirements.txt b/requirements.txt index 1e91dca8391..5bbf33025c3 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,7 +3,7 @@ -c homeassistant/package_constraints.txt # Home Assistant Core -aiodns==3.2.0 +aiodns==3.3.0 aiohasupervisor==0.3.1 aiohttp==3.11.18 aiohttp_cors==0.7.0 diff --git a/requirements_all.txt b/requirements_all.txt index 6b6da010f8a..3b93f9f40d7 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -223,7 +223,7 @@ aiodhcpwatcher==1.1.1 aiodiscover==2.6.1 # homeassistant.components.dnsip -aiodns==3.2.0 +aiodns==3.3.0 # homeassistant.components.duke_energy aiodukeenergy==0.3.0 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index 77df15a6272..40997e5e24b 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -211,7 +211,7 @@ aiodhcpwatcher==1.1.1 aiodiscover==2.6.1 # homeassistant.components.dnsip -aiodns==3.2.0 +aiodns==3.3.0 # homeassistant.components.duke_energy aiodukeenergy==0.3.0 diff --git a/tests/components/dnsip/test_config_flow.py b/tests/components/dnsip/test_config_flow.py index 9d92cb3554c..1a565345275 100644 --- a/tests/components/dnsip/test_config_flow.py +++ b/tests/components/dnsip/test_config_flow.py @@ -224,16 +224,20 @@ async def test_options_flow(hass: HomeAssistant) -> None: assert result["type"] is FlowResultType.FORM assert result["step_id"] == "init" - result = await hass.config_entries.options.async_configure( - result["flow_id"], - user_input={ - CONF_RESOLVER: "8.8.8.8", - CONF_RESOLVER_IPV6: "2001:4860:4860::8888", - CONF_PORT: 53, - CONF_PORT_IPV6: 53, - }, - ) - await hass.async_block_till_done() + with patch( + "homeassistant.components.dnsip.config_flow.aiodns.DNSResolver", + return_value=RetrieveDNS(), + ): + result = await hass.config_entries.options.async_configure( + result["flow_id"], + user_input={ + CONF_RESOLVER: "8.8.8.8", + CONF_RESOLVER_IPV6: "2001:4860:4860::8888", + CONF_PORT: 53, + CONF_PORT_IPV6: 53, + }, + ) + await hass.async_block_till_done() assert result["type"] is FlowResultType.CREATE_ENTRY assert result["data"] == { From 3183bb78ff8aad19c147e73c43a5813aa3305abb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20H=C3=B6rsken?= Date: Sat, 3 May 2025 00:16:49 +0200 Subject: [PATCH 19/90] Update pywmspro to 0.2.2 to make error handling more robust (#144124) --- homeassistant/components/wmspro/manifest.json | 2 +- requirements_all.txt | 2 +- requirements_test_all.txt | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/wmspro/manifest.json b/homeassistant/components/wmspro/manifest.json index dd65be3e7e7..d4eda3a90a6 100644 --- a/homeassistant/components/wmspro/manifest.json +++ b/homeassistant/components/wmspro/manifest.json @@ -14,5 +14,5 @@ "documentation": "https://www.home-assistant.io/integrations/wmspro", "integration_type": "hub", "iot_class": "local_polling", - "requirements": ["pywmspro==0.2.1"] + "requirements": ["pywmspro==0.2.2"] } diff --git a/requirements_all.txt b/requirements_all.txt index 3b93f9f40d7..8c223ab9bc2 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -2577,7 +2577,7 @@ pywilight==0.0.74 pywizlight==0.6.2 # homeassistant.components.wmspro -pywmspro==0.2.1 +pywmspro==0.2.2 # homeassistant.components.ws66i pyws66i==1.1 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index 40997e5e24b..3bf20a45ada 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -2099,7 +2099,7 @@ pywilight==0.0.74 pywizlight==0.6.2 # homeassistant.components.wmspro -pywmspro==0.2.1 +pywmspro==0.2.2 # homeassistant.components.ws66i pyws66i==1.1 From 4450f919c3f2ad7c69a71ca153fd92f74c581d95 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Fri, 2 May 2025 17:46:59 -0500 Subject: [PATCH 20/90] Bump PyISY to 3.4.1 (#144127) --- homeassistant/components/isy994/helpers.py | 3 +-- homeassistant/components/isy994/manifest.json | 2 +- requirements_all.txt | 2 +- requirements_test_all.txt | 2 +- 4 files changed, 4 insertions(+), 5 deletions(-) diff --git a/homeassistant/components/isy994/helpers.py b/homeassistant/components/isy994/helpers.py index 3686a182fe9..587c0544d6c 100644 --- a/homeassistant/components/isy994/helpers.py +++ b/homeassistant/components/isy994/helpers.py @@ -401,8 +401,7 @@ def _categorize_programs(isy_data: IsyData, programs: Programs) -> None: for dtype, _, node_id in folder.children: if dtype != TAG_FOLDER: continue - entity_folder = folder[node_id] - + entity_folder: Programs = folder[node_id] actions = None status = entity_folder.get_by_name(KEY_STATUS) if not status or status.protocol != PROTO_PROGRAM: diff --git a/homeassistant/components/isy994/manifest.json b/homeassistant/components/isy994/manifest.json index 5cd3bb73a89..bbfc7deb80d 100644 --- a/homeassistant/components/isy994/manifest.json +++ b/homeassistant/components/isy994/manifest.json @@ -24,7 +24,7 @@ "integration_type": "hub", "iot_class": "local_push", "loggers": ["pyisy"], - "requirements": ["pyisy==3.4.0"], + "requirements": ["pyisy==3.4.1"], "ssdp": [ { "manufacturer": "Universal Devices Inc.", diff --git a/requirements_all.txt b/requirements_all.txt index 8c223ab9bc2..40509329dd2 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -2054,7 +2054,7 @@ pyiskra==0.1.15 pyiss==1.0.1 # homeassistant.components.isy994 -pyisy==3.4.0 +pyisy==3.4.1 # homeassistant.components.itach pyitachip2ir==0.0.7 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index 3bf20a45ada..4c561092925 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -1678,7 +1678,7 @@ pyiskra==0.1.15 pyiss==1.0.1 # homeassistant.components.isy994 -pyisy==3.4.0 +pyisy==3.4.1 # homeassistant.components.ituran pyituran==0.1.4 From 5e39fb6da1c2353935f5172f1470e8bf5279cfca Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sat, 3 May 2025 03:08:56 -0500 Subject: [PATCH 21/90] Bump bleak-esphome to 2.15.1 (#144129) --- homeassistant/components/eq3btsmart/manifest.json | 2 +- homeassistant/components/esphome/manifest.json | 2 +- requirements_all.txt | 2 +- requirements_test_all.txt | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/homeassistant/components/eq3btsmart/manifest.json b/homeassistant/components/eq3btsmart/manifest.json index b07e78316d8..1f619b2017c 100644 --- a/homeassistant/components/eq3btsmart/manifest.json +++ b/homeassistant/components/eq3btsmart/manifest.json @@ -22,5 +22,5 @@ "integration_type": "device", "iot_class": "local_polling", "loggers": ["eq3btsmart"], - "requirements": ["eq3btsmart==1.4.1", "bleak-esphome==2.14.0"] + "requirements": ["eq3btsmart==1.4.1", "bleak-esphome==2.15.1"] } diff --git a/homeassistant/components/esphome/manifest.json b/homeassistant/components/esphome/manifest.json index e2e3cb34721..beaf68decd9 100644 --- a/homeassistant/components/esphome/manifest.json +++ b/homeassistant/components/esphome/manifest.json @@ -19,7 +19,7 @@ "requirements": [ "aioesphomeapi==30.1.0", "esphome-dashboard-api==1.3.0", - "bleak-esphome==2.14.0" + "bleak-esphome==2.15.1" ], "zeroconf": ["_esphomelib._tcp.local."] } diff --git a/requirements_all.txt b/requirements_all.txt index 40509329dd2..d9a8d90ade0 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -607,7 +607,7 @@ bizkaibus==0.1.1 # homeassistant.components.eq3btsmart # homeassistant.components.esphome -bleak-esphome==2.14.0 +bleak-esphome==2.15.1 # homeassistant.components.bluetooth bleak-retry-connector==3.9.0 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index 4c561092925..4ea60a459d1 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -538,7 +538,7 @@ bimmer-connected[china]==0.17.2 # homeassistant.components.eq3btsmart # homeassistant.components.esphome -bleak-esphome==2.14.0 +bleak-esphome==2.15.1 # homeassistant.components.bluetooth bleak-retry-connector==3.9.0 From 9780db1c2212776db98d6c2c877c7504134a5385 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sat, 3 May 2025 03:09:28 -0500 Subject: [PATCH 22/90] Bump Bluetooth deps to improve auto recovery process (#144133) --- .../components/bluetooth/manifest.json | 4 +- homeassistant/package_constraints.txt | 4 +- requirements_all.txt | 4 +- requirements_test_all.txt | 4 +- tests/components/bluetooth/test_wrappers.py | 59 ------------------- 5 files changed, 8 insertions(+), 67 deletions(-) diff --git a/homeassistant/components/bluetooth/manifest.json b/homeassistant/components/bluetooth/manifest.json index 1ffee18d8fb..5e74f7b5561 100644 --- a/homeassistant/components/bluetooth/manifest.json +++ b/homeassistant/components/bluetooth/manifest.json @@ -18,9 +18,9 @@ "bleak==0.22.3", "bleak-retry-connector==3.9.0", "bluetooth-adapters==0.21.4", - "bluetooth-auto-recovery==1.4.5", + "bluetooth-auto-recovery==1.5.1", "bluetooth-data-tools==1.28.1", "dbus-fast==2.43.0", - "habluetooth==3.45.0" + "habluetooth==3.47.1" ] } diff --git a/homeassistant/package_constraints.txt b/homeassistant/package_constraints.txt index de493201acd..8b53ae13687 100644 --- a/homeassistant/package_constraints.txt +++ b/homeassistant/package_constraints.txt @@ -23,7 +23,7 @@ bcrypt==4.2.0 bleak-retry-connector==3.9.0 bleak==0.22.3 bluetooth-adapters==0.21.4 -bluetooth-auto-recovery==1.4.5 +bluetooth-auto-recovery==1.5.1 bluetooth-data-tools==1.28.1 cached-ipaddress==0.10.0 certifi>=2021.5.30 @@ -34,7 +34,7 @@ dbus-fast==2.43.0 fnv-hash-fast==1.5.0 go2rtc-client==0.1.2 ha-ffmpeg==3.2.2 -habluetooth==3.45.0 +habluetooth==3.47.1 hass-nabucasa==0.96.0 hassil==2.2.3 home-assistant-bluetooth==1.13.1 diff --git a/requirements_all.txt b/requirements_all.txt index d9a8d90ade0..d52a573d7bd 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -637,7 +637,7 @@ bluemaestro-ble==0.4.0 bluetooth-adapters==0.21.4 # homeassistant.components.bluetooth -bluetooth-auto-recovery==1.4.5 +bluetooth-auto-recovery==1.5.1 # homeassistant.components.bluetooth # homeassistant.components.ld2410_ble @@ -1118,7 +1118,7 @@ ha-silabs-firmware-client==0.2.0 habiticalib==0.3.7 # homeassistant.components.bluetooth -habluetooth==3.45.0 +habluetooth==3.47.1 # homeassistant.components.cloud hass-nabucasa==0.96.0 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index 4ea60a459d1..20e4f5af2d1 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -562,7 +562,7 @@ bluemaestro-ble==0.4.0 bluetooth-adapters==0.21.4 # homeassistant.components.bluetooth -bluetooth-auto-recovery==1.4.5 +bluetooth-auto-recovery==1.5.1 # homeassistant.components.bluetooth # homeassistant.components.ld2410_ble @@ -960,7 +960,7 @@ ha-silabs-firmware-client==0.2.0 habiticalib==0.3.7 # homeassistant.components.bluetooth -habluetooth==3.45.0 +habluetooth==3.47.1 # homeassistant.components.cloud hass-nabucasa==0.96.0 diff --git a/tests/components/bluetooth/test_wrappers.py b/tests/components/bluetooth/test_wrappers.py index c5908776882..bfe7445f614 100644 --- a/tests/components/bluetooth/test_wrappers.py +++ b/tests/components/bluetooth/test_wrappers.py @@ -316,65 +316,6 @@ async def test_release_slot_on_connect_exception( cancel_hci1() -@pytest.mark.usefixtures("enable_bluetooth", "two_adapters") -async def test_we_switch_adapters_on_failure( - hass: HomeAssistant, - install_bleak_catcher, -) -> None: - """Ensure we try the next best adapter after a failure.""" - hci0_device_advs, cancel_hci0, cancel_hci1 = _generate_scanners_with_fake_devices( - hass - ) - ble_device = hci0_device_advs["00:00:00:00:00:01"][0] - client = bleak.BleakClient(ble_device) - - class FakeBleakClientFailsHCI0Only(BaseFakeBleakClient): - """Fake bleak client that fails to connect.""" - - async def connect(self, *args, **kwargs): - """Connect.""" - if "/hci0/" in self._device.details["path"]: - return False - return True - - with patch( - "habluetooth.wrappers.get_platform_client_backend_type", - return_value=FakeBleakClientFailsHCI0Only, - ): - assert await client.connect() is False - - with patch( - "habluetooth.wrappers.get_platform_client_backend_type", - return_value=FakeBleakClientFailsHCI0Only, - ): - assert await client.connect() is False - - # After two tries we should switch to hci1 - with patch( - "habluetooth.wrappers.get_platform_client_backend_type", - return_value=FakeBleakClientFailsHCI0Only, - ): - assert await client.connect() is True - - # ..and we remember that hci1 works as long as the client doesn't change - with patch( - "habluetooth.wrappers.get_platform_client_backend_type", - return_value=FakeBleakClientFailsHCI0Only, - ): - assert await client.connect() is True - - # If we replace the client, we should try hci0 again - client = bleak.BleakClient(ble_device) - - with patch( - "habluetooth.wrappers.get_platform_client_backend_type", - return_value=FakeBleakClientFailsHCI0Only, - ): - assert await client.connect() is False - cancel_hci0() - cancel_hci1() - - @pytest.mark.usefixtures("enable_bluetooth", "two_adapters") async def test_passing_subclassed_str_as_address( hass: HomeAssistant, From 558b0ec3b1d6278cc30f7f47ca2d57d7ed9626f4 Mon Sep 17 00:00:00 2001 From: Jan Bouwhuis Date: Sat, 3 May 2025 11:51:26 +0200 Subject: [PATCH 23/90] Fix small issues with mqtt translations and improve readability (#144091) --- homeassistant/components/mqtt/strings.json | 30 +++++++++++----------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/homeassistant/components/mqtt/strings.json b/homeassistant/components/mqtt/strings.json index d2234121803..7339f3869a1 100644 --- a/homeassistant/components/mqtt/strings.json +++ b/homeassistant/components/mqtt/strings.json @@ -256,8 +256,8 @@ "green_template": "Green template", "last_reset_value_template": "Last reset value template", "optimistic": "Optimistic", - "payload_off": "Payload off", - "payload_on": "Payload on", + "payload_off": "Payload \"off\"", + "payload_on": "Payload \"on\"", "qos": "QoS", "red_template": "Red template", "retain": "Retain", @@ -278,7 +278,7 @@ "green_template": "[Template](https://www.home-assistant.io/docs/configuration/templating/#using-value-templates-with-mqtt) to extract green color from the state payload value. Expected result of the template is an integer from 0-255 range.", "last_reset_value_template": "Defines a [template](https://www.home-assistant.io/docs/configuration/templating/#using-value-templates-with-mqtt) to extract the last reset. When Last reset template is set, the State class option must be Total. [Learn more.]({url}#last_reset_value_template)", "force_update": "Sends update events even if the value hasn’t changed. Useful if you want to have meaningful value graphs in history. [Learn more.]({url}#force_update)", - "on_command_type": "Defines when the `payload on` is sent. Using `last` (the default) will send any style (brightness, color, etc) topics first and then a `payload on` to the command_topic. Using `first` will send the `payload on` and then any style topics. Using `brightness` will only send brightness commands instead of the `Payload on` to turn the light on.", + "on_command_type": "Defines when the payload \"on\" is sent. Using \"Last\" (the default) will send any style (brightness, color, etc) topics first and then a payload \"on\" to the command topic. Using \"First\" will send the payload \"on\" and then any style topics. Using \"Brightness\" will only send brightness commands instead of the payload \"on\" to turn the light on.", "optimistic": "Flag that defines if the {platform} entity works in optimistic mode. [Learn more.]({url}#optimistic)", "payload_off": "The payload that represents the off state.", "payload_on": "The payload that represents the on state.", @@ -287,7 +287,7 @@ "retain": "Select if values published by the {platform} entity should be retained at the MQTT broker.", "state_template": "[Template](https://www.home-assistant.io/docs/configuration/templating/#using-value-templates-with-mqtt) to extract state from the state payload value.", "state_topic": "The MQTT topic subscribed to receive {platform} state values. [Learn more.]({url}#state_topic)", - "supported_color_modes": "A list of color modes supported by the list. Possible color modes are On/Off, Brightness, Color temperature, HS, XY, RGB, RGBW, RGBWW, WHITE. Note that if onoff or brightness are used, that must be the only value in the list. [Learn more.]({url}#supported_color_modes)", + "supported_color_modes": "A list of color modes supported by the list. Possible color modes are On/Off, Brightness, Color temperature, HS, XY, RGB, RGBW, RGBWW, White. Note that if On/Off or Brightness are used, that must be the only value in the list. [Learn more.]({url}#supported_color_modes)", "value_template": "Defines a [template](https://www.home-assistant.io/docs/configuration/templating/#using-value-templates-with-mqtt) to extract the {platform} entity value. [Learn more.]({url}#value_template)" }, "sections": { @@ -325,7 +325,7 @@ "data_description": { "brightness": "Flag that defines if light supports brightness when the RGB, RGBW, or RGBWW color mode is supported.", "brightness_command_template": "A [template](https://www.home-assistant.io/docs/configuration/templating/#using-command-templates-with-mqtt) to compose the payload to be published at the brightness command topic.", - "brightness_command_topic": "The publishing topic that will be used to control the brigthness. [Learn more.]({url}#brightness_command_topic)", + "brightness_command_topic": "The publishing topic that will be used to control the brightness. [Learn more.]({url}#brightness_command_topic)", "brightness_scale": "Defines the maximum brightness value (i.e., 100%) of the maximum brightness.", "brightness_state_topic": "The MQTT topic subscribed to receive brightness state values. [Learn more.]({url}#brightness_state_topic)", "brightness_value_template": "Defines a [template](https://www.home-assistant.io/docs/configuration/templating/#using-value-templates-with-mqtt) to extract the brightness value." @@ -385,7 +385,7 @@ "hs_value_template": "HS value template" }, "data_description": { - "hs_command_template": "Defines a [template](https://www.home-assistant.io/docs/configuration/templating/#using-command-templates-with-mqtt) to compose message which will be sent to hs_command_topic. Available variables: `hue` and `sat`.", + "hs_command_template": "Defines a [template](https://www.home-assistant.io/docs/configuration/templating/#using-command-templates-with-mqtt) to compose message which will be sent to HS command topic. Available variables: `hue` and `sat`.", "hs_command_topic": "The MQTT topic to publish commands to change the light’s color state in HS format (Hue Saturation). Range for Hue: 0° .. 360°, Range of Saturation: 0..100. Note: Brightness is sent separately in the brightness command topic. [Learn more.]({url}#hs_command_topic)", "hs_state_topic": "The MQTT topic subscribed to receive color state updates in HS format. The expected payload is the hue and saturation values separated by commas, for example, `359.5,100.0`. Note: Brightness is received separately in the brightness state topic. [Learn more.]({url}#hs_state_topic)", "hs_value_template": "Defines a [template](https://www.home-assistant.io/docs/configuration/templating/#using-value-templates-with-mqtt) to extract the HS value." @@ -574,15 +574,15 @@ "discovery": "Option to enable MQTT automatic discovery.", "discovery_prefix": "The prefix of configuration topics the MQTT integration will subscribe to.", "birth_enable": "When set, Home Assistant will publish an online message to your MQTT broker when MQTT is ready.", - "birth_topic": "The MQTT topic where Home Assistant will publish a `birth` message.", - "birth_payload": "The `birth` message that is published when MQTT is ready and connected.", - "birth_qos": "The quality of service of the `birth` message that is published when MQTT is ready and connected", - "birth_retain": "When set, Home Assistant will retain the `birth` message published to your MQTT broker.", - "will_enable": "When set, Home Assistant will ask your broker to publish a `will` message when MQTT is stopped or when it loses the connection to your broker.", - "will_topic": "The MQTT topic your MQTT broker will publish a `will` message to.", - "will_payload": "The message your MQTT broker `will` publish when the MQTT integration is stopped or when the connection is lost.", - "will_qos": "The quality of service of the `will` message that is published by your MQTT broker.", - "will_retain": "When set, your MQTT broker will retain the `will` message." + "birth_topic": "The MQTT topic where Home Assistant will publish a \"birth\" message.", + "birth_payload": "The \"birth\" message that is published when MQTT is ready and connected.", + "birth_qos": "The quality of service of the \"birth\" message that is published when MQTT is ready and connected", + "birth_retain": "When set, Home Assistant will retain the \"birth\" message published to your MQTT broker.", + "will_enable": "When set, Home Assistant will ask your broker to publish a \"will\" message when MQTT is stopped or when it loses the connection to your broker.", + "will_topic": "The MQTT topic your MQTT broker will publish a \"will\" message to.", + "will_payload": "The message your MQTT broker \"will\" publish when the MQTT integration is stopped or when the connection is lost.", + "will_qos": "The quality of service of the \"will\" message that is published by your MQTT broker.", + "will_retain": "When set, your MQTT broker will retain the \"will\" message." } } }, From 1d500fda67dd251196340600b9474df817f69ab4 Mon Sep 17 00:00:00 2001 From: Marc Mueller <30130371+cdce8p@users.noreply.github.com> Date: Sat, 3 May 2025 14:35:04 +0200 Subject: [PATCH 24/90] Fix fritz coordinator typing (#144146) --- homeassistant/components/fritz/coordinator.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/homeassistant/components/fritz/coordinator.py b/homeassistant/components/fritz/coordinator.py index 9199692f564..d253e9b5b12 100644 --- a/homeassistant/components/fritz/coordinator.py +++ b/homeassistant/components/fritz/coordinator.py @@ -521,7 +521,7 @@ class FritzBoxTools(DataUpdateCoordinator[UpdateCoordinatorDataType]): return {} def manage_device_info( - self, dev_info: Device, dev_mac: str, consider_home: bool + self, dev_info: Device, dev_mac: str, consider_home: float ) -> bool: """Update device lists and return if device is new.""" _LOGGER.debug("Client dev_info: %s", dev_info) From db2435dc3617f5277c7bec2095d391c331cbdcd3 Mon Sep 17 00:00:00 2001 From: Marc Mueller <30130371+cdce8p@users.noreply.github.com> Date: Sat, 3 May 2025 14:35:17 +0200 Subject: [PATCH 25/90] Fix litterrobot entity typing (#144147) --- homeassistant/components/litterrobot/entity.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/homeassistant/components/litterrobot/entity.py b/homeassistant/components/litterrobot/entity.py index 9e9cc8f0740..4117069aa0e 100644 --- a/homeassistant/components/litterrobot/entity.py +++ b/homeassistant/components/litterrobot/entity.py @@ -17,7 +17,7 @@ from .coordinator import LitterRobotDataUpdateCoordinator _WhiskerEntityT = TypeVar("_WhiskerEntityT", bound=Robot | Pet) -def get_device_info(whisker_entity: _WhiskerEntityT) -> DeviceInfo: +def get_device_info(whisker_entity: Robot | Pet) -> DeviceInfo: """Get device info for a robot or pet.""" if isinstance(whisker_entity, Robot): return DeviceInfo( From 64b7f2c285d4ef8dd9de7fa2ca8def5cb879552f Mon Sep 17 00:00:00 2001 From: Thomas55555 <59625598+Thomas55555@users.noreply.github.com> Date: Sat, 3 May 2025 14:39:46 +0200 Subject: [PATCH 26/90] Improve select platform in Husqvarna Automower (#144117) --- .../components/husqvarna_automower/select.py | 14 ++++++-------- .../components/husqvarna_automower/test_select.py | 2 +- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/homeassistant/components/husqvarna_automower/select.py b/homeassistant/components/husqvarna_automower/select.py index 9124a0705e1..1dde9e16295 100644 --- a/homeassistant/components/husqvarna_automower/select.py +++ b/homeassistant/components/husqvarna_automower/select.py @@ -19,10 +19,10 @@ _LOGGER = logging.getLogger(__name__) PARALLEL_UPDATES = 1 HEADLIGHT_MODES: list = [ - HeadlightModes.ALWAYS_OFF.lower(), - HeadlightModes.ALWAYS_ON.lower(), - HeadlightModes.EVENING_AND_NIGHT.lower(), - HeadlightModes.EVENING_ONLY.lower(), + HeadlightModes.ALWAYS_OFF, + HeadlightModes.ALWAYS_ON, + HeadlightModes.EVENING_AND_NIGHT, + HeadlightModes.EVENING_ONLY, ] @@ -65,13 +65,11 @@ class AutomowerSelectEntity(AutomowerControlEntity, SelectEntity): @property def current_option(self) -> str: """Return the current option for the entity.""" - return cast( - HeadlightModes, self.mower_attributes.settings.headlight.mode - ).lower() + return cast(HeadlightModes, self.mower_attributes.settings.headlight.mode) @handle_sending_exception() async def async_select_option(self, option: str) -> None: """Change the selected option.""" await self.coordinator.api.commands.set_headlight_mode( - self.mower_id, cast(HeadlightModes, option.upper()) + self.mower_id, HeadlightModes(option) ) diff --git a/tests/components/husqvarna_automower/test_select.py b/tests/components/husqvarna_automower/test_select.py index 01e7607735b..f1b855a90a3 100644 --- a/tests/components/husqvarna_automower/test_select.py +++ b/tests/components/husqvarna_automower/test_select.py @@ -74,7 +74,7 @@ async def test_select_commands( blocking=True, ) mocked_method = mock_automower_client.commands.set_headlight_mode - mocked_method.assert_called_once_with(TEST_MOWER_ID, service.upper()) + mocked_method.assert_called_once_with(TEST_MOWER_ID, service) assert len(mocked_method.mock_calls) == 1 mocked_method.side_effect = ApiError("Test error") From a2bc3e390815ca7b9dac461f7dcdcd9c9baedbdf Mon Sep 17 00:00:00 2001 From: Josef Zweck Date: Sat, 3 May 2025 14:44:18 +0200 Subject: [PATCH 27/90] Switch to common clientsession for lamarzocco (#144137) --- homeassistant/components/lamarzocco/__init__.py | 4 ++-- homeassistant/components/lamarzocco/config_flow.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/homeassistant/components/lamarzocco/__init__.py b/homeassistant/components/lamarzocco/__init__.py index ad9fec28fb4..ff977438f38 100644 --- a/homeassistant/components/lamarzocco/__init__.py +++ b/homeassistant/components/lamarzocco/__init__.py @@ -23,7 +23,7 @@ from homeassistant.const import ( from homeassistant.core import HomeAssistant from homeassistant.exceptions import ConfigEntryAuthFailed, ConfigEntryNotReady from homeassistant.helpers import issue_registry as ir -from homeassistant.helpers.aiohttp_client import async_create_clientsession +from homeassistant.helpers.aiohttp_client import async_get_clientsession from .const import CONF_USE_BLUETOOTH, DOMAIN from .coordinator import ( @@ -57,7 +57,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: LaMarzoccoConfigEntry) - assert entry.unique_id serial = entry.unique_id - client = async_create_clientsession(hass) + client = async_get_clientsession(hass) cloud_client = LaMarzoccoCloudClient( username=entry.data[CONF_USERNAME], password=entry.data[CONF_PASSWORD], diff --git a/homeassistant/components/lamarzocco/config_flow.py b/homeassistant/components/lamarzocco/config_flow.py index e352e337d0b..8cb2e4dfc61 100644 --- a/homeassistant/components/lamarzocco/config_flow.py +++ b/homeassistant/components/lamarzocco/config_flow.py @@ -33,7 +33,7 @@ from homeassistant.const import ( ) from homeassistant.core import callback from homeassistant.helpers import config_validation as cv -from homeassistant.helpers.aiohttp_client import async_create_clientsession +from homeassistant.helpers.aiohttp_client import async_get_clientsession from homeassistant.helpers.selector import ( SelectOptionDict, SelectSelector, @@ -83,7 +83,7 @@ class LmConfigFlow(ConfigFlow, domain=DOMAIN): **user_input, } - self._client = async_create_clientsession(self.hass) + self._client = async_get_clientsession(self.hass) cloud_client = LaMarzoccoCloudClient( username=data[CONF_USERNAME], password=data[CONF_PASSWORD], From ee555a3700859201d03eb5ef5a5721f27da1ad8b Mon Sep 17 00:00:00 2001 From: Shay Levy Date: Sat, 3 May 2025 17:08:34 +0300 Subject: [PATCH 28/90] Mark Shelly icon-translations as done (#144148) --- homeassistant/components/shelly/quality_scale.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/homeassistant/components/shelly/quality_scale.yaml b/homeassistant/components/shelly/quality_scale.yaml index 601170879d1..6277681347d 100644 --- a/homeassistant/components/shelly/quality_scale.yaml +++ b/homeassistant/components/shelly/quality_scale.yaml @@ -57,7 +57,7 @@ rules: entity-disabled-by-default: done entity-translations: todo exception-translations: done - icon-translations: todo + icon-translations: done reconfiguration-flow: done repair-issues: done stale-devices: From 0ca9ad1cc0bf9e687ebdc1742ec8edc6e08f2467 Mon Sep 17 00:00:00 2001 From: Shay Levy Date: Sat, 3 May 2025 17:17:37 +0300 Subject: [PATCH 29/90] Mark Shelly docs-data-update as done (#144151) --- homeassistant/components/shelly/quality_scale.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/homeassistant/components/shelly/quality_scale.yaml b/homeassistant/components/shelly/quality_scale.yaml index 6277681347d..39a032a57f6 100644 --- a/homeassistant/components/shelly/quality_scale.yaml +++ b/homeassistant/components/shelly/quality_scale.yaml @@ -42,7 +42,7 @@ rules: diagnostics: done discovery-update-info: done discovery: done - docs-data-update: todo + docs-data-update: done docs-examples: done docs-known-limitations: done docs-supported-devices: done From b48a2cf2b5c0729a083f482a51154d0e317ba3d6 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sat, 3 May 2025 10:12:37 -0500 Subject: [PATCH 30/90] Add tests to ensure ESPHome entity_ids are preserved on upgrade (#144116) --- tests/components/esphome/test_entity.py | 152 ++++++++++++++++++++++++ 1 file changed, 152 insertions(+) diff --git a/tests/components/esphome/test_entity.py b/tests/components/esphome/test_entity.py index 71a9c16cee3..ee6e6b6785f 100644 --- a/tests/components/esphome/test_entity.py +++ b/tests/components/esphome/test_entity.py @@ -10,8 +10,11 @@ from aioesphomeapi import ( BinarySensorState, SensorInfo, SensorState, + build_unique_id, ) +import pytest +from homeassistant.components.esphome import DOMAIN from homeassistant.const import ( ATTR_FRIENDLY_NAME, ATTR_RESTORED, @@ -19,6 +22,7 @@ from homeassistant.const import ( STATE_OFF, STATE_ON, STATE_UNAVAILABLE, + Platform, ) from homeassistant.core import Event, EventStateChangedData, HomeAssistant, callback from homeassistant.helpers import entity_registry as er @@ -513,3 +517,151 @@ async def test_entity_without_name_device_with_friendly_name( # Make sure we have set the name to `None` as otherwise # the friendly_name will be "The Best Mixer " assert state.attributes[ATTR_FRIENDLY_NAME] == "The Best Mixer" + + +@pytest.mark.usefixtures("hass_storage") +async def test_entity_id_preserved_on_upgrade( + hass: HomeAssistant, + mock_client: APIClient, + mock_esphome_device: MockESPHomeDeviceType, + entity_registry: er.EntityRegistry, +) -> None: + """Test entity_id is preserved on upgrade.""" + entity_info = [ + BinarySensorInfo( + object_id="my", + key=1, + name="my", + unique_id="binary_sensor_my", + ), + ] + states = [ + BinarySensorState(key=1, state=True, missing_state=False), + ] + user_service = [] + assert ( + build_unique_id("11:22:33:44:55:AA", entity_info[0]) + == "11:22:33:44:55:AA-binary_sensor-my" + ) + + entry = entity_registry.async_get_or_create( + Platform.BINARY_SENSOR, + DOMAIN, + "11:22:33:44:55:AA-binary_sensor-my", + suggested_object_id="should_not_change", + ) + assert entry.entity_id == "binary_sensor.should_not_change" + await mock_esphome_device( + mock_client=mock_client, + entity_info=entity_info, + user_service=user_service, + states=states, + device_info={"friendly_name": "The Best Mixer", "name": "mixer"}, + ) + state = hass.states.get("binary_sensor.should_not_change") + assert state is not None + + +@pytest.mark.usefixtures("hass_storage") +async def test_entity_id_preserved_on_upgrade_old_format_entity_id( + hass: HomeAssistant, + mock_client: APIClient, + mock_esphome_device: MockESPHomeDeviceType, + entity_registry: er.EntityRegistry, +) -> None: + """Test entity_id is preserved on upgrade from old format.""" + entity_info = [ + BinarySensorInfo( + object_id="my", + key=1, + name="my", + unique_id="binary_sensor_my", + ), + ] + states = [ + BinarySensorState(key=1, state=True, missing_state=False), + ] + user_service = [] + assert ( + build_unique_id("11:22:33:44:55:AA", entity_info[0]) + == "11:22:33:44:55:AA-binary_sensor-my" + ) + + entry = entity_registry.async_get_or_create( + Platform.BINARY_SENSOR, + DOMAIN, + "11:22:33:44:55:AA-binary_sensor-my", + suggested_object_id="my", + ) + assert entry.entity_id == "binary_sensor.my" + await mock_esphome_device( + mock_client=mock_client, + entity_info=entity_info, + user_service=user_service, + states=states, + device_info={"name": "mixer"}, + ) + state = hass.states.get("binary_sensor.my") + assert state is not None + + +async def test_entity_id_preserved_on_upgrade_when_in_storage( + hass: HomeAssistant, + mock_client: APIClient, + hass_storage: dict[str, Any], + mock_esphome_device: MockESPHomeDeviceType, + entity_registry: er.EntityRegistry, +) -> None: + """Test entity_id is preserved on upgrade with user defined entity_id.""" + entity_info = [ + BinarySensorInfo( + object_id="my", + key=1, + name="my", + unique_id="binary_sensor_my", + ), + ] + states = [ + BinarySensorState(key=1, state=True, missing_state=False), + ] + user_service = [] + device = await mock_esphome_device( + mock_client=mock_client, + entity_info=entity_info, + user_service=user_service, + states=states, + device_info={"friendly_name": "The Best Mixer", "name": "mixer"}, + ) + state = hass.states.get("binary_sensor.mixer_my") + assert state is not None + # now rename the entity + ent_reg_entry = entity_registry.async_get_or_create( + Platform.BINARY_SENSOR, + DOMAIN, + "11:22:33:44:55:AA-binary_sensor-my", + ) + entity_registry.async_update_entity( + ent_reg_entry.entity_id, + new_entity_id="binary_sensor.user_named", + ) + await hass.config_entries.async_unload(device.entry.entry_id) + await hass.async_block_till_done() + entry = device.entry + entry_id = entry.entry_id + storage_key = f"esphome.{entry_id}" + assert len(hass_storage[storage_key]["data"]["binary_sensor"]) == 1 + binary_sensor_data: dict[str, Any] = hass_storage[storage_key]["data"][ + "binary_sensor" + ][0] + assert binary_sensor_data["name"] == "my" + assert binary_sensor_data["object_id"] == "my" + device = await mock_esphome_device( + mock_client=mock_client, + entity_info=entity_info, + user_service=user_service, + states=states, + entry=entry, + device_info={"friendly_name": "The Best Mixer", "name": "mixer"}, + ) + state = hass.states.get("binary_sensor.user_named") + assert state is not None From 4122f94fb63aefaa6c51061da4b18650196aa3bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=2E=20Diego=20Rodr=C3=ADguez=20Royo?= Date: Sat, 3 May 2025 17:16:02 +0200 Subject: [PATCH 31/90] Add DHCP discovery to Home Connect (#144095) * Add DHCP discovery to Home Connect * Added tests * Use enums * Use more enums --- .../components/home_connect/manifest.json | 14 ++ homeassistant/generated/dhcp.py | 15 ++ .../home_connect/test_config_flow.py | 188 ++++++++++++++++-- 3 files changed, 204 insertions(+), 13 deletions(-) diff --git a/homeassistant/components/home_connect/manifest.json b/homeassistant/components/home_connect/manifest.json index 8a608a900be..e550d22e0ca 100644 --- a/homeassistant/components/home_connect/manifest.json +++ b/homeassistant/components/home_connect/manifest.json @@ -4,6 +4,20 @@ "codeowners": ["@DavidMStraub", "@Diegorro98", "@MartinHjelmare"], "config_flow": true, "dependencies": ["application_credentials", "repairs"], + "dhcp": [ + { + "hostname": "balay-*", + "macaddress": "C8D778*" + }, + { + "hostname": "(bosch|siemens)-*", + "macaddress": "68A40E*" + }, + { + "hostname": "siemens-*", + "macaddress": "38B4D3*" + } + ], "documentation": "https://www.home-assistant.io/integrations/home_connect", "iot_class": "cloud_push", "loggers": ["aiohomeconnect"], diff --git a/homeassistant/generated/dhcp.py b/homeassistant/generated/dhcp.py index 88fb8e06d02..26302b0ac8b 100644 --- a/homeassistant/generated/dhcp.py +++ b/homeassistant/generated/dhcp.py @@ -258,6 +258,21 @@ DHCP: Final[list[dict[str, str | bool]]] = [ "hostname": "guardian*", "macaddress": "30AEA4*", }, + { + "domain": "home_connect", + "hostname": "balay-*", + "macaddress": "C8D778*", + }, + { + "domain": "home_connect", + "hostname": "(bosch|siemens)-*", + "macaddress": "68A40E*", + }, + { + "domain": "home_connect", + "hostname": "siemens-*", + "macaddress": "38B4D3*", + }, { "domain": "homewizard", "registered_devices": True, diff --git a/tests/components/home_connect/test_config_flow.py b/tests/components/home_connect/test_config_flow.py index a8929120acb..73aed382780 100644 --- a/tests/components/home_connect/test_config_flow.py +++ b/tests/components/home_connect/test_config_flow.py @@ -7,15 +7,12 @@ from aiohomeconnect.const import OAUTH2_AUTHORIZE, OAUTH2_TOKEN import pytest from homeassistant import config_entries, setup -from homeassistant.components.application_credentials import ( - ClientCredential, - async_import_client_credential, -) from homeassistant.components.home_connect.const import DOMAIN from homeassistant.config_entries import ConfigEntryState from homeassistant.core import HomeAssistant from homeassistant.data_entry_flow import FlowResultType from homeassistant.helpers import config_entry_oauth2_flow +from homeassistant.helpers.service_info.dhcp import DhcpServiceInfo from .conftest import FAKE_ACCESS_TOKEN, FAKE_REFRESH_TOKEN @@ -26,6 +23,39 @@ from tests.typing import ClientSessionGenerator CLIENT_ID = "1234" CLIENT_SECRET = "5678" +DHCP_DISCOVERY = ( + DhcpServiceInfo( + ip="1.1.1.1", + hostname="balay-dishwasher-000000000000000000", + macaddress="C8:D7:78:00:00:00", + ), + DhcpServiceInfo( + ip="1.1.1.1", + hostname="BOSCH-ABCDE1234-68A40E000000", + macaddress="68:A4:0E:00:00:00", + ), + DhcpServiceInfo( + ip="1.1.1.1", + hostname="SIEMENS-ABCDE1234-68A40E000000", + macaddress="68:A4:0E:00:00:00", + ), + DhcpServiceInfo( + ip="1.1.1.1", + hostname="SIEMENS-ABCDE1234-38B4D3000000", + macaddress="38:B4:D3:00:00:00", + ), + DhcpServiceInfo( + ip="1.1.1.1", + hostname="siemens-dishwasher-000000000000000000", + macaddress="68:A4:0E:00:00:00", + ), + DhcpServiceInfo( + ip="1.1.1.1", + hostname="siemens-dishwasher-000000000000000000", + macaddress="38:B4:D3:00:00:00", + ), +) + @pytest.mark.usefixtures("current_request_with_host") async def test_full_flow( @@ -36,10 +66,6 @@ async def test_full_flow( """Check full flow.""" assert await setup.async_setup_component(hass, "home_connect", {}) - await async_import_client_credential( - hass, DOMAIN, ClientCredential(CLIENT_ID, CLIENT_SECRET) - ) - result = await hass.config_entries.flow.async_init( "home_connect", context={"source": config_entries.SOURCE_USER} ) @@ -95,10 +121,6 @@ async def test_prevent_reconfiguring_same_account( assert await setup.async_setup_component(hass, "home_connect", {}) - await async_import_client_credential( - hass, DOMAIN, ClientCredential(CLIENT_ID, CLIENT_SECRET) - ) - result = await hass.config_entries.flow.async_init( "home_connect", context={"source": config_entries.SOURCE_USER} ) @@ -135,7 +157,7 @@ async def test_prevent_reconfiguring_same_account( result = await hass.config_entries.flow.async_configure(result["flow_id"]) await hass.async_block_till_done() - assert result["type"] == "abort" + assert result["type"] is FlowResultType.ABORT assert result["reason"] == "already_configured" @@ -241,3 +263,143 @@ async def test_reauth_flow_with_different_account( assert result["type"] is FlowResultType.ABORT assert result["reason"] == "wrong_account" + + +@pytest.mark.usefixtures("current_request_with_host") +async def test_zeroconf_flow( + hass: HomeAssistant, + hass_client_no_auth: ClientSessionGenerator, + aioclient_mock: AiohttpClientMocker, +) -> None: + """Test zeroconf flow.""" + assert await setup.async_setup_component(hass, "home_connect", {}) + + result = await hass.config_entries.flow.async_init( + DOMAIN, context={"source": config_entries.SOURCE_ZEROCONF} + ) + state = config_entry_oauth2_flow._encode_jwt( + hass, + { + "flow_id": result["flow_id"], + "redirect_uri": "https://example.com/auth/external/callback", + }, + ) + + assert result["type"] is FlowResultType.EXTERNAL_STEP + assert result["url"] == ( + f"{OAUTH2_AUTHORIZE}?response_type=code&client_id={CLIENT_ID}" + "&redirect_uri=https://example.com/auth/external/callback" + f"&state={state}" + ) + + client = await hass_client_no_auth() + resp = await client.get(f"/auth/external/callback?code=abcd&state={state}") + assert resp.status == HTTPStatus.OK + assert resp.headers["content-type"] == "text/html; charset=utf-8" + + aioclient_mock.post( + OAUTH2_TOKEN, + json={ + "refresh_token": FAKE_REFRESH_TOKEN, + "access_token": FAKE_ACCESS_TOKEN, + "type": "Bearer", + "expires_in": 60, + }, + ) + + with patch( + "homeassistant.components.home_connect.async_setup_entry", return_value=True + ) as mock_setup_entry: + result = await hass.config_entries.flow.async_configure(result["flow_id"]) + await hass.async_block_till_done() + + assert hass.config_entries.async_entry_for_domain_unique_id(DOMAIN, "1234567890") + assert len(mock_setup_entry.mock_calls) == 1 + + +@pytest.mark.usefixtures("current_request_with_host") +async def test_zeroconf_flow_already_setup( + hass: HomeAssistant, + hass_client_no_auth: ClientSessionGenerator, + aioclient_mock: AiohttpClientMocker, + config_entry: MockConfigEntry, +) -> None: + """Test zeroconf discovery with already setup device.""" + config_entry.add_to_hass(hass) + + result = await hass.config_entries.flow.async_init( + DOMAIN, + context={"source": config_entries.SOURCE_ZEROCONF}, + data=DHCP_DISCOVERY[0], + ) + assert result["type"] is FlowResultType.ABORT + assert result["reason"] == "already_configured" + + +@pytest.mark.usefixtures("current_request_with_host") +@pytest.mark.parametrize("dchp_discovery", DHCP_DISCOVERY) +async def test_dhcp_flow( + hass: HomeAssistant, + hass_client_no_auth: ClientSessionGenerator, + aioclient_mock: AiohttpClientMocker, + dchp_discovery: DhcpServiceInfo, +) -> None: + """Test DHCP discovery.""" + + result = await hass.config_entries.flow.async_init( + DOMAIN, context={"source": config_entries.SOURCE_DHCP}, data=dchp_discovery + ) + state = config_entry_oauth2_flow._encode_jwt( + hass, + { + "flow_id": result["flow_id"], + "redirect_uri": "https://example.com/auth/external/callback", + }, + ) + assert result["type"] is FlowResultType.EXTERNAL_STEP + assert result["url"] == ( + f"{OAUTH2_AUTHORIZE}?response_type=code&client_id={CLIENT_ID}" + "&redirect_uri=https://example.com/auth/external/callback" + f"&state={state}" + ) + + client = await hass_client_no_auth() + resp = await client.get(f"/auth/external/callback?code=abcd&state={state}") + assert resp.status == HTTPStatus.OK + assert resp.headers["content-type"] == "text/html; charset=utf-8" + + aioclient_mock.post( + OAUTH2_TOKEN, + json={ + "refresh_token": FAKE_REFRESH_TOKEN, + "access_token": FAKE_ACCESS_TOKEN, + "type": "Bearer", + "expires_in": 60, + }, + ) + + with patch( + "homeassistant.components.home_connect.async_setup_entry", return_value=True + ) as mock_setup_entry: + result = await hass.config_entries.flow.async_configure(result["flow_id"]) + await hass.async_block_till_done() + + assert hass.config_entries.async_entry_for_domain_unique_id(DOMAIN, "1234567890") + assert len(mock_setup_entry.mock_calls) == 1 + + +@pytest.mark.usefixtures("current_request_with_host") +async def test_dhcp_flow_already_setup( + hass: HomeAssistant, + hass_client_no_auth: ClientSessionGenerator, + aioclient_mock: AiohttpClientMocker, + config_entry: MockConfigEntry, +) -> None: + """Test DHCP discovery with already setup device.""" + config_entry.add_to_hass(hass) + + result = await hass.config_entries.flow.async_init( + DOMAIN, context={"source": config_entries.SOURCE_DHCP}, data=DHCP_DISCOVERY[0] + ) + assert result["type"] is FlowResultType.ABORT + assert result["reason"] == "already_configured" From debec3bfbc29acb1060e2da9729a3cd1d0f96811 Mon Sep 17 00:00:00 2001 From: Jan Bouwhuis Date: Sat, 3 May 2025 18:13:43 +0200 Subject: [PATCH 32/90] Improve supported color modes description (#144144) --- homeassistant/components/mqtt/strings.json | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/homeassistant/components/mqtt/strings.json b/homeassistant/components/mqtt/strings.json index 7339f3869a1..23a2a888989 100644 --- a/homeassistant/components/mqtt/strings.json +++ b/homeassistant/components/mqtt/strings.json @@ -244,7 +244,6 @@ "title": "Configure MQTT device \"{mqtt_device}\"", "description": "Please configure MQTT specific details for {platform} entity \"{entity}\":", "data": { - "on_command_type": "ON command type", "blue_template": "Blue template", "brightness_template": "Brightness template", "command_template": "Command template", @@ -255,6 +254,7 @@ "force_update": "Force update", "green_template": "Green template", "last_reset_value_template": "Last reset value template", + "on_command_type": "ON command type", "optimistic": "Optimistic", "payload_off": "Payload \"off\"", "payload_on": "Payload \"on\"", @@ -275,19 +275,19 @@ "command_template": "A [template](https://www.home-assistant.io/docs/configuration/templating/#using-command-templates-with-mqtt) to render the payload to be published at the command topic.", "command_topic": "The publishing topic that will be used to control the {platform} entity. [Learn more.]({url}#command_topic)", "color_temp_template": "[Template](https://www.home-assistant.io/docs/configuration/templating/#using-value-templates-with-mqtt) to extract color temperature in Kelvin from the state payload value. Expected result of the template is an integer.", + "force_update": "Sends update events even if the value hasn’t changed. Useful if you want to have meaningful value graphs in history. [Learn more.]({url}#force_update)", "green_template": "[Template](https://www.home-assistant.io/docs/configuration/templating/#using-value-templates-with-mqtt) to extract green color from the state payload value. Expected result of the template is an integer from 0-255 range.", "last_reset_value_template": "Defines a [template](https://www.home-assistant.io/docs/configuration/templating/#using-value-templates-with-mqtt) to extract the last reset. When Last reset template is set, the State class option must be Total. [Learn more.]({url}#last_reset_value_template)", - "force_update": "Sends update events even if the value hasn’t changed. Useful if you want to have meaningful value graphs in history. [Learn more.]({url}#force_update)", "on_command_type": "Defines when the payload \"on\" is sent. Using \"Last\" (the default) will send any style (brightness, color, etc) topics first and then a payload \"on\" to the command topic. Using \"First\" will send the payload \"on\" and then any style topics. Using \"Brightness\" will only send brightness commands instead of the payload \"on\" to turn the light on.", "optimistic": "Flag that defines if the {platform} entity works in optimistic mode. [Learn more.]({url}#optimistic)", - "payload_off": "The payload that represents the off state.", - "payload_on": "The payload that represents the on state.", + "payload_off": "The payload that represents the \"off\" state.", + "payload_on": "The payload that represents the \"on\" state.", "qos": "The QoS value a {platform} entity should use.", "red_template": "[Template](https://www.home-assistant.io/docs/configuration/templating/#using-value-templates-with-mqtt) to extract red color from the state payload value. Expected result of the template is an integer from 0-255 range.", "retain": "Select if values published by the {platform} entity should be retained at the MQTT broker.", "state_template": "[Template](https://www.home-assistant.io/docs/configuration/templating/#using-value-templates-with-mqtt) to extract state from the state payload value.", "state_topic": "The MQTT topic subscribed to receive {platform} state values. [Learn more.]({url}#state_topic)", - "supported_color_modes": "A list of color modes supported by the list. Possible color modes are On/Off, Brightness, Color temperature, HS, XY, RGB, RGBW, RGBWW, White. Note that if On/Off or Brightness are used, that must be the only value in the list. [Learn more.]({url}#supported_color_modes)", + "supported_color_modes": "A list of color modes supported by the light. Possible color modes are On/Off, Brightness, Color temperature, HS, XY, RGB, RGBW, RGBWW, White. Note that if On/Off or Brightness are used, that must be the only value in the list. [Learn more.]({url}#supported_color_modes)", "value_template": "Defines a [template](https://www.home-assistant.io/docs/configuration/templating/#using-value-templates-with-mqtt) to extract the {platform} entity value. [Learn more.]({url}#value_template)" }, "sections": { From aea5760424fa1deeae896d5871912ed9ddbdbb6b Mon Sep 17 00:00:00 2001 From: Florian Sabonchi <54689374+florian-sabonchi@users.noreply.github.com> Date: Sat, 3 May 2025 20:25:27 +0200 Subject: [PATCH 33/90] Fix check for locked device in AVM Fritz!SmartHome (#141697) * feat: raise execption on hvac mode while device is locked * fix: test for setting hvac mode while device is locked. * feat: update translation * feat: add separate translations for HVAC and temperature * fix: test cases * fix: test cases for test_set_preset_mode_boost * rev: code review * rev: exception string * feat: updated error message and added helper function * Update homeassistant/components/fritzbox/strings.json Co-authored-by: Michael <35783820+mib1185@users.noreply.github.com> * fix: translation key * remove check_active_or_lock_mode from async_set_preset_mode --------- Co-authored-by: Michael <35783820+mib1185@users.noreply.github.com> --- homeassistant/components/fritzbox/climate.py | 27 +++-- .../components/fritzbox/strings.json | 8 +- tests/components/fritzbox/test_climate.py | 113 +++++++++++++++++- 3 files changed, 130 insertions(+), 18 deletions(-) diff --git a/homeassistant/components/fritzbox/climate.py b/homeassistant/components/fritzbox/climate.py index 194bc5621b3..573877fa71b 100644 --- a/homeassistant/components/fritzbox/climate.py +++ b/homeassistant/components/fritzbox/climate.py @@ -144,6 +144,7 @@ class FritzboxThermostat(FritzBoxDeviceEntity, ClimateEntity): async def async_set_temperature(self, **kwargs: Any) -> None: """Set new target temperature.""" + self.check_active_or_lock_mode() if kwargs.get(ATTR_HVAC_MODE) is HVACMode.OFF: await self.async_set_hkr_state("off") elif (target_temp := kwargs.get(ATTR_TEMPERATURE)) is not None: @@ -168,11 +169,7 @@ class FritzboxThermostat(FritzBoxDeviceEntity, ClimateEntity): async def async_set_hvac_mode(self, hvac_mode: HVACMode) -> None: """Set new operation mode.""" - if self.data.holiday_active or self.data.summer_active: - raise HomeAssistantError( - translation_domain=DOMAIN, - translation_key="change_hvac_while_active_mode", - ) + self.check_active_or_lock_mode() if self.hvac_mode is hvac_mode: LOGGER.debug( "%s is already in requested hvac mode %s", self.name, hvac_mode @@ -204,11 +201,7 @@ class FritzboxThermostat(FritzBoxDeviceEntity, ClimateEntity): async def async_set_preset_mode(self, preset_mode: str) -> None: """Set preset mode.""" - if self.data.holiday_active or self.data.summer_active: - raise HomeAssistantError( - translation_domain=DOMAIN, - translation_key="change_preset_while_active_mode", - ) + self.check_active_or_lock_mode() await self.async_set_hkr_state(PRESET_API_HKR_STATE_MAPPING[preset_mode]) @property @@ -230,3 +223,17 @@ class FritzboxThermostat(FritzBoxDeviceEntity, ClimateEntity): attrs[ATTR_STATE_WINDOW_OPEN] = self.data.window_open return attrs + + def check_active_or_lock_mode(self) -> None: + """Check if in summer/vacation mode or lock enabled.""" + if self.data.holiday_active or self.data.summer_active: + raise HomeAssistantError( + translation_domain=DOMAIN, + translation_key="change_settings_while_active_mode", + ) + + if self.data.lock: + raise HomeAssistantError( + translation_domain=DOMAIN, + translation_key="change_settings_while_lock_enabled", + ) diff --git a/homeassistant/components/fritzbox/strings.json b/homeassistant/components/fritzbox/strings.json index bb7d2f0fdf1..38bc6dc9c39 100644 --- a/homeassistant/components/fritzbox/strings.json +++ b/homeassistant/components/fritzbox/strings.json @@ -88,11 +88,11 @@ "manual_switching_disabled": { "message": "Can't toggle switch while manual switching is disabled for the device." }, - "change_preset_while_active_mode": { - "message": "Can't change preset while holiday or summer mode is active on the device." + "change_settings_while_lock_enabled": { + "message": "Can't change settings while manual access for telephone, app, or user interface is disabled on the device" }, - "change_hvac_while_active_mode": { - "message": "Can't change HVAC mode while holiday or summer mode is active on the device." + "change_settings_while_active_mode": { + "message": "Can't change settings while holiday or summer mode is active on the device." } } } diff --git a/tests/components/fritzbox/test_climate.py b/tests/components/fritzbox/test_climate.py index 5bf81ef0238..bdf9dba8b42 100644 --- a/tests/components/fritzbox/test_climate.py +++ b/tests/components/fritzbox/test_climate.py @@ -211,6 +211,8 @@ async def test_set_temperature( ) -> None: """Test setting temperature.""" device = FritzDeviceClimateMock() + device.lock = False + await setup_config_entry( hass, MOCK_CONFIG[FB_DOMAIN][CONF_DEVICES][0], ENTITY_ID, device, fritz ) @@ -288,6 +290,8 @@ async def test_set_hvac_mode( ) -> None: """Test setting hvac mode.""" device = FritzDeviceClimateMock() + + device.lock = False device.target_temperature = target_temperature if current_preset is PRESET_COMFORT: @@ -335,6 +339,8 @@ async def test_set_preset_mode_comfort( ) -> None: """Test setting preset mode.""" device = FritzDeviceClimateMock() + + device.lock = False device.comfort_temperature = comfort_temperature await setup_config_entry( hass, MOCK_CONFIG[FB_DOMAIN][CONF_DEVICES][0], ENTITY_ID, device, fritz @@ -366,6 +372,8 @@ async def test_set_preset_mode_eco( ) -> None: """Test setting preset mode.""" device = FritzDeviceClimateMock() + + device.lock = False device.eco_temperature = eco_temperature await setup_config_entry( hass, MOCK_CONFIG[FB_DOMAIN][CONF_DEVICES][0], ENTITY_ID, device, fritz @@ -387,6 +395,8 @@ async def test_set_preset_mode_boost( ) -> None: """Test setting preset mode.""" device = FritzDeviceClimateMock() + device.lock = False + await setup_config_entry( hass, MOCK_CONFIG[FB_DOMAIN][CONF_DEVICES][0], ENTITY_ID, device, fritz ) @@ -471,11 +481,106 @@ async def test_discover_new_device(hass: HomeAssistant, fritz: Mock) -> None: assert state +@pytest.mark.parametrize( + "service_data", + [ + {ATTR_TEMPERATURE: 23}, + { + ATTR_HVAC_MODE: HVACMode.HEAT, + ATTR_TEMPERATURE: 25, + }, + ], +) +async def test_set_temperature_lock( + hass: HomeAssistant, + fritz: Mock, + service_data: dict, +) -> None: + """Test setting temperature while device is locked.""" + device = FritzDeviceClimateMock() + + device.lock = True + assert await setup_config_entry( + hass, MOCK_CONFIG[FB_DOMAIN][CONF_DEVICES][0], ENTITY_ID, device, fritz + ) + + with pytest.raises( + HomeAssistantError, + match="Can't change settings while manual access for telephone, app, or user interface is disabled on the device", + ): + await hass.services.async_call( + CLIMATE_DOMAIN, + SERVICE_SET_TEMPERATURE, + {ATTR_ENTITY_ID: ENTITY_ID, **service_data}, + True, + ) + + +@pytest.mark.parametrize( + ("service_data", "target_temperature", "current_preset", "expected_call_args"), + [ + # mode off always sets target temperature to 0 + ({ATTR_HVAC_MODE: HVACMode.OFF}, 22, PRESET_COMFORT, [call(0, True)]), + ({ATTR_HVAC_MODE: HVACMode.OFF}, 16, PRESET_ECO, [call(0, True)]), + ({ATTR_HVAC_MODE: HVACMode.OFF}, 16, None, [call(0, True)]), + # mode heat sets target temperature based on current scheduled preset, + # when not already in mode heat + ({ATTR_HVAC_MODE: HVACMode.HEAT}, 0.0, PRESET_COMFORT, [call(22, True)]), + ({ATTR_HVAC_MODE: HVACMode.HEAT}, 0.0, PRESET_ECO, [call(16, True)]), + ({ATTR_HVAC_MODE: HVACMode.HEAT}, 0.0, None, [call(22, True)]), + # mode heat does not set target temperature, when already in mode heat + ({ATTR_HVAC_MODE: HVACMode.HEAT}, 16, PRESET_COMFORT, []), + ({ATTR_HVAC_MODE: HVACMode.HEAT}, 16, PRESET_ECO, []), + ({ATTR_HVAC_MODE: HVACMode.HEAT}, 16, None, []), + ({ATTR_HVAC_MODE: HVACMode.HEAT}, 22, PRESET_COMFORT, []), + ({ATTR_HVAC_MODE: HVACMode.HEAT}, 22, PRESET_ECO, []), + ({ATTR_HVAC_MODE: HVACMode.HEAT}, 22, None, []), + ], +) +async def test_set_hvac_mode_lock( + hass: HomeAssistant, + fritz: Mock, + service_data: dict, + target_temperature: float, + current_preset: str, + expected_call_args: list[_Call], +) -> None: + """Test setting hvac mode while device is locked.""" + device = FritzDeviceClimateMock() + + device.lock = True + device.target_temperature = target_temperature + + if current_preset is PRESET_COMFORT: + device.nextchange_temperature = device.eco_temperature + elif current_preset is PRESET_ECO: + device.nextchange_temperature = device.comfort_temperature + else: + device.nextchange_endperiod = 0 + + assert await setup_config_entry( + hass, MOCK_CONFIG[FB_DOMAIN][CONF_DEVICES][0], ENTITY_ID, device, fritz + ) + + with pytest.raises( + HomeAssistantError, + match="Can't change settings while manual access for telephone, app, or user interface is disabled on the device", + ): + await hass.services.async_call( + CLIMATE_DOMAIN, + SERVICE_SET_HVAC_MODE, + {ATTR_ENTITY_ID: ENTITY_ID, **service_data}, + True, + ) + + async def test_holidy_summer_mode( hass: HomeAssistant, freezer: FrozenDateTimeFactory, fritz: Mock ) -> None: """Test holiday and summer mode.""" device = FritzDeviceClimateMock() + device.lock = False + await setup_config_entry( hass, MOCK_CONFIG[FB_DOMAIN][CONF_DEVICES][0], ENTITY_ID, device, fritz ) @@ -510,7 +615,7 @@ async def test_holidy_summer_mode( with pytest.raises( HomeAssistantError, - match="Can't change HVAC mode while holiday or summer mode is active on the device", + match="Can't change settings while holiday or summer mode is active on the device", ): await hass.services.async_call( "climate", @@ -520,7 +625,7 @@ async def test_holidy_summer_mode( ) with pytest.raises( HomeAssistantError, - match="Can't change preset while holiday or summer mode is active on the device", + match="Can't change settings while holiday or summer mode is active on the device", ): await hass.services.async_call( "climate", @@ -546,7 +651,7 @@ async def test_holidy_summer_mode( with pytest.raises( HomeAssistantError, - match="Can't change HVAC mode while holiday or summer mode is active on the device", + match="Can't change settings while holiday or summer mode is active on the device", ): await hass.services.async_call( "climate", @@ -556,7 +661,7 @@ async def test_holidy_summer_mode( ) with pytest.raises( HomeAssistantError, - match="Can't change preset while holiday or summer mode is active on the device", + match="Can't change settings while holiday or summer mode is active on the device", ): await hass.services.async_call( "climate", From fb94f8ea189cb18e2b11c5166687e2b9ebb4bd60 Mon Sep 17 00:00:00 2001 From: Michael <35783820+mib1185@users.noreply.github.com> Date: Sat, 3 May 2025 21:04:59 +0200 Subject: [PATCH 34/90] Make the network device tracking feature optional in AVM Fritz!Tools (#144149) * make the network device tracking feature optional * fix doc strings * Apply suggestions from code review Co-authored-by: Jan Bouwhuis --------- Co-authored-by: Jan Bouwhuis --- homeassistant/components/fritz/__init__.py | 7 +++++ homeassistant/components/fritz/config_flow.py | 24 +++++++++++++-- homeassistant/components/fritz/const.py | 3 ++ homeassistant/components/fritz/coordinator.py | 30 ++++++++++++++----- homeassistant/components/fritz/strings.json | 22 +++++++++----- tests/components/fritz/test_config_flow.py | 2 ++ 6 files changed, 71 insertions(+), 17 deletions(-) diff --git a/homeassistant/components/fritz/__init__.py b/homeassistant/components/fritz/__init__.py index 05a2a07707f..9610fe4b34d 100644 --- a/homeassistant/components/fritz/__init__.py +++ b/homeassistant/components/fritz/__init__.py @@ -15,6 +15,8 @@ from homeassistant.helpers import config_validation as cv from homeassistant.helpers.typing import ConfigType from .const import ( + CONF_FEATURE_DEVICE_TRACKING, + DEFAULT_CONF_FEATURE_DEVICE_TRACKING, DEFAULT_SSL, DOMAIN, FRITZ_AUTH_EXCEPTIONS, @@ -38,6 +40,7 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: async def async_setup_entry(hass: HomeAssistant, entry: FritzConfigEntry) -> bool: """Set up fritzboxtools from config entry.""" _LOGGER.debug("Setting up FRITZ!Box Tools component") + avm_wrapper = AvmWrapper( hass=hass, config_entry=entry, @@ -46,6 +49,9 @@ async def async_setup_entry(hass: HomeAssistant, entry: FritzConfigEntry) -> boo username=entry.data[CONF_USERNAME], password=entry.data[CONF_PASSWORD], use_tls=entry.data.get(CONF_SSL, DEFAULT_SSL), + device_discovery_enabled=entry.options.get( + CONF_FEATURE_DEVICE_TRACKING, DEFAULT_CONF_FEATURE_DEVICE_TRACKING + ), ) try: @@ -62,6 +68,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: FritzConfigEntry) -> boo raise ConfigEntryAuthFailed("Missing UPnP configuration") await avm_wrapper.async_config_entry_first_refresh() + await avm_wrapper.async_trigger_cleanup() entry.runtime_data = avm_wrapper diff --git a/homeassistant/components/fritz/config_flow.py b/homeassistant/components/fritz/config_flow.py index fb17f872cb6..2c22a35c4dd 100644 --- a/homeassistant/components/fritz/config_flow.py +++ b/homeassistant/components/fritz/config_flow.py @@ -35,7 +35,9 @@ from homeassistant.helpers.service_info.ssdp import ( from homeassistant.helpers.typing import VolDictType from .const import ( + CONF_FEATURE_DEVICE_TRACKING, CONF_OLD_DISCOVERY, + DEFAULT_CONF_FEATURE_DEVICE_TRACKING, DEFAULT_CONF_OLD_DISCOVERY, DEFAULT_HOST, DEFAULT_HTTP_PORT, @@ -72,7 +74,8 @@ class FritzBoxToolsFlowHandler(ConfigFlow, domain=DOMAIN): """Initialize FRITZ!Box Tools flow.""" self._name: str = "" self._password: str = "" - self._use_tls: bool = False + self._use_tls: bool = DEFAULT_SSL + self._feature_device_discovery: bool = DEFAULT_CONF_FEATURE_DEVICE_TRACKING self._port: int | None = None self._username: str = "" self._model: str = "" @@ -141,6 +144,7 @@ class FritzBoxToolsFlowHandler(ConfigFlow, domain=DOMAIN): options={ CONF_CONSIDER_HOME: DEFAULT_CONSIDER_HOME.total_seconds(), CONF_OLD_DISCOVERY: DEFAULT_CONF_OLD_DISCOVERY, + CONF_FEATURE_DEVICE_TRACKING: self._feature_device_discovery, }, ) @@ -204,6 +208,7 @@ class FritzBoxToolsFlowHandler(ConfigFlow, domain=DOMAIN): self._username = user_input[CONF_USERNAME] self._password = user_input[CONF_PASSWORD] self._use_tls = user_input[CONF_SSL] + self._feature_device_discovery = user_input[CONF_FEATURE_DEVICE_TRACKING] self._port = self._determine_port(user_input) error = await self.async_fritz_tools_init() @@ -234,6 +239,10 @@ class FritzBoxToolsFlowHandler(ConfigFlow, domain=DOMAIN): vol.Required(CONF_USERNAME): str, vol.Required(CONF_PASSWORD): str, vol.Optional(CONF_SSL, default=DEFAULT_SSL): bool, + vol.Required( + CONF_FEATURE_DEVICE_TRACKING, + default=DEFAULT_CONF_FEATURE_DEVICE_TRACKING, + ): bool, } ), errors=errors or {}, @@ -250,6 +259,10 @@ class FritzBoxToolsFlowHandler(ConfigFlow, domain=DOMAIN): vol.Required(CONF_USERNAME): str, vol.Required(CONF_PASSWORD): str, vol.Optional(CONF_SSL, default=DEFAULT_SSL): bool, + vol.Required( + CONF_FEATURE_DEVICE_TRACKING, + default=DEFAULT_CONF_FEATURE_DEVICE_TRACKING, + ): bool, } ), description_placeholders={"name": self._name}, @@ -405,7 +418,7 @@ class FritzBoxToolsOptionsFlowHandler(OptionsFlow): """Handle options flow.""" if user_input is not None: - return self.async_create_entry(title="", data=user_input) + return self.async_create_entry(data=user_input) options = self.config_entry.options data_schema = vol.Schema( @@ -420,6 +433,13 @@ class FritzBoxToolsOptionsFlowHandler(OptionsFlow): CONF_OLD_DISCOVERY, default=options.get(CONF_OLD_DISCOVERY, DEFAULT_CONF_OLD_DISCOVERY), ): bool, + vol.Optional( + CONF_FEATURE_DEVICE_TRACKING, + default=options.get( + CONF_FEATURE_DEVICE_TRACKING, + DEFAULT_CONF_FEATURE_DEVICE_TRACKING, + ), + ): bool, } ) return self.async_show_form(step_id="init", data_schema=data_schema) diff --git a/homeassistant/components/fritz/const.py b/homeassistant/components/fritz/const.py index 2237823bc3b..32f52e68458 100644 --- a/homeassistant/components/fritz/const.py +++ b/homeassistant/components/fritz/const.py @@ -40,6 +40,9 @@ PLATFORMS = [ CONF_OLD_DISCOVERY = "old_discovery" DEFAULT_CONF_OLD_DISCOVERY = False +CONF_FEATURE_DEVICE_TRACKING = "feature_device_tracking" +DEFAULT_CONF_FEATURE_DEVICE_TRACKING = True + DSL_CONNECTION: Literal["dsl"] = "dsl" DEFAULT_DEVICE_NAME = "Unknown device" diff --git a/homeassistant/components/fritz/coordinator.py b/homeassistant/components/fritz/coordinator.py index d253e9b5b12..e22a66d254f 100644 --- a/homeassistant/components/fritz/coordinator.py +++ b/homeassistant/components/fritz/coordinator.py @@ -39,6 +39,7 @@ from homeassistant.util.hass_dict import HassKey from .const import ( CONF_OLD_DISCOVERY, + DEFAULT_CONF_FEATURE_DEVICE_TRACKING, DEFAULT_CONF_OLD_DISCOVERY, DEFAULT_HOST, DEFAULT_SSL, @@ -175,6 +176,7 @@ class FritzBoxTools(DataUpdateCoordinator[UpdateCoordinatorDataType]): username: str = DEFAULT_USERNAME, host: str = DEFAULT_HOST, use_tls: bool = DEFAULT_SSL, + device_discovery_enabled: bool = DEFAULT_CONF_FEATURE_DEVICE_TRACKING, ) -> None: """Initialize FritzboxTools class.""" super().__init__( @@ -202,6 +204,7 @@ class FritzBoxTools(DataUpdateCoordinator[UpdateCoordinatorDataType]): self.port = port self.username = username self.use_tls = use_tls + self.device_discovery_enabled = device_discovery_enabled self.has_call_deflections: bool = False self._model: str | None = None self._current_firmware: str | None = None @@ -332,10 +335,15 @@ class FritzBoxTools(DataUpdateCoordinator[UpdateCoordinatorDataType]): "entity_states": {}, } try: - await self.async_scan_devices() + await self.async_update_device_info() + + if self.device_discovery_enabled: + await self.async_scan_devices() + entity_data["entity_states"] = await self.hass.async_add_executor_job( self._entity_states_update ) + if self.has_call_deflections: entity_data[ "call_deflections" @@ -551,12 +559,8 @@ class FritzBoxTools(DataUpdateCoordinator[UpdateCoordinatorDataType]): if new_device: async_dispatcher_send(self.hass, self.signal_device_new) - async def async_scan_devices(self, now: datetime | None = None) -> None: - """Scan for new devices and return a list of found device ids.""" - - if self.hass.is_stopping: - _ha_is_stopping("scan devices") - return + async def async_update_device_info(self, now: datetime | None = None) -> None: + """Update own device information.""" _LOGGER.debug("Checking host info for FRITZ!Box device %s", self.host) ( @@ -565,6 +569,13 @@ class FritzBoxTools(DataUpdateCoordinator[UpdateCoordinatorDataType]): self._release_url, ) = await self._async_update_device_info() + async def async_scan_devices(self, now: datetime | None = None) -> None: + """Scan for new network devices.""" + + if self.hass.is_stopping: + _ha_is_stopping("scan devices") + return + _LOGGER.debug("Checking devices for FRITZ!Box device %s", self.host) _default_consider_home = DEFAULT_CONSIDER_HOME.total_seconds() if self._options: @@ -683,7 +694,10 @@ class FritzBoxTools(DataUpdateCoordinator[UpdateCoordinatorDataType]): async def async_trigger_cleanup(self) -> None: """Trigger device trackers cleanup.""" - device_hosts = await self._async_update_hosts_info() + _LOGGER.debug("Device tracker cleanup triggered") + device_hosts = {self.mac: Device(True, "", "", "", "", None)} + if self.device_discovery_enabled: + device_hosts = await self._async_update_hosts_info() entity_reg: er.EntityRegistry = er.async_get(self.hass) config_entry = self.config_entry diff --git a/homeassistant/components/fritz/strings.json b/homeassistant/components/fritz/strings.json index 6191fc524dd..ee23a8cfbef 100644 --- a/homeassistant/components/fritz/strings.json +++ b/homeassistant/components/fritz/strings.json @@ -4,7 +4,9 @@ "data_description_port": "Leave empty to use the default port.", "data_description_username": "Username for the FRITZ!Box.", "data_description_password": "Password for the FRITZ!Box.", - "data_description_ssl": "Use SSL to connect to the FRITZ!Box." + "data_description_ssl": "Use SSL to connect to the FRITZ!Box.", + "data_description_feature_device_tracking": "Enable or disable the network device tracking feature.", + "data_feature_device_tracking": "Enable network device tracking" }, "config": { "flow_title": "{name}", @@ -15,12 +17,14 @@ "data": { "username": "[%key:common::config_flow::data::username%]", "password": "[%key:common::config_flow::data::password%]", - "ssl": "[%key:common::config_flow::data::ssl%]" + "ssl": "[%key:common::config_flow::data::ssl%]", + "feature_device_tracking": "[%key:component::fritz::common::data_feature_device_tracking%]" }, "data_description": { "username": "[%key:component::fritz::common::data_description_username%]", "password": "[%key:component::fritz::common::data_description_password%]", - "ssl": "[%key:component::fritz::common::data_description_ssl%]" + "ssl": "[%key:component::fritz::common::data_description_ssl%]", + "feature_device_tracking": "[%key:component::fritz::common::data_description_feature_device_tracking%]" } }, "reauth_confirm": { @@ -57,14 +61,16 @@ "port": "[%key:common::config_flow::data::port%]", "username": "[%key:common::config_flow::data::username%]", "password": "[%key:common::config_flow::data::password%]", - "ssl": "[%key:common::config_flow::data::ssl%]" + "ssl": "[%key:common::config_flow::data::ssl%]", + "feature_device_tracking": "[%key:component::fritz::common::data_feature_device_tracking%]" }, "data_description": { "host": "[%key:component::fritz::common::data_description_host%]", "port": "[%key:component::fritz::common::data_description_port%]", "username": "[%key:component::fritz::common::data_description_username%]", "password": "[%key:component::fritz::common::data_description_password%]", - "ssl": "[%key:component::fritz::common::data_description_ssl%]" + "ssl": "[%key:component::fritz::common::data_description_ssl%]", + "feature_device_tracking": "[%key:component::fritz::common::data_description_feature_device_tracking%]" } } }, @@ -89,11 +95,13 @@ "init": { "data": { "consider_home": "Seconds to consider a device at 'home'", - "old_discovery": "Enable old discovery method" + "old_discovery": "Enable old discovery method", + "feature_device_tracking": "[%key:component::fritz::common::data_feature_device_tracking%]" }, "data_description": { "consider_home": "Time in seconds to consider a device at home. Default is 180 seconds.", - "old_discovery": "Enable old discovery method. This is needed for some scenarios." + "old_discovery": "Enable old discovery method. This is needed for some scenarios.", + "feature_device_tracking": "[%key:component::fritz::common::data_description_feature_device_tracking%]" } } } diff --git a/tests/components/fritz/test_config_flow.py b/tests/components/fritz/test_config_flow.py index ee3ae881b2c..f790489c341 100644 --- a/tests/components/fritz/test_config_flow.py +++ b/tests/components/fritz/test_config_flow.py @@ -16,6 +16,7 @@ from homeassistant.components.device_tracker import ( DEFAULT_CONSIDER_HOME, ) from homeassistant.components.fritz.const import ( + CONF_FEATURE_DEVICE_TRACKING, CONF_OLD_DISCOVERY, DOMAIN, ERROR_AUTH_INVALID, @@ -744,6 +745,7 @@ async def test_options_flow(hass: HomeAssistant) -> None: assert result["data"] == { CONF_OLD_DISCOVERY: False, CONF_CONSIDER_HOME: 37, + CONF_FEATURE_DEVICE_TRACKING: True, } From 30e4264aa9d987d09e65dcb4360f99a26ca9f500 Mon Sep 17 00:00:00 2001 From: Charlie Rusbridger Date: Sat, 3 May 2025 20:10:33 +0100 Subject: [PATCH 35/90] Use kodi posters, fall back to thumbnails if unavailable. (#144066) --- homeassistant/components/kodi/browse_media.py | 34 +++++++++++++------ 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/homeassistant/components/kodi/browse_media.py b/homeassistant/components/kodi/browse_media.py index 60e99d98cb1..3873f385881 100644 --- a/homeassistant/components/kodi/browse_media.py +++ b/homeassistant/components/kodi/browse_media.py @@ -152,7 +152,10 @@ async def item_payload(item, get_thumbnail_url=None): _LOGGER.debug("Unknown media type received: %s", media_content_type) raise UnknownMediaType from err - thumbnail = item.get("thumbnail") + if "art" in item: + thumbnail = item["art"].get("poster", item.get("thumbnail")) + else: + thumbnail = item.get("thumbnail") if thumbnail is not None and get_thumbnail_url is not None: thumbnail = await get_thumbnail_url( media_content_type, media_content_id, thumbnail_url=thumbnail @@ -237,14 +240,16 @@ async def get_media_info(media_library, search_id, search_type): title = None media = None - properties = ["thumbnail"] + properties = ["thumbnail", "art"] if search_type == MediaType.ALBUM: if search_id: album = await media_library.get_album_details( album_id=int(search_id), properties=properties ) thumbnail = media_library.thumbnail_url( - album["albumdetails"].get("thumbnail") + album["albumdetails"]["art"].get( + "poster", album["albumdetails"].get("thumbnail") + ) ) title = album["albumdetails"]["label"] media = await media_library.get_songs( @@ -256,6 +261,7 @@ async def get_media_info(media_library, search_id, search_type): "album", "thumbnail", "track", + "art", ], ) media = media.get("songs") @@ -274,7 +280,9 @@ async def get_media_info(media_library, search_id, search_type): artist_id=int(search_id), properties=properties ) thumbnail = media_library.thumbnail_url( - artist["artistdetails"].get("thumbnail") + artist["artistdetails"]["art"].get( + "poster", artist["artistdetails"].get("thumbnail") + ) ) title = artist["artistdetails"]["label"] else: @@ -293,9 +301,10 @@ async def get_media_info(media_library, search_id, search_type): movie_id=int(search_id), properties=properties ) thumbnail = media_library.thumbnail_url( - movie["moviedetails"].get("thumbnail") + movie["moviedetails"]["art"].get( + "poster", movie["moviedetails"].get("thumbnail") + ) ) - title = movie["moviedetails"]["label"] else: media = await media_library.get_movies(properties) media = media.get("movies") @@ -305,14 +314,16 @@ async def get_media_info(media_library, search_id, search_type): if search_id: media = await media_library.get_seasons( tv_show_id=int(search_id), - properties=["thumbnail", "season", "tvshowid"], + properties=["thumbnail", "season", "tvshowid", "art"], ) media = media.get("seasons") tvshow = await media_library.get_tv_show_details( tv_show_id=int(search_id), properties=properties ) thumbnail = media_library.thumbnail_url( - tvshow["tvshowdetails"].get("thumbnail") + tvshow["tvshowdetails"]["art"].get( + "poster", tvshow["tvshowdetails"].get("thumbnail") + ) ) title = tvshow["tvshowdetails"]["label"] else: @@ -325,7 +336,7 @@ async def get_media_info(media_library, search_id, search_type): media = await media_library.get_episodes( tv_show_id=int(tv_show_id), season_id=int(season_id), - properties=["thumbnail", "tvshowid", "seasonid"], + properties=["thumbnail", "tvshowid", "seasonid", "art"], ) media = media.get("episodes") if media: @@ -333,7 +344,9 @@ async def get_media_info(media_library, search_id, search_type): season_id=int(media[0]["seasonid"]), properties=properties ) thumbnail = media_library.thumbnail_url( - season["seasondetails"].get("thumbnail") + season["seasondetails"]["art"].get( + "poster", season["seasondetails"].get("thumbnail") + ) ) title = season["seasondetails"]["label"] @@ -343,6 +356,7 @@ async def get_media_info(media_library, search_id, search_type): properties=["thumbnail", "channeltype", "channel", "broadcastnow"], ) media = media.get("channels") + title = "Channels" return thumbnail, title, media From 716b559e5d50a00f47b96f581f13bc969df88c8c Mon Sep 17 00:00:00 2001 From: tronikos Date: Sat, 3 May 2025 12:12:01 -0700 Subject: [PATCH 36/90] Skip the update right after the migration in Opower (#144088) * Wait for the migration to finish in Opower * Don't call async_block_till_done since this can timeout and seems to meant for tests * Don't call async_block_till_done since this can timeout and seems to meant for tests --- .../components/opower/coordinator.py | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/homeassistant/components/opower/coordinator.py b/homeassistant/components/opower/coordinator.py index adb32d914ee..dd0b2c87bb5 100644 --- a/homeassistant/components/opower/coordinator.py +++ b/homeassistant/components/opower/coordinator.py @@ -190,7 +190,7 @@ class OpowerCoordinator(DataUpdateCoordinator[dict[str, Forecast]]): return_sum = 0.0 last_stats_time = None else: - await self._async_maybe_migrate_statistics( + migrated = await self._async_maybe_migrate_statistics( account.utility_account_id, { cost_statistic_id: compensation_statistic_id, @@ -203,6 +203,13 @@ class OpowerCoordinator(DataUpdateCoordinator[dict[str, Forecast]]): return_statistic_id: return_metadata, }, ) + if migrated: + # Skip update to avoid working on old data since the migration is done + # asynchronously. Update the statistics in the next refresh in 12h. + _LOGGER.debug( + "Statistics migration completed. Skipping update for now" + ) + continue cost_reads = await self._async_get_cost_reads( account, self.api.utility.timezone(), @@ -326,7 +333,7 @@ class OpowerCoordinator(DataUpdateCoordinator[dict[str, Forecast]]): utility_account_id: str, migration_map: dict[str, str], metadata_map: dict[str, StatisticMetaData], - ) -> None: + ) -> bool: """Perform one-time statistics migration based on the provided map. Splits negative values from source IDs into target IDs. @@ -339,7 +346,7 @@ class OpowerCoordinator(DataUpdateCoordinator[dict[str, Forecast]]): """ if not migration_map: - return + return False need_migration_source_ids = set() for source_id, target_id in migration_map.items(): @@ -354,7 +361,7 @@ class OpowerCoordinator(DataUpdateCoordinator[dict[str, Forecast]]): if not last_target_stat: need_migration_source_ids.add(source_id) if not need_migration_source_ids: - return + return False _LOGGER.info("Starting one-time migration for: %s", need_migration_source_ids) @@ -416,7 +423,7 @@ class OpowerCoordinator(DataUpdateCoordinator[dict[str, Forecast]]): if not need_migration_source_ids: _LOGGER.debug("No migration needed") - return + return False for stat_id, stats in processed_stats.items(): _LOGGER.debug("Applying %d migrated stats for %s", len(stats), stat_id) @@ -442,6 +449,8 @@ class OpowerCoordinator(DataUpdateCoordinator[dict[str, Forecast]]): }, ) + return True + async def _async_get_cost_reads( self, account: Account, time_zone_str: str, start_time: float | None = None ) -> list[CostRead]: From 1264c2cbfa9ebefef3bc4be65a53115e35b8dea5 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sat, 3 May 2025 14:21:03 -0500 Subject: [PATCH 37/90] Bump zeroconf to 0.147.0 (#144158) --- homeassistant/components/zeroconf/manifest.json | 2 +- homeassistant/package_constraints.txt | 2 +- pyproject.toml | 2 +- requirements.txt | 2 +- requirements_all.txt | 2 +- requirements_test_all.txt | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/homeassistant/components/zeroconf/manifest.json b/homeassistant/components/zeroconf/manifest.json index e2637d792e2..fe190e78956 100644 --- a/homeassistant/components/zeroconf/manifest.json +++ b/homeassistant/components/zeroconf/manifest.json @@ -8,5 +8,5 @@ "iot_class": "local_push", "loggers": ["zeroconf"], "quality_scale": "internal", - "requirements": ["zeroconf==0.146.5"] + "requirements": ["zeroconf==0.147.0"] } diff --git a/homeassistant/package_constraints.txt b/homeassistant/package_constraints.txt index 8b53ae13687..6845f3fab9b 100644 --- a/homeassistant/package_constraints.txt +++ b/homeassistant/package_constraints.txt @@ -75,7 +75,7 @@ voluptuous-serialize==2.6.0 voluptuous==0.15.2 webrtc-models==0.3.0 yarl==1.20.0 -zeroconf==0.146.5 +zeroconf==0.147.0 # Constrain pycryptodome to avoid vulnerability # see https://github.com/home-assistant/core/pull/16238 diff --git a/pyproject.toml b/pyproject.toml index c71cf0dbaf2..8623d54b963 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -123,7 +123,7 @@ dependencies = [ "voluptuous-openapi==0.0.7", "yarl==1.20.0", "webrtc-models==0.3.0", - "zeroconf==0.146.5", + "zeroconf==0.147.0", ] [project.urls] diff --git a/requirements.txt b/requirements.txt index 5bbf33025c3..e8b9e12bfe0 100644 --- a/requirements.txt +++ b/requirements.txt @@ -60,4 +60,4 @@ voluptuous-serialize==2.6.0 voluptuous-openapi==0.0.7 yarl==1.20.0 webrtc-models==0.3.0 -zeroconf==0.146.5 +zeroconf==0.147.0 diff --git a/requirements_all.txt b/requirements_all.txt index d52a573d7bd..42140c39fcc 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -3156,7 +3156,7 @@ zabbix-utils==2.0.2 zamg==0.3.6 # homeassistant.components.zeroconf -zeroconf==0.146.5 +zeroconf==0.147.0 # homeassistant.components.zeversolar zeversolar==0.3.2 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index 20e4f5af2d1..44d3f1d9143 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -2555,7 +2555,7 @@ yt-dlp[default]==2025.03.31 zamg==0.3.6 # homeassistant.components.zeroconf -zeroconf==0.146.5 +zeroconf==0.147.0 # homeassistant.components.zeversolar zeversolar==0.3.2 From b9aadb252f10a711675fff8928820f978f1e9582 Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Sat, 3 May 2025 17:21:22 -0400 Subject: [PATCH 38/90] Point thumbnail TTS media source to right logo (#144162) --- homeassistant/components/tts/media_source.py | 2 +- tests/components/tts/test_media_source.py | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/homeassistant/components/tts/media_source.py b/homeassistant/components/tts/media_source.py index d3c0998bb77..f096e082364 100644 --- a/homeassistant/components/tts/media_source.py +++ b/homeassistant/components/tts/media_source.py @@ -180,7 +180,7 @@ class TTSMediaSource(MediaSource): raise BrowseError("Unknown provider") if isinstance(engine_instance, TextToSpeechEntity): - engine_domain = engine_instance.platform.domain + engine_domain = engine_instance.platform.platform_name else: engine_domain = engine diff --git a/tests/components/tts/test_media_source.py b/tests/components/tts/test_media_source.py index c9d70c7f43e..eb4b09cab5b 100644 --- a/tests/components/tts/test_media_source.py +++ b/tests/components/tts/test_media_source.py @@ -78,6 +78,7 @@ async def test_browsing(hass: HomeAssistant, setup: str) -> None: assert item_child.children is None assert item_child.can_play is False assert item_child.can_expand is True + assert item_child.thumbnail == "https://brands.home-assistant.io/_/test/logo.png" item_child = await media_source.async_browse_media( hass, item.children[0].media_content_id + "?message=bla" From a6131b3ebf13d2eec262fc37dadeb3dc364a9a93 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sat, 3 May 2025 18:22:48 -0500 Subject: [PATCH 39/90] Bump habluetooth to 3.48.2 (#144157) --- homeassistant/components/bluetooth/manifest.json | 2 +- homeassistant/package_constraints.txt | 2 +- requirements_all.txt | 2 +- requirements_test_all.txt | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/homeassistant/components/bluetooth/manifest.json b/homeassistant/components/bluetooth/manifest.json index 5e74f7b5561..f9377443296 100644 --- a/homeassistant/components/bluetooth/manifest.json +++ b/homeassistant/components/bluetooth/manifest.json @@ -21,6 +21,6 @@ "bluetooth-auto-recovery==1.5.1", "bluetooth-data-tools==1.28.1", "dbus-fast==2.43.0", - "habluetooth==3.47.1" + "habluetooth==3.48.2" ] } diff --git a/homeassistant/package_constraints.txt b/homeassistant/package_constraints.txt index 6845f3fab9b..73415df8abd 100644 --- a/homeassistant/package_constraints.txt +++ b/homeassistant/package_constraints.txt @@ -34,7 +34,7 @@ dbus-fast==2.43.0 fnv-hash-fast==1.5.0 go2rtc-client==0.1.2 ha-ffmpeg==3.2.2 -habluetooth==3.47.1 +habluetooth==3.48.2 hass-nabucasa==0.96.0 hassil==2.2.3 home-assistant-bluetooth==1.13.1 diff --git a/requirements_all.txt b/requirements_all.txt index 42140c39fcc..be4709419ab 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -1118,7 +1118,7 @@ ha-silabs-firmware-client==0.2.0 habiticalib==0.3.7 # homeassistant.components.bluetooth -habluetooth==3.47.1 +habluetooth==3.48.2 # homeassistant.components.cloud hass-nabucasa==0.96.0 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index 44d3f1d9143..686aa81a4a5 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -960,7 +960,7 @@ ha-silabs-firmware-client==0.2.0 habiticalib==0.3.7 # homeassistant.components.bluetooth -habluetooth==3.47.1 +habluetooth==3.48.2 # homeassistant.components.cloud hass-nabucasa==0.96.0 From a15a3c12d57303a31531cceb2636c6aa6be11ad3 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sat, 3 May 2025 19:40:28 -0500 Subject: [PATCH 40/90] Pass requestor_uuid to bond API calls (#144128) --- homeassistant/components/bond/__init__.py | 3 ++- homeassistant/components/bond/config_flow.py | 14 +++++++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/homeassistant/components/bond/__init__.py b/homeassistant/components/bond/__init__.py index eb28bebdb06..00b8c8a0e13 100644 --- a/homeassistant/components/bond/__init__.py +++ b/homeassistant/components/bond/__init__.py @@ -5,7 +5,7 @@ import logging from typing import Any from aiohttp import ClientError, ClientResponseError, ClientTimeout -from bond_async import Bond, BPUPSubscriptions, start_bpup +from bond_async import Bond, BPUPSubscriptions, RequestorUUID, start_bpup from homeassistant.config_entries import ConfigEntry from homeassistant.const import ( @@ -49,6 +49,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: BondConfigEntry) -> bool token=token, timeout=ClientTimeout(total=_API_TIMEOUT), session=async_get_clientsession(hass), + requestor_uuid=RequestorUUID.HOME_ASSISTANT, ) hub = BondHub(bond, host) try: diff --git a/homeassistant/components/bond/config_flow.py b/homeassistant/components/bond/config_flow.py index ffa0098840c..9fcfbd342d8 100644 --- a/homeassistant/components/bond/config_flow.py +++ b/homeassistant/components/bond/config_flow.py @@ -8,7 +8,7 @@ import logging from typing import Any from aiohttp import ClientConnectionError, ClientResponseError -from bond_async import Bond +from bond_async import Bond, RequestorUUID import voluptuous as vol from homeassistant.config_entries import ConfigEntryState, ConfigFlow, ConfigFlowResult @@ -34,7 +34,12 @@ TOKEN_SCHEMA = vol.Schema({}) async def async_get_token(hass: HomeAssistant, host: str) -> str | None: """Try to fetch the token from the bond device.""" - bond = Bond(host, "", session=async_get_clientsession(hass)) + bond = Bond( + host, + "", + session=async_get_clientsession(hass), + requestor_uuid=RequestorUUID.HOME_ASSISTANT, + ) response: dict[str, str] = {} with contextlib.suppress(ClientConnectionError): response = await bond.token() @@ -45,7 +50,10 @@ async def _validate_input(hass: HomeAssistant, data: dict[str, Any]) -> tuple[st """Validate the user input allows us to connect.""" bond = Bond( - data[CONF_HOST], data[CONF_ACCESS_TOKEN], session=async_get_clientsession(hass) + data[CONF_HOST], + data[CONF_ACCESS_TOKEN], + session=async_get_clientsession(hass), + requestor_uuid=RequestorUUID.HOME_ASSISTANT, ) try: hub = BondHub(bond, data[CONF_HOST]) From 2a5c0d9b88c1a89597048ebe02e0c7c2999e8f1c Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sat, 3 May 2025 20:50:17 -0500 Subject: [PATCH 41/90] Add support for updating ESPHome deep sleep devices (#144161) Co-authored-by: Keith Burzinski --- homeassistant/components/esphome/strings.json | 5 +- homeassistant/components/esphome/update.py | 87 ++++-- tests/components/esphome/test_update.py | 294 ++++++++++++++++++ 3 files changed, 363 insertions(+), 23 deletions(-) diff --git a/homeassistant/components/esphome/strings.json b/homeassistant/components/esphome/strings.json index bc198d514ab..eab88e8df95 100644 --- a/homeassistant/components/esphome/strings.json +++ b/homeassistant/components/esphome/strings.json @@ -195,7 +195,10 @@ "message": "Error compiling {configuration}; Try again in ESPHome dashboard for more information." }, "error_uploading": { - "message": "Error during OTA of {configuration}; Try again in ESPHome dashboard for more information." + "message": "Error during OTA (Over-The-Air) of {configuration}; Try again in ESPHome dashboard for more information." + }, + "ota_in_progress": { + "message": "An OTA (Over-The-Air) update is already in progress for {configuration}." } } } diff --git a/homeassistant/components/esphome/update.py b/homeassistant/components/esphome/update.py index 01ac638bdb1..d24d8919461 100644 --- a/homeassistant/components/esphome/update.py +++ b/homeassistant/components/esphome/update.py @@ -125,21 +125,17 @@ class ESPHomeDashboardUpdateEntity( (dr.CONNECTION_NETWORK_MAC, entry_data.device_info.mac_address) } ) + self._install_lock = asyncio.Lock() + self._available_future: asyncio.Future[None] | None = None self._update_attrs() @callback def _update_attrs(self) -> None: """Update the supported features.""" - # If the device has deep sleep, we can't assume we can install updates - # as the ESP will not be connectable (by design). coordinator = self.coordinator device_info = self._device_info # Install support can change at run time - if ( - coordinator.last_update_success - and coordinator.supports_update - and not device_info.has_deep_sleep - ): + if coordinator.last_update_success and coordinator.supports_update: self._attr_supported_features = UpdateEntityFeature.INSTALL else: self._attr_supported_features = NO_FEATURES @@ -178,6 +174,13 @@ class ESPHomeDashboardUpdateEntity( self, static_info: list[EntityInfo] | None = None ) -> None: """Handle updated data from the device.""" + if ( + self._entry_data.available + and self._available_future + and not self._available_future.done() + ): + self._available_future.set_result(None) + self._available_future = None self._update_attrs() self.async_write_ha_state() @@ -192,17 +195,46 @@ class ESPHomeDashboardUpdateEntity( entry_data.async_subscribe_device_updated(self._handle_device_update) ) + async def async_will_remove_from_hass(self) -> None: + """Handle entity about to be removed from Home Assistant.""" + if self._available_future and not self._available_future.done(): + self._available_future.cancel() + self._available_future = None + + async def _async_wait_available(self) -> None: + """Wait until the device is available.""" + # If the device has deep sleep, we need to wait for it to wake up + # and connect to the network to be able to install the update. + if self._entry_data.available: + return + self._available_future = self.hass.loop.create_future() + try: + await self._available_future + finally: + self._available_future = None + async def async_install( self, version: str | None, backup: bool, **kwargs: Any ) -> None: """Install an update.""" - async with self.hass.data.setdefault(KEY_UPDATE_LOCK, asyncio.Lock()): - coordinator = self.coordinator - api = coordinator.api - device = coordinator.data.get(self._device_info.name) - assert device is not None - configuration = device["configuration"] - try: + if self._install_lock.locked(): + raise HomeAssistantError( + translation_domain=DOMAIN, + translation_key="ota_in_progress", + translation_placeholders={ + "configuration": self._device_info.name, + }, + ) + + # Ensure only one OTA per device at a time + async with self._install_lock: + # Ensure only one compile at a time for ALL devices + async with self.hass.data.setdefault(KEY_UPDATE_LOCK, asyncio.Lock()): + coordinator = self.coordinator + api = coordinator.api + device = coordinator.data.get(self._device_info.name) + assert device is not None + configuration = device["configuration"] if not await api.compile(configuration): raise HomeAssistantError( translation_domain=DOMAIN, @@ -211,14 +243,25 @@ class ESPHomeDashboardUpdateEntity( "configuration": configuration, }, ) - if not await api.upload(configuration, "OTA"): - raise HomeAssistantError( - translation_domain=DOMAIN, - translation_key="error_uploading", - translation_placeholders={ - "configuration": configuration, - }, - ) + + # If the device uses deep sleep, there's a small chance it goes + # to sleep right after the dashboard connects but before the OTA + # starts. In that case, the update won't go through, so we try + # again to catch it on its next wakeup. + attempts = 2 if self._device_info.has_deep_sleep else 1 + try: + for attempt in range(1, attempts + 1): + await self._async_wait_available() + if await api.upload(configuration, "OTA"): + break + if attempt == attempts: + raise HomeAssistantError( + translation_domain=DOMAIN, + translation_key="error_uploading", + translation_placeholders={ + "configuration": configuration, + }, + ) finally: await self.coordinator.async_request_refresh() diff --git a/tests/components/esphome/test_update.py b/tests/components/esphome/test_update.py index c9b88d9fb57..63294a6ad69 100644 --- a/tests/components/esphome/test_update.py +++ b/tests/components/esphome/test_update.py @@ -1,5 +1,6 @@ """Test ESPHome update entities.""" +import asyncio from typing import Any from unittest.mock import patch @@ -546,3 +547,296 @@ async def test_generic_device_update_entity_has_update( ) mock_client.update_command.assert_called_with(key=1, command=UpdateCommand.CHECK) + + +async def test_attempt_to_update_twice( + hass: HomeAssistant, + mock_client: APIClient, + mock_esphome_device: MockESPHomeDeviceType, + mock_dashboard: dict[str, Any], +) -> None: + """Test attempting to update twice.""" + mock_dashboard["configured"] = [ + { + "name": "test", + "current_version": "2023.2.0-dev", + "configuration": "test.yaml", + } + ] + await async_get_dashboard(hass).async_refresh() + await mock_esphome_device( + mock_client=mock_client, + entity_info=[], + user_service=[], + states=[], + ) + await hass.async_block_till_done() + state = hass.states.get("update.test_firmware") + assert state is not None + + async def delayed_compile(*args: Any, **kwargs: Any) -> None: + """Delay the update.""" + await asyncio.sleep(0) + return True + + # Compile success, upload fails + with ( + patch( + "homeassistant.components.esphome.coordinator.ESPHomeDashboardAPI.compile", + delayed_compile, + ), + patch( + "homeassistant.components.esphome.coordinator.ESPHomeDashboardAPI.upload", + return_value=False, + ), + ): + update_task = hass.async_create_task( + hass.services.async_call( + UPDATE_DOMAIN, + SERVICE_INSTALL, + {ATTR_ENTITY_ID: "update.test_firmware"}, + blocking=True, + ) + ) + + with pytest.raises(HomeAssistantError, match="update is already in progress"): + await hass.services.async_call( + UPDATE_DOMAIN, + SERVICE_INSTALL, + {ATTR_ENTITY_ID: "update.test_firmware"}, + blocking=True, + ) + + with pytest.raises(HomeAssistantError, match="OTA"): + await update_task + + +async def test_update_deep_sleep_already_online( + hass: HomeAssistant, + mock_client: APIClient, + mock_esphome_device: MockESPHomeDeviceType, + mock_dashboard: dict[str, Any], +) -> None: + """Test attempting to update twice.""" + mock_dashboard["configured"] = [ + { + "name": "test", + "current_version": "2023.2.0-dev", + "configuration": "test.yaml", + } + ] + await async_get_dashboard(hass).async_refresh() + await mock_esphome_device( + mock_client=mock_client, + entity_info=[], + user_service=[], + states=[], + device_info={"has_deep_sleep": True}, + ) + await hass.async_block_till_done() + state = hass.states.get("update.test_firmware") + assert state is not None + + # Compile success, upload success + with ( + patch( + "homeassistant.components.esphome.coordinator.ESPHomeDashboardAPI.compile", + return_value=True, + ), + patch( + "homeassistant.components.esphome.coordinator.ESPHomeDashboardAPI.upload", + return_value=True, + ), + ): + await hass.services.async_call( + UPDATE_DOMAIN, + SERVICE_INSTALL, + {ATTR_ENTITY_ID: "update.test_firmware"}, + blocking=True, + ) + + +async def test_update_deep_sleep_offline( + hass: HomeAssistant, + mock_client: APIClient, + mock_esphome_device: MockESPHomeDeviceType, + mock_dashboard: dict[str, Any], +) -> None: + """Test device comes online while updating.""" + mock_dashboard["configured"] = [ + { + "name": "test", + "current_version": "2023.2.0-dev", + "configuration": "test.yaml", + } + ] + await async_get_dashboard(hass).async_refresh() + device = await mock_esphome_device( + mock_client=mock_client, + entity_info=[], + user_service=[], + states=[], + device_info={"has_deep_sleep": True}, + ) + await hass.async_block_till_done() + state = hass.states.get("update.test_firmware") + assert state is not None + await device.mock_disconnect(True) + + # Compile success, upload success + with ( + patch( + "homeassistant.components.esphome.coordinator.ESPHomeDashboardAPI.compile", + return_value=True, + ), + patch( + "homeassistant.components.esphome.coordinator.ESPHomeDashboardAPI.upload", + return_value=True, + ), + ): + update_task = hass.async_create_task( + hass.services.async_call( + UPDATE_DOMAIN, + SERVICE_INSTALL, + {ATTR_ENTITY_ID: "update.test_firmware"}, + blocking=True, + ) + ) + await asyncio.sleep(0) + assert not update_task.done() + await device.mock_connect() + await hass.async_block_till_done() + + +async def test_update_deep_sleep_offline_sleep_during_ota( + hass: HomeAssistant, + mock_client: APIClient, + mock_esphome_device: MockESPHomeDeviceType, + mock_dashboard: dict[str, Any], +) -> None: + """Test device goes to sleep right as we start the OTA.""" + mock_dashboard["configured"] = [ + { + "name": "test", + "current_version": "2023.2.0-dev", + "configuration": "test.yaml", + } + ] + await async_get_dashboard(hass).async_refresh() + device = await mock_esphome_device( + mock_client=mock_client, + entity_info=[], + user_service=[], + states=[], + device_info={"has_deep_sleep": True}, + ) + await hass.async_block_till_done() + state = hass.states.get("update.test_firmware") + assert state is not None + await device.mock_disconnect(True) + + upload_attempt = 0 + upload_attempt_2_future = hass.loop.create_future() + disconnect_future = hass.loop.create_future() + + async def upload_takes_a_while(*args: Any, **kwargs: Any) -> None: + """Delay the update.""" + nonlocal upload_attempt + upload_attempt += 1 + if upload_attempt == 1: + # We are simulating the device going back to sleep + # before the upload can be started + # Wait for the device to go unavailable + # before returning false + await disconnect_future + return False + upload_attempt_2_future.set_result(None) + return True + + # Compile success, upload fails first time, success second time + with ( + patch( + "homeassistant.components.esphome.coordinator.ESPHomeDashboardAPI.compile", + return_value=True, + ), + patch( + "homeassistant.components.esphome.coordinator.ESPHomeDashboardAPI.upload", + upload_takes_a_while, + ), + ): + update_task = hass.async_create_task( + hass.services.async_call( + UPDATE_DOMAIN, + SERVICE_INSTALL, + {ATTR_ENTITY_ID: "update.test_firmware"}, + blocking=True, + ) + ) + await asyncio.sleep(0) + assert not update_task.done() + await device.mock_connect() + # Mock device being at the end of its sleep cycle + # and going to sleep right as the upload starts + # This can happen because there is non zero time + # between when we tell the dashboard to upload and + # when the upload actually starts + await device.mock_disconnect(True) + disconnect_future.set_result(None) + assert not upload_attempt_2_future.done() + # Now the device wakes up and the upload is attempted + await device.mock_connect() + await upload_attempt_2_future + await hass.async_block_till_done() + + +async def test_update_deep_sleep_offline_cancelled_unload( + hass: HomeAssistant, + mock_client: APIClient, + mock_esphome_device: MockESPHomeDeviceType, + mock_dashboard: dict[str, Any], +) -> None: + """Test deep sleep update attempt is cancelled on unload.""" + mock_dashboard["configured"] = [ + { + "name": "test", + "current_version": "2023.2.0-dev", + "configuration": "test.yaml", + } + ] + await async_get_dashboard(hass).async_refresh() + device = await mock_esphome_device( + mock_client=mock_client, + entity_info=[], + user_service=[], + states=[], + device_info={"has_deep_sleep": True}, + ) + await hass.async_block_till_done() + state = hass.states.get("update.test_firmware") + assert state is not None + await device.mock_disconnect(True) + + # Compile success, upload success, but we cancel the update + with ( + patch( + "homeassistant.components.esphome.coordinator.ESPHomeDashboardAPI.compile", + return_value=True, + ), + patch( + "homeassistant.components.esphome.coordinator.ESPHomeDashboardAPI.upload", + return_value=True, + ), + ): + update_task = hass.async_create_task( + hass.services.async_call( + UPDATE_DOMAIN, + SERVICE_INSTALL, + {ATTR_ENTITY_ID: "update.test_firmware"}, + blocking=True, + ) + ) + await asyncio.sleep(0) + assert not update_task.done() + await hass.config_entries.async_unload(device.entry.entry_id) + await hass.async_block_till_done() + assert update_task.cancelled() From 516a3c0504ddc97974267137534989a55de69718 Mon Sep 17 00:00:00 2001 From: Marc Mueller <30130371+cdce8p@users.noreply.github.com> Date: Sun, 4 May 2025 10:02:11 +0200 Subject: [PATCH 42/90] Fix licenses check for setuptools (#144181) --- script/licenses.py | 1 - 1 file changed, 1 deletion(-) diff --git a/script/licenses.py b/script/licenses.py index aed3bec9998..f801603738a 100644 --- a/script/licenses.py +++ b/script/licenses.py @@ -208,7 +208,6 @@ EXCEPTIONS = { # https://github.com/jaraco/skeleton/pull/170 # https://github.com/jaraco/skeleton/pull/171 "jaraco.itertools", # MIT - https://github.com/jaraco/jaraco.itertools/issues/21 - "setuptools", # MIT } TODO = { From d1615f9a6ed77668f5f7cff9874aa8d2370edffa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=85ke=20Strandberg?= Date: Sun, 4 May 2025 11:30:37 +0200 Subject: [PATCH 43/90] Bump pymiele to 0.4.3 (#144176) * Use device class transation * Bump pymiele to 0.4.3 --------- Co-authored-by: Shay Levy --- homeassistant/components/miele/manifest.json | 2 +- requirements_all.txt | 2 +- requirements_test_all.txt | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/miele/manifest.json b/homeassistant/components/miele/manifest.json index dc9b420e07e..c0795922875 100644 --- a/homeassistant/components/miele/manifest.json +++ b/homeassistant/components/miele/manifest.json @@ -8,7 +8,7 @@ "iot_class": "cloud_push", "loggers": ["pymiele"], "quality_scale": "bronze", - "requirements": ["pymiele==0.4.1"], + "requirements": ["pymiele==0.4.3"], "single_config_entry": true, "zeroconf": ["_mieleathome._tcp.local."] } diff --git a/requirements_all.txt b/requirements_all.txt index be4709419ab..80467891b8d 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -2135,7 +2135,7 @@ pymeteoclimatic==0.1.0 pymicro-vad==1.0.1 # homeassistant.components.miele -pymiele==0.4.1 +pymiele==0.4.3 # homeassistant.components.xiaomi_tv pymitv==1.4.3 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index 686aa81a4a5..6650853d379 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -1747,7 +1747,7 @@ pymeteoclimatic==0.1.0 pymicro-vad==1.0.1 # homeassistant.components.miele -pymiele==0.4.1 +pymiele==0.4.3 # homeassistant.components.mochad pymochad==0.2.0 From b5d499dda88634a3498fd42522a78da6eb58a36e Mon Sep 17 00:00:00 2001 From: Norbert Rittel Date: Sun, 4 May 2025 12:06:46 +0200 Subject: [PATCH 44/90] Fix spelling of "comma-separated (list)" in `fritzbox_callmonitor` (#144191) Also fix one missing sentence-casing in corresponding "title" string. --- homeassistant/components/fritzbox_callmonitor/strings.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/fritzbox_callmonitor/strings.json b/homeassistant/components/fritzbox_callmonitor/strings.json index 437b218a8e2..35af748ebe7 100644 --- a/homeassistant/components/fritzbox_callmonitor/strings.json +++ b/homeassistant/components/fritzbox_callmonitor/strings.json @@ -39,9 +39,9 @@ "options": { "step": { "init": { - "title": "Configure Prefixes", + "title": "Configure prefixes", "data": { - "prefixes": "Prefixes (comma separated list)" + "prefixes": "Prefixes (comma-separated list)" } } }, From 1e0d1c46ab40b8f74520b96dcebaa70eb05ff319 Mon Sep 17 00:00:00 2001 From: hahn-th <15319212+hahn-th@users.noreply.github.com> Date: Sun, 4 May 2025 12:07:18 +0200 Subject: [PATCH 45/90] Bump homematicip to 2.0.1.1 (#144182) Co-authored-by: Shay Levy --- homeassistant/components/homematicip_cloud/hap.py | 2 +- homeassistant/components/homematicip_cloud/manifest.json | 2 +- requirements_all.txt | 2 +- requirements_test_all.txt | 2 +- tests/components/homematicip_cloud/test_hap.py | 2 +- tests/components/homematicip_cloud/test_init.py | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/homeassistant/components/homematicip_cloud/hap.py b/homeassistant/components/homematicip_cloud/hap.py index d55b98b8c18..6f98836a1ff 100644 --- a/homeassistant/components/homematicip_cloud/hap.py +++ b/homeassistant/components/homematicip_cloud/hap.py @@ -9,10 +9,10 @@ from typing import Any from homematicip.async_home import AsyncHome from homematicip.auth import Auth -from homematicip.base.base_connection import HmipConnectionError from homematicip.base.enums import EventType from homematicip.connection.connection_context import ConnectionContextBuilder from homematicip.connection.rest_connection import RestConnection +from homematicip.exceptions.connection_exceptions import HmipConnectionError import homeassistant from homeassistant.config_entries import ConfigEntry diff --git a/homeassistant/components/homematicip_cloud/manifest.json b/homeassistant/components/homematicip_cloud/manifest.json index afd5863891d..15bc24c110f 100644 --- a/homeassistant/components/homematicip_cloud/manifest.json +++ b/homeassistant/components/homematicip_cloud/manifest.json @@ -6,5 +6,5 @@ "documentation": "https://www.home-assistant.io/integrations/homematicip_cloud", "iot_class": "cloud_push", "loggers": ["homematicip"], - "requirements": ["homematicip==2.0.1"] + "requirements": ["homematicip==2.0.1.1"] } diff --git a/requirements_all.txt b/requirements_all.txt index 80467891b8d..9d116efa284 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -1167,7 +1167,7 @@ home-assistant-frontend==20250502.0 home-assistant-intents==2025.4.30 # homeassistant.components.homematicip_cloud -homematicip==2.0.1 +homematicip==2.0.1.1 # homeassistant.components.horizon horimote==0.4.1 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index 6650853d379..b14067bfd17 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -997,7 +997,7 @@ home-assistant-frontend==20250502.0 home-assistant-intents==2025.4.30 # homeassistant.components.homematicip_cloud -homematicip==2.0.1 +homematicip==2.0.1.1 # homeassistant.components.remember_the_milk httplib2==0.20.4 diff --git a/tests/components/homematicip_cloud/test_hap.py b/tests/components/homematicip_cloud/test_hap.py index 1732459149c..e34424d3439 100644 --- a/tests/components/homematicip_cloud/test_hap.py +++ b/tests/components/homematicip_cloud/test_hap.py @@ -3,8 +3,8 @@ from unittest.mock import Mock, patch from homematicip.auth import Auth -from homematicip.base.base_connection import HmipConnectionError from homematicip.connection.connection_context import ConnectionContext +from homematicip.exceptions.connection_exceptions import HmipConnectionError import pytest from homeassistant.components.homematicip_cloud import DOMAIN as HMIPC_DOMAIN diff --git a/tests/components/homematicip_cloud/test_init.py b/tests/components/homematicip_cloud/test_init.py index a3578baa9aa..f28b3870705 100644 --- a/tests/components/homematicip_cloud/test_init.py +++ b/tests/components/homematicip_cloud/test_init.py @@ -2,8 +2,8 @@ from unittest.mock import AsyncMock, Mock, patch -from homematicip.base.base_connection import HmipConnectionError from homematicip.connection.connection_context import ConnectionContext +from homematicip.exceptions.connection_exceptions import HmipConnectionError from homeassistant.components.homematicip_cloud.const import ( CONF_ACCESSPOINT, From b9e11b0f458eca575d2d9b87cee36271e1ae0a1c Mon Sep 17 00:00:00 2001 From: Norbert Rittel Date: Sun, 4 May 2025 12:07:30 +0200 Subject: [PATCH 46/90] Fix spelling of "comma-separated" and "IP address" in `cast` (#144188) --- homeassistant/components/cast/strings.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/cast/strings.json b/homeassistant/components/cast/strings.json index 8c7c7c0cff0..aa52d21e05f 100644 --- a/homeassistant/components/cast/strings.json +++ b/homeassistant/components/cast/strings.json @@ -10,12 +10,12 @@ "known_hosts": "Add known host" }, "data_description": { - "known_hosts": "Hostnames or IP-addresses of cast devices, use if mDNS discovery is not working" + "known_hosts": "Hostnames or IP addresses of cast devices, use if mDNS discovery is not working" } } }, "error": { - "invalid_known_hosts": "Known hosts must be a comma separated list of hosts." + "invalid_known_hosts": "Known hosts must be a comma-separated list of hosts." } }, "options": { From 04982f5e122374462f4010cbfd90a0bbf43b3a3b Mon Sep 17 00:00:00 2001 From: Maciej Bieniek Date: Sun, 4 May 2025 12:08:07 +0200 Subject: [PATCH 47/90] Add missing pollen category to AccuWeather (#144185) * Add extreme level to pollen map * Sort * Sort --- homeassistant/components/accuweather/const.py | 1 + homeassistant/components/accuweather/strings.json | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/homeassistant/components/accuweather/const.py b/homeassistant/components/accuweather/const.py index 7216f5a0b9b..e1dc4a9abcb 100644 --- a/homeassistant/components/accuweather/const.py +++ b/homeassistant/components/accuweather/const.py @@ -67,6 +67,7 @@ POLLEN_CATEGORY_MAP = { 2: "moderate", 3: "high", 4: "very_high", + 5: "extreme", } UPDATE_INTERVAL_OBSERVATION = timedelta(minutes=40) UPDATE_INTERVAL_DAILY_FORECAST = timedelta(hours=6) diff --git a/homeassistant/components/accuweather/strings.json b/homeassistant/components/accuweather/strings.json index e81ef782d98..19e52be1ce3 100644 --- a/homeassistant/components/accuweather/strings.json +++ b/homeassistant/components/accuweather/strings.json @@ -72,6 +72,7 @@ "level": { "name": "Level", "state": { + "extreme": "Extreme", "high": "[%key:common::state::high%]", "low": "[%key:common::state::low%]", "moderate": "Moderate", @@ -89,6 +90,7 @@ "level": { "name": "[%key:component::accuweather::entity::sensor::grass_pollen::state_attributes::level::name%]", "state": { + "extreme": "[%key:component::accuweather::entity::sensor::grass_pollen::state_attributes::level::state::extreme%]", "high": "[%key:common::state::high%]", "low": "[%key:common::state::low%]", "moderate": "[%key:component::accuweather::entity::sensor::grass_pollen::state_attributes::level::state::moderate%]", @@ -123,6 +125,7 @@ "level": { "name": "[%key:component::accuweather::entity::sensor::grass_pollen::state_attributes::level::name%]", "state": { + "extreme": "[%key:component::accuweather::entity::sensor::grass_pollen::state_attributes::level::state::extreme%]", "high": "[%key:common::state::high%]", "low": "[%key:common::state::low%]", "moderate": "[%key:component::accuweather::entity::sensor::grass_pollen::state_attributes::level::state::moderate%]", @@ -167,6 +170,7 @@ "level": { "name": "[%key:component::accuweather::entity::sensor::grass_pollen::state_attributes::level::name%]", "state": { + "extreme": "[%key:component::accuweather::entity::sensor::grass_pollen::state_attributes::level::state::extreme%]", "high": "[%key:common::state::high%]", "low": "[%key:common::state::low%]", "moderate": "[%key:component::accuweather::entity::sensor::grass_pollen::state_attributes::level::state::moderate%]", @@ -181,6 +185,7 @@ "level": { "name": "[%key:component::accuweather::entity::sensor::grass_pollen::state_attributes::level::name%]", "state": { + "extreme": "[%key:component::accuweather::entity::sensor::grass_pollen::state_attributes::level::state::extreme%]", "high": "[%key:common::state::high%]", "low": "[%key:common::state::low%]", "moderate": "[%key:component::accuweather::entity::sensor::grass_pollen::state_attributes::level::state::moderate%]", @@ -195,6 +200,7 @@ "level": { "name": "[%key:component::accuweather::entity::sensor::grass_pollen::state_attributes::level::name%]", "state": { + "extreme": "[%key:component::accuweather::entity::sensor::grass_pollen::state_attributes::level::state::extreme%]", "high": "[%key:common::state::high%]", "low": "[%key:common::state::low%]", "moderate": "[%key:component::accuweather::entity::sensor::grass_pollen::state_attributes::level::state::moderate%]", From 2aa82da615beeffbf24fb623d6a928c9fe5df91e Mon Sep 17 00:00:00 2001 From: Norbert Rittel Date: Sun, 4 May 2025 12:09:09 +0200 Subject: [PATCH 48/90] Fix spelling of "comma-separated (list)" in `huawei_lte` (#144189) --- homeassistant/components/huawei_lte/strings.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/homeassistant/components/huawei_lte/strings.json b/homeassistant/components/huawei_lte/strings.json index 50879c9e166..2845338b9cf 100644 --- a/homeassistant/components/huawei_lte/strings.json +++ b/homeassistant/components/huawei_lte/strings.json @@ -61,7 +61,7 @@ }, "data_description": { "name": "Used to distinguish between notification services in case there are multiple Huawei LTE devices configured. Changes to this option value take effect after Home Assistant restart.", - "recipient": "Comma separated list of default recipient SMS phone numbers for the notification service, used in case the notification sender does not specify any.", + "recipient": "Comma-separated list of default recipient SMS phone numbers for the notification service, used in case the notification sender does not specify any.", "track_wired_clients": "Whether the device tracker entities track also clients attached to the router's wired Ethernet network, in addition to wireless clients.", "unauthenticated_mode": "Whether to run in unauthenticated mode. Unauthenticated mode provides a limited set of features, but may help in case there are problems accessing the router's web interface from a browser while the integration is active. Changes to this option value take effect after integration reload." } From cb37d4d36a351dfb7644554f2e8e74d7cd3186f1 Mon Sep 17 00:00:00 2001 From: Norbert Rittel Date: Sun, 4 May 2025 12:09:31 +0200 Subject: [PATCH 49/90] Fix spelling of "comma-separated (list / event name)" in `doorbird` (#144190) --- homeassistant/components/doorbird/strings.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/doorbird/strings.json b/homeassistant/components/doorbird/strings.json index ad43e8c1c1c..285b544e465 100644 --- a/homeassistant/components/doorbird/strings.json +++ b/homeassistant/components/doorbird/strings.json @@ -3,10 +3,10 @@ "step": { "init": { "data": { - "events": "Comma separated list of events." + "events": "Comma-separated list of events." }, "data_description": { - "events": "Add a comma separated event name for each event you wish to track. After entering them here, use the DoorBird app to assign them to a specific event.\n\nExample: somebody_pressed_the_button, motion" + "events": "Add a comma-separated event name for each event you wish to track. After entering them here, use the DoorBird app to assign them to a specific event.\n\nExample: somebody_pressed_the_button, motion" } } } From de496c693e5d7c547fd4b14c571ba65e5ceae98d Mon Sep 17 00:00:00 2001 From: Brett Adams Date: Sun, 4 May 2025 21:36:13 +1000 Subject: [PATCH 50/90] Add hazard lights binary sensor to Teslemetry (#144166) --- .../components/teslemetry/binary_sensor.py | 6 ++ .../components/teslemetry/icons.json | 6 ++ .../components/teslemetry/strings.json | 3 + .../snapshots/test_binary_sensor.ambr | 60 +++++++++++++++++++ 4 files changed, 75 insertions(+) diff --git a/homeassistant/components/teslemetry/binary_sensor.py b/homeassistant/components/teslemetry/binary_sensor.py index a62dbe1e00f..7dca1667b29 100644 --- a/homeassistant/components/teslemetry/binary_sensor.py +++ b/homeassistant/components/teslemetry/binary_sensor.py @@ -391,6 +391,12 @@ VEHICLE_DESCRIPTIONS: tuple[TeslemetryBinarySensorEntityDescription, ...] = ( entity_registry_enabled_default=False, streaming_firmware="2024.44.25", ), + TeslemetryBinarySensorEntityDescription( + key="lights_hazards_active", + streaming_listener=lambda x, y: x.listen_LightsHazardsActive(y), + entity_registry_enabled_default=False, + streaming_firmware="2025.2.6", + ), TeslemetryBinarySensorEntityDescription( key="lights_high_beams", streaming_listener=lambda x, y: x.listen_LightsHighBeams(y), diff --git a/homeassistant/components/teslemetry/icons.json b/homeassistant/components/teslemetry/icons.json index 06ac1595a80..5bc3f52b9b7 100644 --- a/homeassistant/components/teslemetry/icons.json +++ b/homeassistant/components/teslemetry/icons.json @@ -73,6 +73,12 @@ "on": "mdi:snowflake-melt" } }, + "lights_hazards_active": { + "state": { + "off": "mdi:car-light-dimmed", + "on": "mdi:hazard-lights" + } + }, "lights_high_beams": { "state": { "off": "mdi:car-light-dimmed", diff --git a/homeassistant/components/teslemetry/strings.json b/homeassistant/components/teslemetry/strings.json index 54568c971c4..456850fde3e 100644 --- a/homeassistant/components/teslemetry/strings.json +++ b/homeassistant/components/teslemetry/strings.json @@ -203,6 +203,9 @@ "defrost_for_preconditioning": { "name": "Defrost for preconditioning" }, + "lights_hazards_active": { + "name": "Hazard lights" + }, "lights_high_beams": { "name": "High beams" }, diff --git a/tests/components/teslemetry/snapshots/test_binary_sensor.ambr b/tests/components/teslemetry/snapshots/test_binary_sensor.ambr index d957bdedcf4..0af85a6846d 100644 --- a/tests/components/teslemetry/snapshots/test_binary_sensor.ambr +++ b/tests/components/teslemetry/snapshots/test_binary_sensor.ambr @@ -1514,6 +1514,53 @@ 'state': 'unknown', }) # --- +# name: test_binary_sensor[binary_sensor.test_hazard_lights-entry] + EntityRegistryEntrySnapshot({ + 'aliases': set({ + }), + 'area_id': None, + 'capabilities': None, + 'config_entry_id': , + 'config_subentry_id': , + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'binary_sensor', + 'entity_category': None, + 'entity_id': 'binary_sensor.test_hazard_lights', + 'has_entity_name': True, + 'hidden_by': None, + 'icon': None, + 'id': , + 'labels': set({ + }), + 'name': None, + 'options': dict({ + }), + 'original_device_class': None, + 'original_icon': None, + 'original_name': 'Hazard lights', + 'platform': 'teslemetry', + 'previous_unique_id': None, + 'supported_features': 0, + 'translation_key': 'lights_hazards_active', + 'unique_id': 'LRW3F7EK4NC700000-lights_hazards_active', + 'unit_of_measurement': None, + }) +# --- +# name: test_binary_sensor[binary_sensor.test_hazard_lights-state] + StateSnapshot({ + 'attributes': ReadOnlyDict({ + 'friendly_name': 'Test Hazard lights', + }), + 'context': , + 'entity_id': 'binary_sensor.test_hazard_lights', + 'last_changed': , + 'last_reported': , + 'last_updated': , + 'state': 'unknown', + }) +# --- # name: test_binary_sensor[binary_sensor.test_high_beams-entry] EntityRegistryEntrySnapshot({ 'aliases': set({ @@ -3504,6 +3551,19 @@ 'state': 'unknown', }) # --- +# name: test_binary_sensor_refresh[binary_sensor.test_hazard_lights-statealt] + StateSnapshot({ + 'attributes': ReadOnlyDict({ + 'friendly_name': 'Test Hazard lights', + }), + 'context': , + 'entity_id': 'binary_sensor.test_hazard_lights', + 'last_changed': , + 'last_reported': , + 'last_updated': , + 'state': 'unknown', + }) +# --- # name: test_binary_sensor_refresh[binary_sensor.test_high_beams-statealt] StateSnapshot({ 'attributes': ReadOnlyDict({ From 8c6edd8b818c7cec2ded4a607df5f0141a70bc94 Mon Sep 17 00:00:00 2001 From: Brett Adams Date: Sun, 4 May 2025 21:41:45 +1000 Subject: [PATCH 51/90] Add better typing to Teslemetry switch platform (#144168) --- homeassistant/components/teslemetry/switch.py | 43 +++++++++++-------- 1 file changed, 25 insertions(+), 18 deletions(-) diff --git a/homeassistant/components/teslemetry/switch.py b/homeassistant/components/teslemetry/switch.py index 645a8398820..9d30c73220d 100644 --- a/homeassistant/components/teslemetry/switch.py +++ b/homeassistant/components/teslemetry/switch.py @@ -2,12 +2,13 @@ from __future__ import annotations -from collections.abc import Callable +from collections.abc import Awaitable, Callable from dataclasses import dataclass from itertools import chain from typing import Any from tesla_fleet_api.const import AutoSeat, Scope +from tesla_fleet_api.teslemetry.vehicles import TeslemetryVehicle from teslemetry_stream import TeslemetryStreamVehicle from homeassistant.components.switch import ( @@ -37,15 +38,14 @@ PARALLEL_UPDATES = 0 class TeslemetrySwitchEntityDescription(SwitchEntityDescription): """Describes Teslemetry Switch entity.""" - on_func: Callable - off_func: Callable + on_func: Callable[[TeslemetryVehicle], Awaitable[dict[str, Any]]] + off_func: Callable[[TeslemetryVehicle], Awaitable[dict[str, Any]]] scopes: list[Scope] value_func: Callable[[StateType], bool] = bool streaming_listener: Callable[ - [TeslemetryStreamVehicle, Callable[[StateType], None]], + [TeslemetryStreamVehicle, Callable[[bool | None], None]], Callable[[], None], ] - streaming_value_fn: Callable[[StateType], bool] = bool streaming_firmware: str = "2024.26" unique_id: str | None = None @@ -53,15 +53,18 @@ class TeslemetrySwitchEntityDescription(SwitchEntityDescription): VEHICLE_DESCRIPTIONS: tuple[TeslemetrySwitchEntityDescription, ...] = ( TeslemetrySwitchEntityDescription( key="vehicle_state_sentry_mode", - streaming_listener=lambda x, y: x.listen_SentryMode(y), - streaming_value_fn=lambda x: x != "Off", + streaming_listener=lambda vehicle, callback: vehicle.listen_SentryMode( + lambda value: callback(None if value is None else value != "Off") + ), on_func=lambda api: api.set_sentry_mode(on=True), off_func=lambda api: api.set_sentry_mode(on=False), scopes=[Scope.VEHICLE_CMDS], ), TeslemetrySwitchEntityDescription( key="climate_state_auto_seat_climate_left", - streaming_listener=lambda x, y: x.listen_AutoSeatClimateLeft(y), + streaming_listener=lambda vehicle, callback: vehicle.listen_AutoSeatClimateLeft( + callback + ), on_func=lambda api: api.remote_auto_seat_climate_request( AutoSeat.FRONT_LEFT, True ), @@ -72,7 +75,8 @@ VEHICLE_DESCRIPTIONS: tuple[TeslemetrySwitchEntityDescription, ...] = ( ), TeslemetrySwitchEntityDescription( key="climate_state_auto_seat_climate_right", - streaming_listener=lambda x, y: x.listen_AutoSeatClimateRight(y), + streaming_listener=lambda vehicle, + callback: vehicle.listen_AutoSeatClimateRight(callback), on_func=lambda api: api.remote_auto_seat_climate_request( AutoSeat.FRONT_RIGHT, True ), @@ -83,7 +87,8 @@ VEHICLE_DESCRIPTIONS: tuple[TeslemetrySwitchEntityDescription, ...] = ( ), TeslemetrySwitchEntityDescription( key="climate_state_auto_steering_wheel_heat", - streaming_listener=lambda x, y: x.listen_HvacSteeringWheelHeatAuto(y), + streaming_listener=lambda vehicle, + callback: vehicle.listen_HvacSteeringWheelHeatAuto(callback), on_func=lambda api: api.remote_auto_steering_wheel_heat_climate_request( on=True ), @@ -94,8 +99,9 @@ VEHICLE_DESCRIPTIONS: tuple[TeslemetrySwitchEntityDescription, ...] = ( ), TeslemetrySwitchEntityDescription( key="climate_state_defrost_mode", - streaming_listener=lambda x, y: x.listen_DefrostMode(y), - streaming_value_fn=lambda x: x != "Off", + streaming_listener=lambda vehicle, callback: vehicle.listen_DefrostMode( + lambda value: callback(None if value is None else value != "Off") + ), on_func=lambda api: api.set_preconditioning_max(on=True, manual_override=False), off_func=lambda api: api.set_preconditioning_max( on=False, manual_override=False @@ -106,8 +112,11 @@ VEHICLE_DESCRIPTIONS: tuple[TeslemetrySwitchEntityDescription, ...] = ( key="charge_state_charging_state", unique_id="charge_state_user_charge_enable_request", value_func=lambda state: state in {"Starting", "Charging"}, - streaming_listener=lambda x, y: x.listen_DetailedChargeState(y), - streaming_value_fn=lambda x: x in {"Starting", "Charging"}, + streaming_listener=lambda vehicle, callback: vehicle.listen_DetailedChargeState( + lambda value: callback( + None if value is None else value in {"Starting", "Charging"} + ) + ), on_func=lambda api: api.charge_start(), off_func=lambda api: api.charge_stop(), scopes=[Scope.VEHICLE_CMDS, Scope.VEHICLE_CHARGING_CMDS], @@ -239,11 +248,9 @@ class TeslemetryStreamingVehicleSwitchEntity( ) ) - def _value_callback(self, value: StateType) -> None: + def _value_callback(self, value: bool | None) -> None: """Update the value of the entity.""" - self._attr_is_on = ( - None if value is None else self.entity_description.streaming_value_fn(value) - ) + self._attr_is_on = value self.async_write_ha_state() From 5a475ec7ea2f5204ab1406eeb18df9e988c9b490 Mon Sep 17 00:00:00 2001 From: Brett Adams Date: Sun, 4 May 2025 21:42:25 +1000 Subject: [PATCH 52/90] Improve typing of binary sensors in Teslemetry (#144169) --- .../components/teslemetry/binary_sensor.py | 183 ++++++++++++------ 1 file changed, 126 insertions(+), 57 deletions(-) diff --git a/homeassistant/components/teslemetry/binary_sensor.py b/homeassistant/components/teslemetry/binary_sensor.py index 7dca1667b29..da5072e2535 100644 --- a/homeassistant/components/teslemetry/binary_sensor.py +++ b/homeassistant/components/teslemetry/binary_sensor.py @@ -58,26 +58,28 @@ VEHICLE_DESCRIPTIONS: tuple[TeslemetryBinarySensorEntityDescription, ...] = ( TeslemetryBinarySensorEntityDescription( key="state", polling=True, - polling_value_fn=lambda x: x == TeslemetryState.ONLINE, - streaming_listener=lambda x, y: x.listen_State(y), + polling_value_fn=lambda value: value == TeslemetryState.ONLINE, + streaming_listener=lambda vehicle, callback: vehicle.listen_State(callback), device_class=BinarySensorDeviceClass.CONNECTIVITY, ), TeslemetryBinarySensorEntityDescription( key="cellular", - streaming_listener=lambda x, y: x.listen_Cellular(y), + streaming_listener=lambda vehicle, callback: vehicle.listen_Cellular(callback), device_class=BinarySensorDeviceClass.CONNECTIVITY, entity_category=EntityCategory.DIAGNOSTIC, ), TeslemetryBinarySensorEntityDescription( key="wifi", - streaming_listener=lambda x, y: x.listen_Wifi(y), + streaming_listener=lambda vehicle, callback: vehicle.listen_Wifi(callback), device_class=BinarySensorDeviceClass.CONNECTIVITY, entity_category=EntityCategory.DIAGNOSTIC, ), TeslemetryBinarySensorEntityDescription( key="charge_state_battery_heater_on", polling=True, - streaming_listener=lambda x, y: x.listen_BatteryHeaterOn(y), + streaming_listener=lambda vehicle, callback: vehicle.listen_BatteryHeaterOn( + callback + ), device_class=BinarySensorDeviceClass.HEAT, entity_category=EntityCategory.DIAGNOSTIC, entity_registry_enabled_default=False, @@ -85,8 +87,8 @@ VEHICLE_DESCRIPTIONS: tuple[TeslemetryBinarySensorEntityDescription, ...] = ( TeslemetryBinarySensorEntityDescription( key="charge_state_charger_phases", polling=True, - streaming_listener=lambda x, y: x.listen_ChargerPhases( - lambda z: y(None if z is None else z > 1) + streaming_listener=lambda vehicle, callback: vehicle.listen_ChargerPhases( + lambda value: callback(None if value is None else value > 1) ), polling_value_fn=lambda x: cast(int, x) > 1, entity_registry_enabled_default=False, @@ -94,7 +96,8 @@ VEHICLE_DESCRIPTIONS: tuple[TeslemetryBinarySensorEntityDescription, ...] = ( TeslemetryBinarySensorEntityDescription( key="charge_state_preconditioning_enabled", polling=True, - streaming_listener=lambda x, y: x.listen_PreconditioningEnabled(y), + streaming_listener=lambda vehicle, + callback: vehicle.listen_PreconditioningEnabled(callback), entity_category=EntityCategory.DIAGNOSTIC, entity_registry_enabled_default=False, ), @@ -107,7 +110,8 @@ VEHICLE_DESCRIPTIONS: tuple[TeslemetryBinarySensorEntityDescription, ...] = ( TeslemetryBinarySensorEntityDescription( key="charge_state_scheduled_charging_pending", polling=True, - streaming_listener=lambda x, y: x.listen_ScheduledChargingPending(y), + streaming_listener=lambda vehicle, + callback: vehicle.listen_ScheduledChargingPending(callback), entity_category=EntityCategory.DIAGNOSTIC, entity_registry_enabled_default=False, ), @@ -175,8 +179,8 @@ VEHICLE_DESCRIPTIONS: tuple[TeslemetryBinarySensorEntityDescription, ...] = ( TeslemetryBinarySensorEntityDescription( key="vehicle_state_fd_window", polling=True, - streaming_listener=lambda x, y: x.listen_FrontDriverWindow( - lambda z: y(WINDOW_STATES.get(z)) + streaming_listener=lambda vehicle, callback: vehicle.listen_FrontDriverWindow( + lambda value: callback(None if value is None else WINDOW_STATES.get(value)) ), device_class=BinarySensorDeviceClass.WINDOW, entity_category=EntityCategory.DIAGNOSTIC, @@ -184,8 +188,9 @@ VEHICLE_DESCRIPTIONS: tuple[TeslemetryBinarySensorEntityDescription, ...] = ( TeslemetryBinarySensorEntityDescription( key="vehicle_state_fp_window", polling=True, - streaming_listener=lambda x, y: x.listen_FrontPassengerWindow( - lambda z: y(WINDOW_STATES.get(z)) + streaming_listener=lambda vehicle, + callback: vehicle.listen_FrontPassengerWindow( + lambda value: callback(None if value is None else WINDOW_STATES.get(value)) ), device_class=BinarySensorDeviceClass.WINDOW, entity_category=EntityCategory.DIAGNOSTIC, @@ -193,8 +198,8 @@ VEHICLE_DESCRIPTIONS: tuple[TeslemetryBinarySensorEntityDescription, ...] = ( TeslemetryBinarySensorEntityDescription( key="vehicle_state_rd_window", polling=True, - streaming_listener=lambda x, y: x.listen_RearDriverWindow( - lambda z: y(WINDOW_STATES.get(z)) + streaming_listener=lambda vehicle, callback: vehicle.listen_RearDriverWindow( + lambda value: callback(None if value is None else WINDOW_STATES.get(value)) ), device_class=BinarySensorDeviceClass.WINDOW, entity_category=EntityCategory.DIAGNOSTIC, @@ -202,8 +207,8 @@ VEHICLE_DESCRIPTIONS: tuple[TeslemetryBinarySensorEntityDescription, ...] = ( TeslemetryBinarySensorEntityDescription( key="vehicle_state_rp_window", polling=True, - streaming_listener=lambda x, y: x.listen_RearPassengerWindow( - lambda z: y(WINDOW_STATES.get(z)) + streaming_listener=lambda vehicle, callback: vehicle.listen_RearPassengerWindow( + lambda value: callback(None if value is None else WINDOW_STATES.get(value)) ), device_class=BinarySensorDeviceClass.WINDOW, entity_category=EntityCategory.DIAGNOSTIC, @@ -212,182 +217,234 @@ VEHICLE_DESCRIPTIONS: tuple[TeslemetryBinarySensorEntityDescription, ...] = ( key="vehicle_state_df", polling=True, device_class=BinarySensorDeviceClass.DOOR, - streaming_listener=lambda x, y: x.listen_FrontDriverDoor(y), + streaming_listener=lambda vehicle, callback: vehicle.listen_FrontDriverDoor( + callback + ), entity_category=EntityCategory.DIAGNOSTIC, ), TeslemetryBinarySensorEntityDescription( key="vehicle_state_dr", polling=True, device_class=BinarySensorDeviceClass.DOOR, - streaming_listener=lambda x, y: x.listen_RearDriverDoor(y), + streaming_listener=lambda vehicle, callback: vehicle.listen_RearDriverDoor( + callback + ), entity_category=EntityCategory.DIAGNOSTIC, ), TeslemetryBinarySensorEntityDescription( key="vehicle_state_pf", polling=True, device_class=BinarySensorDeviceClass.DOOR, - streaming_listener=lambda x, y: x.listen_FrontPassengerDoor(y), + streaming_listener=lambda vehicle, callback: vehicle.listen_FrontPassengerDoor( + callback + ), entity_category=EntityCategory.DIAGNOSTIC, ), TeslemetryBinarySensorEntityDescription( key="vehicle_state_pr", polling=True, device_class=BinarySensorDeviceClass.DOOR, - streaming_listener=lambda x, y: x.listen_RearPassengerDoor(y), + streaming_listener=lambda vehicle, callback: vehicle.listen_RearPassengerDoor( + callback + ), entity_category=EntityCategory.DIAGNOSTIC, ), TeslemetryBinarySensorEntityDescription( key="automatic_blind_spot_camera", - streaming_listener=lambda x, y: x.listen_AutomaticBlindSpotCamera(y), + streaming_listener=lambda vehicle, + callback: vehicle.listen_AutomaticBlindSpotCamera(callback), entity_registry_enabled_default=False, ), TeslemetryBinarySensorEntityDescription( key="automatic_emergency_braking_off", - streaming_listener=lambda x, y: x.listen_AutomaticEmergencyBrakingOff(y), + streaming_listener=lambda vehicle, + callback: vehicle.listen_AutomaticEmergencyBrakingOff(callback), entity_registry_enabled_default=False, ), TeslemetryBinarySensorEntityDescription( key="blind_spot_collision_warning_chime", - streaming_listener=lambda x, y: x.listen_BlindSpotCollisionWarningChime(y), + streaming_listener=lambda vehicle, + callback: vehicle.listen_BlindSpotCollisionWarningChime(callback), entity_registry_enabled_default=False, ), TeslemetryBinarySensorEntityDescription( key="bms_full_charge_complete", - streaming_listener=lambda x, y: x.listen_BmsFullchargecomplete(y), + streaming_listener=lambda vehicle, + callback: vehicle.listen_BmsFullchargecomplete(callback), entity_registry_enabled_default=False, ), TeslemetryBinarySensorEntityDescription( key="brake_pedal", - streaming_listener=lambda x, y: x.listen_BrakePedal(y), + streaming_listener=lambda vehicle, callback: vehicle.listen_BrakePedal( + callback + ), entity_registry_enabled_default=False, ), TeslemetryBinarySensorEntityDescription( key="charge_port_cold_weather_mode", - streaming_listener=lambda x, y: x.listen_ChargePortColdWeatherMode(y), + streaming_listener=lambda vehicle, + callback: vehicle.listen_ChargePortColdWeatherMode(callback), entity_registry_enabled_default=False, ), TeslemetryBinarySensorEntityDescription( key="service_mode", - streaming_listener=lambda x, y: x.listen_ServiceMode(y), + streaming_listener=lambda vehicle, callback: vehicle.listen_ServiceMode( + callback + ), entity_registry_enabled_default=False, ), TeslemetryBinarySensorEntityDescription( key="pin_to_drive_enabled", - streaming_listener=lambda x, y: x.listen_PinToDriveEnabled(y), + streaming_listener=lambda vehicle, callback: vehicle.listen_PinToDriveEnabled( + callback + ), entity_registry_enabled_default=False, ), TeslemetryBinarySensorEntityDescription( key="drive_rail", - streaming_listener=lambda x, y: x.listen_DriveRail(y), + streaming_listener=lambda vehicle, callback: vehicle.listen_DriveRail(callback), entity_registry_enabled_default=False, ), TeslemetryBinarySensorEntityDescription( key="driver_seat_belt", - streaming_listener=lambda x, y: x.listen_DriverSeatBelt(y), + streaming_listener=lambda vehicle, callback: vehicle.listen_DriverSeatBelt( + callback + ), entity_registry_enabled_default=False, ), TeslemetryBinarySensorEntityDescription( key="driver_seat_occupied", - streaming_listener=lambda x, y: x.listen_DriverSeatOccupied(y), + streaming_listener=lambda vehicle, callback: vehicle.listen_DriverSeatOccupied( + callback + ), entity_registry_enabled_default=False, ), TeslemetryBinarySensorEntityDescription( key="passenger_seat_belt", - streaming_listener=lambda x, y: x.listen_PassengerSeatBelt(y), + streaming_listener=lambda vehicle, callback: vehicle.listen_PassengerSeatBelt( + callback + ), entity_registry_enabled_default=False, ), TeslemetryBinarySensorEntityDescription( key="fast_charger_present", - streaming_listener=lambda x, y: x.listen_FastChargerPresent(y), + streaming_listener=lambda vehicle, callback: vehicle.listen_FastChargerPresent( + callback + ), entity_registry_enabled_default=False, ), TeslemetryBinarySensorEntityDescription( key="gps_state", - streaming_listener=lambda x, y: x.listen_GpsState(y), + streaming_listener=lambda vehicle, callback: vehicle.listen_GpsState(callback), entity_registry_enabled_default=False, entity_category=EntityCategory.DIAGNOSTIC, device_class=BinarySensorDeviceClass.CONNECTIVITY, ), TeslemetryBinarySensorEntityDescription( key="guest_mode_enabled", - streaming_listener=lambda x, y: x.listen_GuestModeEnabled(y), + streaming_listener=lambda vehicle, callback: vehicle.listen_GuestModeEnabled( + callback + ), entity_registry_enabled_default=False, ), TeslemetryBinarySensorEntityDescription( key="dc_dc_enable", - streaming_listener=lambda x, y: x.listen_DCDCEnable(y), + streaming_listener=lambda vehicle, callback: vehicle.listen_DCDCEnable( + callback + ), entity_registry_enabled_default=False, ), TeslemetryBinarySensorEntityDescription( key="emergency_lane_departure_avoidance", - streaming_listener=lambda x, y: x.listen_EmergencyLaneDepartureAvoidance(y), + streaming_listener=lambda vehicle, + callback: vehicle.listen_EmergencyLaneDepartureAvoidance(callback), entity_registry_enabled_default=False, ), TeslemetryBinarySensorEntityDescription( key="supercharger_session_trip_planner", - streaming_listener=lambda x, y: x.listen_SuperchargerSessionTripPlanner(y), + streaming_listener=lambda vehicle, + callback: vehicle.listen_SuperchargerSessionTripPlanner(callback), entity_registry_enabled_default=False, ), TeslemetryBinarySensorEntityDescription( key="wiper_heat_enabled", - streaming_listener=lambda x, y: x.listen_WiperHeatEnabled(y), + streaming_listener=lambda vehicle, callback: vehicle.listen_WiperHeatEnabled( + callback + ), streaming_firmware="2024.44.25", entity_registry_enabled_default=False, ), TeslemetryBinarySensorEntityDescription( key="rear_display_hvac_enabled", - streaming_listener=lambda x, y: x.listen_RearDisplayHvacEnabled(y), + streaming_listener=lambda vehicle, + callback: vehicle.listen_RearDisplayHvacEnabled(callback), streaming_firmware="2024.44.25", entity_registry_enabled_default=False, ), TeslemetryBinarySensorEntityDescription( key="offroad_lightbar_present", - streaming_listener=lambda x, y: x.listen_OffroadLightbarPresent(y), + streaming_listener=lambda vehicle, + callback: vehicle.listen_OffroadLightbarPresent(callback), streaming_firmware="2024.44.25", entity_registry_enabled_default=False, ), TeslemetryBinarySensorEntityDescription( key="homelink_nearby", - streaming_listener=lambda x, y: x.listen_HomelinkNearby(y), + streaming_listener=lambda vehicle, callback: vehicle.listen_HomelinkNearby( + callback + ), streaming_firmware="2024.44.25", entity_registry_enabled_default=False, ), TeslemetryBinarySensorEntityDescription( key="europe_vehicle", - streaming_listener=lambda x, y: x.listen_EuropeVehicle(y), + streaming_listener=lambda vehicle, callback: vehicle.listen_EuropeVehicle( + callback + ), streaming_firmware="2024.44.25", entity_registry_enabled_default=False, ), TeslemetryBinarySensorEntityDescription( key="right_hand_drive", - streaming_listener=lambda x, y: x.listen_RightHandDrive(y), + streaming_listener=lambda vehicle, callback: vehicle.listen_RightHandDrive( + callback + ), streaming_firmware="2024.44.25", entity_registry_enabled_default=False, ), TeslemetryBinarySensorEntityDescription( key="located_at_home", - streaming_listener=lambda x, y: x.listen_LocatedAtHome(y), + streaming_listener=lambda vehicle, callback: vehicle.listen_LocatedAtHome( + callback + ), streaming_firmware="2024.44.32", ), TeslemetryBinarySensorEntityDescription( key="located_at_work", - streaming_listener=lambda x, y: x.listen_LocatedAtWork(y), + streaming_listener=lambda vehicle, callback: vehicle.listen_LocatedAtWork( + callback + ), streaming_firmware="2024.44.32", ), TeslemetryBinarySensorEntityDescription( key="located_at_favorite", - streaming_listener=lambda x, y: x.listen_LocatedAtFavorite(y), + streaming_listener=lambda vehicle, callback: vehicle.listen_LocatedAtFavorite( + callback + ), streaming_firmware="2024.44.32", entity_registry_enabled_default=False, ), TeslemetryBinarySensorEntityDescription( key="charge_enable_request", - streaming_listener=lambda x, y: x.listen_ChargeEnableRequest(y), + streaming_listener=lambda vehicle, callback: vehicle.listen_ChargeEnableRequest( + callback + ), entity_registry_enabled_default=False, ), TeslemetryBinarySensorEntityDescription( key="defrost_for_preconditioning", - streaming_listener=lambda x, y: x.listen_DefrostForPreconditioning(y), + streaming_listener=lambda vehicle, + callback: vehicle.listen_DefrostForPreconditioning(callback), entity_registry_enabled_default=False, streaming_firmware="2024.44.25", ), @@ -399,36 +456,48 @@ VEHICLE_DESCRIPTIONS: tuple[TeslemetryBinarySensorEntityDescription, ...] = ( ), TeslemetryBinarySensorEntityDescription( key="lights_high_beams", - streaming_listener=lambda x, y: x.listen_LightsHighBeams(y), + streaming_listener=lambda vehicle, callback: vehicle.listen_LightsHighBeams( + callback + ), entity_registry_enabled_default=False, streaming_firmware="2025.2.6", ), TeslemetryBinarySensorEntityDescription( key="seat_vent_enabled", - streaming_listener=lambda x, y: x.listen_SeatVentEnabled(y), + streaming_listener=lambda vehicle, callback: vehicle.listen_SeatVentEnabled( + callback + ), entity_registry_enabled_default=False, streaming_firmware="2025.2.6", ), TeslemetryBinarySensorEntityDescription( key="speed_limit_mode", - streaming_listener=lambda x, y: x.listen_SpeedLimitMode(y), + streaming_listener=lambda vehicle, callback: vehicle.listen_SpeedLimitMode( + callback + ), entity_registry_enabled_default=False, ), TeslemetryBinarySensorEntityDescription( key="remote_start_enabled", - streaming_listener=lambda x, y: x.listen_RemoteStartEnabled(y), + streaming_listener=lambda vehicle, callback: vehicle.listen_RemoteStartEnabled( + callback + ), entity_registry_enabled_default=False, ), TeslemetryBinarySensorEntityDescription( key="hvil", - streaming_listener=lambda x, y: x.listen_Hvil(lambda z: y(z == "Fault")), + streaming_listener=lambda vehicle, callback: vehicle.listen_Hvil( + lambda value: callback(None if value is None else value == "Fault") + ), device_class=BinarySensorDeviceClass.PROBLEM, entity_registry_enabled_default=False, entity_category=EntityCategory.DIAGNOSTIC, ), TeslemetryBinarySensorEntityDescription( key="hvac_auto_mode", - streaming_listener=lambda x, y: x.listen_HvacAutoMode(lambda z: y(z == "On")), + streaming_listener=lambda vehicle, callback: vehicle.listen_HvacAutoMode( + lambda value: callback(None if value is None else value == "On") + ), entity_registry_enabled_default=False, ), ) @@ -437,7 +506,7 @@ VEHICLE_DESCRIPTIONS: tuple[TeslemetryBinarySensorEntityDescription, ...] = ( ENERGY_LIVE_DESCRIPTIONS: tuple[TeslemetryBinarySensorEntityDescription, ...] = ( TeslemetryBinarySensorEntityDescription( key="grid_status", - polling_value_fn=lambda x: x == "Active", + polling_value_fn=lambda value: value == "Active", device_class=BinarySensorDeviceClass.POWER, entity_category=EntityCategory.DIAGNOSTIC, ), From 80466841794927654dd7b62bf1f19b68b6959b4e Mon Sep 17 00:00:00 2001 From: Brett Adams Date: Sun, 4 May 2025 21:44:56 +1000 Subject: [PATCH 53/90] Update models const in Teslemetry (#144175) --- homeassistant/components/teslemetry/__init__.py | 4 ++-- homeassistant/components/teslemetry/const.py | 7 ------- 2 files changed, 2 insertions(+), 9 deletions(-) diff --git a/homeassistant/components/teslemetry/__init__.py b/homeassistant/components/teslemetry/__init__.py index 9efa55de54f..1eb1ea54091 100644 --- a/homeassistant/components/teslemetry/__init__.py +++ b/homeassistant/components/teslemetry/__init__.py @@ -23,7 +23,7 @@ from homeassistant.helpers.aiohttp_client import async_get_clientsession from homeassistant.helpers.device_registry import DeviceInfo from homeassistant.helpers.typing import ConfigType -from .const import DOMAIN, LOGGER, MODELS +from .const import DOMAIN, LOGGER from .coordinator import ( TeslemetryEnergyHistoryCoordinator, TeslemetryEnergySiteInfoCoordinator, @@ -119,7 +119,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: TeslemetryConfigEntry) - manufacturer="Tesla", configuration_url="https://teslemetry.com/console", name=product["display_name"], - model=MODELS.get(vin[3]), + model=api.model, serial_number=vin, ) diff --git a/homeassistant/components/teslemetry/const.py b/homeassistant/components/teslemetry/const.py index 01c6c33f505..ebda486aedf 100644 --- a/homeassistant/components/teslemetry/const.py +++ b/homeassistant/components/teslemetry/const.py @@ -9,13 +9,6 @@ DOMAIN = "teslemetry" LOGGER = logging.getLogger(__package__) -MODELS = { - "S": "Model S", - "3": "Model 3", - "X": "Model X", - "Y": "Model Y", -} - ENERGY_HISTORY_FIELDS = [ "solar_energy_exported", "generator_energy_exported", From 87fab1fa149182616d604cf16b332ceef217312b Mon Sep 17 00:00:00 2001 From: Brett Adams Date: Sun, 4 May 2025 22:18:39 +1000 Subject: [PATCH 54/90] Rename classes in Teslemetry (#144179) --- .../components/teslemetry/binary_sensor.py | 4 +-- homeassistant/components/teslemetry/button.py | 4 +-- .../components/teslemetry/climate.py | 14 ++++---- homeassistant/components/teslemetry/cover.py | 34 +++++++++++-------- .../components/teslemetry/device_tracker.py | 13 ++++--- homeassistant/components/teslemetry/entity.py | 12 +++---- homeassistant/components/teslemetry/lock.py | 14 ++++---- .../components/teslemetry/media_player.py | 8 +++-- homeassistant/components/teslemetry/number.py | 8 ++--- homeassistant/components/teslemetry/select.py | 8 +++-- homeassistant/components/teslemetry/sensor.py | 6 ++-- homeassistant/components/teslemetry/switch.py | 8 ++--- homeassistant/components/teslemetry/update.py | 8 +++-- 13 files changed, 80 insertions(+), 61 deletions(-) diff --git a/homeassistant/components/teslemetry/binary_sensor.py b/homeassistant/components/teslemetry/binary_sensor.py index da5072e2535..99c21cbe03e 100644 --- a/homeassistant/components/teslemetry/binary_sensor.py +++ b/homeassistant/components/teslemetry/binary_sensor.py @@ -24,7 +24,7 @@ from .const import TeslemetryState from .entity import ( TeslemetryEnergyInfoEntity, TeslemetryEnergyLiveEntity, - TeslemetryVehicleEntity, + TeslemetryVehiclePollingEntity, TeslemetryVehicleStreamEntity, ) from .models import TeslemetryEnergyData, TeslemetryVehicleData @@ -569,7 +569,7 @@ async def async_setup_entry( class TeslemetryVehiclePollingBinarySensorEntity( - TeslemetryVehicleEntity, BinarySensorEntity + TeslemetryVehiclePollingEntity, BinarySensorEntity ): """Base class for Teslemetry vehicle binary sensors.""" diff --git a/homeassistant/components/teslemetry/button.py b/homeassistant/components/teslemetry/button.py index 4ca2fd9b166..6cb9d996b95 100644 --- a/homeassistant/components/teslemetry/button.py +++ b/homeassistant/components/teslemetry/button.py @@ -13,7 +13,7 @@ from homeassistant.core import HomeAssistant from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback from . import TeslemetryConfigEntry -from .entity import TeslemetryVehicleEntity +from .entity import TeslemetryVehiclePollingEntity from .helpers import handle_command, handle_vehicle_command from .models import TeslemetryVehicleData @@ -73,7 +73,7 @@ async def async_setup_entry( ) -class TeslemetryButtonEntity(TeslemetryVehicleEntity, ButtonEntity): +class TeslemetryButtonEntity(TeslemetryVehiclePollingEntity, ButtonEntity): """Base class for Teslemetry buttons.""" entity_description: TeslemetryButtonEntityDescription diff --git a/homeassistant/components/teslemetry/climate.py b/homeassistant/components/teslemetry/climate.py index c1c8fcd2f73..0a1c23adcb0 100644 --- a/homeassistant/components/teslemetry/climate.py +++ b/homeassistant/components/teslemetry/climate.py @@ -30,7 +30,7 @@ from . import TeslemetryConfigEntry from .const import DOMAIN, TeslemetryClimateSide from .entity import ( TeslemetryRootEntity, - TeslemetryVehicleEntity, + TeslemetryVehiclePollingEntity, TeslemetryVehicleStreamEntity, ) from .helpers import handle_vehicle_command @@ -64,7 +64,7 @@ async def async_setup_entry( async_add_entities( chain( ( - TeslemetryPollingClimateEntity( + TeslemetryVehiclePollingClimateEntity( vehicle, TeslemetryClimateSide.DRIVER, entry.runtime_data.scopes ) if vehicle.api.pre2021 or vehicle.firmware < "2024.44.25" @@ -74,7 +74,7 @@ async def async_setup_entry( for vehicle in entry.runtime_data.vehicles ), ( - TeslemetryPollingCabinOverheatProtectionEntity( + TeslemetryVehiclePollingCabinOverheatProtectionEntity( vehicle, entry.runtime_data.scopes ) if vehicle.api.pre2021 or vehicle.firmware < "2024.44.25" @@ -178,7 +178,9 @@ class TeslemetryClimateEntity(TeslemetryRootEntity, ClimateEntity): self.async_write_ha_state() -class TeslemetryPollingClimateEntity(TeslemetryClimateEntity, TeslemetryVehicleEntity): +class TeslemetryVehiclePollingClimateEntity( + TeslemetryClimateEntity, TeslemetryVehiclePollingEntity +): """Polling vehicle climate entity.""" _attr_supported_features = ( @@ -430,8 +432,8 @@ class TeslemetryCabinOverheatProtectionEntity(TeslemetryRootEntity, ClimateEntit self.async_write_ha_state() -class TeslemetryPollingCabinOverheatProtectionEntity( - TeslemetryVehicleEntity, TeslemetryCabinOverheatProtectionEntity +class TeslemetryVehiclePollingCabinOverheatProtectionEntity( + TeslemetryVehiclePollingEntity, TeslemetryCabinOverheatProtectionEntity ): """Vehicle Cabin Overheat Protection.""" diff --git a/homeassistant/components/teslemetry/cover.py b/homeassistant/components/teslemetry/cover.py index cde1d3f7d4f..de036edc32a 100644 --- a/homeassistant/components/teslemetry/cover.py +++ b/homeassistant/components/teslemetry/cover.py @@ -21,7 +21,7 @@ from homeassistant.helpers.restore_state import RestoreEntity from . import TeslemetryConfigEntry from .entity import ( TeslemetryRootEntity, - TeslemetryVehicleEntity, + TeslemetryVehiclePollingEntity, TeslemetryVehicleStreamEntity, ) from .helpers import handle_vehicle_command @@ -43,13 +43,15 @@ async def async_setup_entry( async_add_entities( chain( ( - TeslemetryPollingWindowEntity(vehicle, entry.runtime_data.scopes) + TeslemetryVehiclePollingWindowEntity(vehicle, entry.runtime_data.scopes) if vehicle.api.pre2021 or vehicle.firmware < "2024.26" else TeslemetryStreamingWindowEntity(vehicle, entry.runtime_data.scopes) for vehicle in entry.runtime_data.vehicles ), ( - TeslemetryPollingChargePortEntity(vehicle, entry.runtime_data.scopes) + TeslemetryVehiclePollingChargePortEntity( + vehicle, entry.runtime_data.scopes + ) if vehicle.api.pre2021 or vehicle.firmware < "2024.44.25" else TeslemetryStreamingChargePortEntity( vehicle, entry.runtime_data.scopes @@ -57,7 +59,9 @@ async def async_setup_entry( for vehicle in entry.runtime_data.vehicles ), ( - TeslemetryPollingFrontTrunkEntity(vehicle, entry.runtime_data.scopes) + TeslemetryVehiclePollingFrontTrunkEntity( + vehicle, entry.runtime_data.scopes + ) if vehicle.api.pre2021 or vehicle.firmware < "2024.26" else TeslemetryStreamingFrontTrunkEntity( vehicle, entry.runtime_data.scopes @@ -65,7 +69,9 @@ async def async_setup_entry( for vehicle in entry.runtime_data.vehicles ), ( - TeslemetryPollingRearTrunkEntity(vehicle, entry.runtime_data.scopes) + TeslemetryVehiclePollingRearTrunkEntity( + vehicle, entry.runtime_data.scopes + ) if vehicle.api.pre2021 or vehicle.firmware < "2024.26" else TeslemetryStreamingRearTrunkEntity( vehicle, entry.runtime_data.scopes @@ -121,8 +127,8 @@ class TeslemetryWindowEntity(TeslemetryRootEntity, CoverEntity): self.async_write_ha_state() -class TeslemetryPollingWindowEntity( - TeslemetryVehicleEntity, TeslemetryWindowEntity, CoverEntity +class TeslemetryVehiclePollingWindowEntity( + TeslemetryVehiclePollingEntity, TeslemetryWindowEntity, CoverEntity ): """Polling cover entity for windows.""" @@ -238,8 +244,8 @@ class TeslemetryChargePortEntity( self.async_write_ha_state() -class TeslemetryPollingChargePortEntity( - TeslemetryVehicleEntity, TeslemetryChargePortEntity +class TeslemetryVehiclePollingChargePortEntity( + TeslemetryVehiclePollingEntity, TeslemetryChargePortEntity ): """Polling cover entity for the charge port.""" @@ -312,8 +318,8 @@ class TeslemetryFrontTrunkEntity(TeslemetryRootEntity, CoverEntity): # In the future this could be extended to add aftermarket close support through a option flow -class TeslemetryPollingFrontTrunkEntity( - TeslemetryVehicleEntity, TeslemetryFrontTrunkEntity +class TeslemetryVehiclePollingFrontTrunkEntity( + TeslemetryVehiclePollingEntity, TeslemetryFrontTrunkEntity ): """Polling cover entity for the front trunk.""" @@ -381,8 +387,8 @@ class TeslemetryRearTrunkEntity(TeslemetryRootEntity, CoverEntity): self.async_write_ha_state() -class TeslemetryPollingRearTrunkEntity( - TeslemetryVehicleEntity, TeslemetryRearTrunkEntity +class TeslemetryVehiclePollingRearTrunkEntity( + TeslemetryVehiclePollingEntity, TeslemetryRearTrunkEntity ): """Base class for the rear trunk cover entities.""" @@ -424,7 +430,7 @@ class TeslemetryStreamingRearTrunkEntity( self._attr_is_closed = None if value is None else not value -class TeslemetrySunroofEntity(TeslemetryVehicleEntity, CoverEntity): +class TeslemetrySunroofEntity(TeslemetryVehiclePollingEntity, CoverEntity): """Cover entity for the sunroof.""" _attr_device_class = CoverDeviceClass.WINDOW diff --git a/homeassistant/components/teslemetry/device_tracker.py b/homeassistant/components/teslemetry/device_tracker.py index bb90a7b19bd..6a3df6ecb6a 100644 --- a/homeassistant/components/teslemetry/device_tracker.py +++ b/homeassistant/components/teslemetry/device_tracker.py @@ -19,7 +19,7 @@ from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback from homeassistant.helpers.restore_state import RestoreEntity from . import TeslemetryConfigEntry -from .entity import TeslemetryVehicleEntity, TeslemetryVehicleStreamEntity +from .entity import TeslemetryVehiclePollingEntity, TeslemetryVehicleStreamEntity from .models import TeslemetryVehicleData PARALLEL_UPDATES = 0 @@ -74,7 +74,8 @@ async def async_setup_entry( """Set up the Teslemetry device tracker platform from a config entry.""" entities: list[ - TeslemetryPollingDeviceTrackerEntity | TeslemetryStreamingDeviceTrackerEntity + TeslemetryVehiclePollingDeviceTrackerEntity + | TeslemetryStreamingDeviceTrackerEntity ] = [] # Only add vehicle location entities if the user has granted vehicle location scope. if Scope.VEHICLE_LOCATION not in entry.runtime_data.scopes: @@ -85,7 +86,9 @@ async def async_setup_entry( if vehicle.api.pre2021 or vehicle.firmware < description.streaming_firmware: if description.polling_prefix: entities.append( - TeslemetryPollingDeviceTrackerEntity(vehicle, description) + TeslemetryVehiclePollingDeviceTrackerEntity( + vehicle, description + ) ) else: entities.append( @@ -95,7 +98,9 @@ async def async_setup_entry( async_add_entities(entities) -class TeslemetryPollingDeviceTrackerEntity(TeslemetryVehicleEntity, TrackerEntity): +class TeslemetryVehiclePollingDeviceTrackerEntity( + TeslemetryVehiclePollingEntity, TrackerEntity +): """Base class for Teslemetry Tracker Entities.""" entity_description: TeslemetryDeviceTrackerEntityDescription diff --git a/homeassistant/components/teslemetry/entity.py b/homeassistant/components/teslemetry/entity.py index 9ce812980db..4930129642f 100644 --- a/homeassistant/components/teslemetry/entity.py +++ b/homeassistant/components/teslemetry/entity.py @@ -38,7 +38,7 @@ class TeslemetryRootEntity(Entity): ) -class TeslemetryEntity( +class TeslemetryPollingEntity( TeslemetryRootEntity, CoordinatorEntity[ TeslemetryVehicleDataCoordinator @@ -98,7 +98,7 @@ class TeslemetryEntity( """Update the attributes of the entity.""" -class TeslemetryVehicleEntity(TeslemetryEntity): +class TeslemetryVehiclePollingEntity(TeslemetryPollingEntity): """Parent class for Teslemetry Vehicle entities.""" _last_update: int = 0 @@ -130,7 +130,7 @@ class TeslemetryVehicleEntity(TeslemetryEntity): return self.coordinator.data.get(self.key) -class TeslemetryEnergyLiveEntity(TeslemetryEntity): +class TeslemetryEnergyLiveEntity(TeslemetryPollingEntity): """Parent class for Teslemetry Energy Site Live entities.""" api: EnergySite @@ -151,7 +151,7 @@ class TeslemetryEnergyLiveEntity(TeslemetryEntity): super().__init__(data.live_coordinator, key) -class TeslemetryEnergyInfoEntity(TeslemetryEntity): +class TeslemetryEnergyInfoEntity(TeslemetryPollingEntity): """Parent class for Teslemetry Energy Site Info Entities.""" api: EnergySite @@ -170,7 +170,7 @@ class TeslemetryEnergyInfoEntity(TeslemetryEntity): super().__init__(data.info_coordinator, key) -class TeslemetryEnergyHistoryEntity(TeslemetryEntity): +class TeslemetryEnergyHistoryEntity(TeslemetryPollingEntity): """Parent class for Teslemetry Energy History Entities.""" def __init__( @@ -189,7 +189,7 @@ class TeslemetryEnergyHistoryEntity(TeslemetryEntity): super().__init__(data.history_coordinator, key) -class TeslemetryWallConnectorEntity(TeslemetryEntity): +class TeslemetryWallConnectorEntity(TeslemetryPollingEntity): """Parent class for Teslemetry Wall Connector Entities.""" _attr_has_entity_name = True diff --git a/homeassistant/components/teslemetry/lock.py b/homeassistant/components/teslemetry/lock.py index 68505a12a13..75cf72c9c88 100644 --- a/homeassistant/components/teslemetry/lock.py +++ b/homeassistant/components/teslemetry/lock.py @@ -17,7 +17,7 @@ from . import TeslemetryConfigEntry from .const import DOMAIN from .entity import ( TeslemetryRootEntity, - TeslemetryVehicleEntity, + TeslemetryVehiclePollingEntity, TeslemetryVehicleStreamEntity, ) from .helpers import handle_vehicle_command @@ -38,7 +38,7 @@ async def async_setup_entry( async_add_entities( chain( ( - TeslemetryPollingVehicleLockEntity( + TeslemetryVehiclePollingVehicleLockEntity( vehicle, Scope.VEHICLE_CMDS in entry.runtime_data.scopes ) if vehicle.api.pre2021 or vehicle.firmware < "2024.26" @@ -48,7 +48,7 @@ async def async_setup_entry( for vehicle in entry.runtime_data.vehicles ), ( - TeslemetryPollingCableLockEntity( + TeslemetryVehiclePollingCableLockEntity( vehicle, Scope.VEHICLE_CMDS in entry.runtime_data.scopes ) if vehicle.api.pre2021 or vehicle.firmware < "2024.26" @@ -81,8 +81,8 @@ class TeslemetryVehicleLockEntity(TeslemetryRootEntity, LockEntity): self.async_write_ha_state() -class TeslemetryPollingVehicleLockEntity( - TeslemetryVehicleEntity, TeslemetryVehicleLockEntity +class TeslemetryVehiclePollingVehicleLockEntity( + TeslemetryVehiclePollingEntity, TeslemetryVehicleLockEntity ): """Polling vehicle lock entity for Teslemetry.""" @@ -152,8 +152,8 @@ class TeslemetryCableLockEntity(TeslemetryRootEntity, LockEntity): self.async_write_ha_state() -class TeslemetryPollingCableLockEntity( - TeslemetryVehicleEntity, TeslemetryCableLockEntity +class TeslemetryVehiclePollingCableLockEntity( + TeslemetryVehiclePollingEntity, TeslemetryCableLockEntity ): """Polling cable lock entity for Teslemetry.""" diff --git a/homeassistant/components/teslemetry/media_player.py b/homeassistant/components/teslemetry/media_player.py index 50f15618e66..11615d94614 100644 --- a/homeassistant/components/teslemetry/media_player.py +++ b/homeassistant/components/teslemetry/media_player.py @@ -18,7 +18,7 @@ from homeassistant.helpers.restore_state import RestoreEntity from . import TeslemetryConfigEntry from .entity import ( TeslemetryRootEntity, - TeslemetryVehicleEntity, + TeslemetryVehiclePollingEntity, TeslemetryVehicleStreamEntity, ) from .helpers import handle_vehicle_command @@ -52,7 +52,7 @@ async def async_setup_entry( """Set up the Teslemetry Media platform from a config entry.""" async_add_entities( - TeslemetryPollingMediaEntity(vehicle, entry.runtime_data.scopes) + TeslemetryVehiclePollingMediaEntity(vehicle, entry.runtime_data.scopes) if vehicle.api.pre2021 or vehicle.firmware < "2025.2.6" else TeslemetryStreamingMediaEntity(vehicle, entry.runtime_data.scopes) for vehicle in entry.runtime_data.vehicles @@ -107,7 +107,9 @@ class TeslemetryMediaEntity(TeslemetryRootEntity, MediaPlayerEntity): await handle_vehicle_command(self.api.media_prev_track()) -class TeslemetryPollingMediaEntity(TeslemetryVehicleEntity, TeslemetryMediaEntity): +class TeslemetryVehiclePollingMediaEntity( + TeslemetryVehiclePollingEntity, TeslemetryMediaEntity +): """Polling vehicle media player class.""" def __init__( diff --git a/homeassistant/components/teslemetry/number.py b/homeassistant/components/teslemetry/number.py index 117c0a8c233..466fc9f5ee6 100644 --- a/homeassistant/components/teslemetry/number.py +++ b/homeassistant/components/teslemetry/number.py @@ -33,7 +33,7 @@ from . import TeslemetryConfigEntry from .entity import ( TeslemetryEnergyInfoEntity, TeslemetryRootEntity, - TeslemetryVehicleEntity, + TeslemetryVehiclePollingEntity, TeslemetryVehicleStreamEntity, ) from .helpers import handle_command, handle_vehicle_command @@ -140,7 +140,7 @@ async def async_setup_entry( async_add_entities( chain( ( - TeslemetryPollingNumberEntity( + TeslemetryVehiclePollingNumberEntity( vehicle, description, entry.runtime_data.scopes, @@ -183,8 +183,8 @@ class TeslemetryVehicleNumberEntity(TeslemetryRootEntity, NumberEntity): self.async_write_ha_state() -class TeslemetryPollingNumberEntity( - TeslemetryVehicleEntity, TeslemetryVehicleNumberEntity +class TeslemetryVehiclePollingNumberEntity( + TeslemetryVehiclePollingEntity, TeslemetryVehicleNumberEntity ): """Vehicle polling number entity.""" diff --git a/homeassistant/components/teslemetry/select.py b/homeassistant/components/teslemetry/select.py index 9e13d15edc4..be90636497e 100644 --- a/homeassistant/components/teslemetry/select.py +++ b/homeassistant/components/teslemetry/select.py @@ -20,7 +20,7 @@ from . import TeslemetryConfigEntry from .entity import ( TeslemetryEnergyInfoEntity, TeslemetryRootEntity, - TeslemetryVehicleEntity, + TeslemetryVehiclePollingEntity, TeslemetryVehicleStreamEntity, ) from .helpers import handle_command, handle_vehicle_command @@ -177,7 +177,7 @@ async def async_setup_entry( async_add_entities( chain( ( - TeslemetryPollingSelectEntity( + TeslemetryVehiclePollingSelectEntity( vehicle, description, entry.runtime_data.scopes ) if vehicle.api.pre2021 @@ -223,7 +223,9 @@ class TeslemetrySelectEntity(TeslemetryRootEntity, SelectEntity): self.async_write_ha_state() -class TeslemetryPollingSelectEntity(TeslemetryVehicleEntity, TeslemetrySelectEntity): +class TeslemetryVehiclePollingSelectEntity( + TeslemetryVehiclePollingEntity, TeslemetrySelectEntity +): """Base polling vehicle select entity class.""" def __init__( diff --git a/homeassistant/components/teslemetry/sensor.py b/homeassistant/components/teslemetry/sensor.py index b87bd334e8c..20e2abfe9e6 100644 --- a/homeassistant/components/teslemetry/sensor.py +++ b/homeassistant/components/teslemetry/sensor.py @@ -41,7 +41,7 @@ from .entity import ( TeslemetryEnergyHistoryEntity, TeslemetryEnergyInfoEntity, TeslemetryEnergyLiveEntity, - TeslemetryVehicleEntity, + TeslemetryVehiclePollingEntity, TeslemetryVehicleStreamEntity, TeslemetryWallConnectorEntity, ) @@ -1633,7 +1633,7 @@ class TeslemetryStreamSensorEntity(TeslemetryVehicleStreamEntity, RestoreSensor) self.async_write_ha_state() -class TeslemetryVehicleSensorEntity(TeslemetryVehicleEntity, SensorEntity): +class TeslemetryVehicleSensorEntity(TeslemetryVehiclePollingEntity, SensorEntity): """Base class for Teslemetry vehicle metric sensors.""" entity_description: TeslemetryVehicleSensorEntityDescription @@ -1696,7 +1696,7 @@ class TeslemetryStreamTimeSensorEntity(TeslemetryVehicleStreamEntity, SensorEnti self.async_write_ha_state() -class TeslemetryVehicleTimeSensorEntity(TeslemetryVehicleEntity, SensorEntity): +class TeslemetryVehicleTimeSensorEntity(TeslemetryVehiclePollingEntity, SensorEntity): """Base class for Teslemetry vehicle time sensors.""" entity_description: TeslemetryTimeEntityDescription diff --git a/homeassistant/components/teslemetry/switch.py b/homeassistant/components/teslemetry/switch.py index 9d30c73220d..acd17ac4165 100644 --- a/homeassistant/components/teslemetry/switch.py +++ b/homeassistant/components/teslemetry/switch.py @@ -25,7 +25,7 @@ from . import TeslemetryConfigEntry from .entity import ( TeslemetryEnergyInfoEntity, TeslemetryRootEntity, - TeslemetryVehicleEntity, + TeslemetryVehiclePollingEntity, TeslemetryVehicleStreamEntity, ) from .helpers import handle_command, handle_vehicle_command @@ -134,7 +134,7 @@ async def async_setup_entry( async_add_entities( chain( ( - TeslemetryPollingVehicleSwitchEntity( + TeslemetryVehiclePollingVehicleSwitchEntity( vehicle, description, entry.runtime_data.scopes ) if vehicle.api.pre2021 @@ -184,8 +184,8 @@ class TeslemetryVehicleSwitchEntity(TeslemetryRootEntity, SwitchEntity): self.async_write_ha_state() -class TeslemetryPollingVehicleSwitchEntity( - TeslemetryVehicleEntity, TeslemetryVehicleSwitchEntity +class TeslemetryVehiclePollingVehicleSwitchEntity( + TeslemetryVehiclePollingEntity, TeslemetryVehicleSwitchEntity ): """Base class for Teslemetry polling vehicle switch entities.""" diff --git a/homeassistant/components/teslemetry/update.py b/homeassistant/components/teslemetry/update.py index b8d40877de4..144a97039fc 100644 --- a/homeassistant/components/teslemetry/update.py +++ b/homeassistant/components/teslemetry/update.py @@ -15,7 +15,7 @@ from homeassistant.helpers.restore_state import RestoreEntity from . import TeslemetryConfigEntry from .entity import ( TeslemetryRootEntity, - TeslemetryVehicleEntity, + TeslemetryVehiclePollingEntity, TeslemetryVehicleStreamEntity, ) from .helpers import handle_vehicle_command @@ -38,7 +38,7 @@ async def async_setup_entry( """Set up the Teslemetry update platform from a config entry.""" async_add_entities( - TeslemetryPollingUpdateEntity(vehicle, entry.runtime_data.scopes) + TeslemetryVehiclePollingUpdateEntity(vehicle, entry.runtime_data.scopes) if vehicle.api.pre2021 or vehicle.firmware < "2024.44.25" else TeslemetryStreamingUpdateEntity(vehicle, entry.runtime_data.scopes) for vehicle in entry.runtime_data.vehicles @@ -62,7 +62,9 @@ class TeslemetryUpdateEntity(TeslemetryRootEntity, UpdateEntity): self.async_write_ha_state() -class TeslemetryPollingUpdateEntity(TeslemetryVehicleEntity, TeslemetryUpdateEntity): +class TeslemetryVehiclePollingUpdateEntity( + TeslemetryVehiclePollingEntity, TeslemetryUpdateEntity +): """Teslemetry Updates entity.""" def __init__( From 9e388f5b1335bda9daff25b188483a3b991339a1 Mon Sep 17 00:00:00 2001 From: Norbert Rittel Date: Sun, 4 May 2025 14:21:06 +0200 Subject: [PATCH 55/90] Fix spelling of "comma-separated (network addresses)" in `nmap_tracker` (#144197) --- homeassistant/components/nmap_tracker/strings.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/nmap_tracker/strings.json b/homeassistant/components/nmap_tracker/strings.json index 3cbbea007b1..5605ce82ac3 100644 --- a/homeassistant/components/nmap_tracker/strings.json +++ b/homeassistant/components/nmap_tracker/strings.json @@ -23,9 +23,9 @@ "user": { "description": "Configure hosts to be scanned by Nmap. Network address and excludes can be IP addresses (192.168.1.1), IP networks (192.168.0.0/24) or IP ranges (192.168.1.0-32).", "data": { - "hosts": "Network addresses (comma separated) to scan", + "hosts": "Network addresses (comma-separated) to scan", "home_interval": "Minimum number of minutes between scans of active devices (preserve battery)", - "exclude": "Network addresses (comma separated) to exclude from scanning", + "exclude": "Network addresses (comma-separated) to exclude from scanning", "scan_options": "Raw configurable scan options for Nmap" } } From 095318114bc90f19ef00d195586dc90225c0c42d Mon Sep 17 00:00:00 2001 From: Michael Hannon <62535904+mhannon11@users.noreply.github.com> Date: Sun, 4 May 2025 23:58:32 +1000 Subject: [PATCH 56/90] Add Zimi Cloud Connect Integration (#129876) * Give entry unique id with MAC, strings.json tweaks * Update codeowners * Add config_flow tests * Update requirements * Update homeassistant/components/zimi/__init__.py Co-authored-by: Josef Zweck <24647999+zweckj@users.noreply.github.com> * Update homeassistant/components/zimi/config_flow.py Co-authored-by: Josef Zweck <24647999+zweckj@users.noreply.github.com> * Update homeassistant/components/zimi/config_flow.py Co-authored-by: Josef Zweck <24647999+zweckj@users.noreply.github.com> * Store controller reference in entry.runtime_data instead of hass.data * Add typing * Removed hass data pop on unload. (No longer needed when hass data moved for runtime_data) * Refactor config_flow based on feedback from @zweckj with inline validation, simpler defaults, better description data * Add Michael to codeowners * Remove manual debug override in entity * Populate via_device * remove empty keys from manifest.json * Refactor with DataUpdateCoordinator Device Entities use existing push update method * set via_device to match zcc identifier * Changed logger to use debug level * Define the zimi constants * Move extraaneous code out from try * Move __del__ to async_wil_remove_from_hass * Use zcc device for name * Print debug if mac mismatch Add final exception if api is not ready after connect * Re-work configuration flow: 1. Remove unused CONF_TIMEOUT, CONF_VERBOSITY and CONF_WATCHDOG 2. Move connect() logic out of ZimiCoordinator 3. Add fast connect check during ConfigFlow to check mac matches 4. Use zcc version 3.2.3 with default watchdog time value (and remove this from HA) * Add error detail to mac mismatch * Update homeassistant/components/zimi/config_flow.py Co-authored-by: Josef Zweck <24647999+zweckj@users.noreply.github.com> * Update homeassistant/components/zimi/const.py Co-authored-by: Josef Zweck <24647999+zweckj@users.noreply.github.com> * Update homeassistant/components/zimi/coordinator.py Co-authored-by: Josef Zweck <24647999+zweckj@users.noreply.github.com> * Update homeassistant/components/zimi/coordinator.py Co-authored-by: Josef Zweck <24647999+zweckj@users.noreply.github.com> * Update homeassistant/components/zimi/light.py Co-authored-by: Josef Zweck <24647999+zweckj@users.noreply.github.com> * Remove coordinator and move setup to __init__ * Set name in _attr_name * Use _light directly for status etc; Remove _state and _brightness; SImplify update() * Update homeassistant/components/zimi/config_flow.py Co-authored-by: Josef Zweck <24647999+zweckj@users.noreply.github.com> * Update homeassistant/components/zimi/strings.json Co-authored-by: Josef Zweck <24647999+zweckj@users.noreply.github.com> * Update homeassistant/components/zimi/config_flow.py Co-authored-by: Josef Zweck <24647999+zweckj@users.noreply.github.com> * Update homeassistant/components/zimi/config_flow.py Co-authored-by: Josef Zweck <24647999+zweckj@users.noreply.github.com> * No need to delete device, fix return Co-authored-by: Josef Zweck <24647999+zweckj@users.noreply.github.com> * Remove non-failing items from try Abort duplicate configurations Co-authored-by: Josef Zweck <24647999+zweckj@users.noreply.github.com> * Move attr change to notify Co-authored-by: Josef Zweck <24647999+zweckj@users.noreply.github.com> * Update homeassistant/components/zimi/__init__.py Co-authored-by: Josef Zweck <24647999+zweckj@users.noreply.github.com> * Remove superflous defalt * Update homeassistant/components/zimi/light.py Co-authored-by: Josef Zweck <24647999+zweckj@users.noreply.github.com> * Update homeassistant/components/zimi/light.py Co-authored-by: Josef Zweck <24647999+zweckj@users.noreply.github.com> * Update homeassistant/components/zimi/config_flow.py Co-authored-by: Josef Zweck <24647999+zweckj@users.noreply.github.com> * Update homeassistant/components/zimi/config_flow.py Co-authored-by: Josef Zweck <24647999+zweckj@users.noreply.github.com> * Move aysnc_connect_to_controller to helpers.py Co-authored-by: Josef Zweck <24647999+zweckj@users.noreply.github.com> * Invert if api Co-authored-by: Josef Zweck <24647999+zweckj@users.noreply.github.com> * Update homeassistant/components/zimi/config_flow.py Co-authored-by: Josef Zweck <24647999+zweckj@users.noreply.github.com> * Added ZimiConfigEntry to type runtime_data correctly. Co-authored-by: Josef Zweck <24647999+zweckj@users.noreply.github.com> * Use _abort_if_unique_id_configured Co-authored-by: Josef Zweck <24647999+zweckj@users.noreply.github.com> * Invert error logic for cleaner flow Co-authored-by: Josef Zweck <24647999+zweckj@users.noreply.github.com> * Add ZimiDimmer class * Set colour_mode only in ZimiDimmer * Use device name instead of entity name Update deviceinfo for zcc Update deviceinfo for lights More ZimiDimmer and ZimiLight cleanup * Update homeassistant/components/zimi/__init__.py Co-authored-by: Josef Zweck * Update homeassistant/components/zimi/__init__.py Co-authored-by: Josef Zweck * Add missing import for CONNECTION_NETWORK_MAC * @mhannon11 Fixed some minor style changes BUT these tests need re-working now that the config_flow has a second call to the zcc helper to check the API. The tests as written now fail with connect_fail * Remove some code from try * Moved static items from initialiser * Remove superflous assert when unloading entry * refactor - move title out of data * One call to async_add_entities Update ZimiDimmer to initialise color_modes after calling super() * Create ZimiEntity base class (as ToggleEntity) * Updated test of config_flow * Move api_mock parameters to test cases * Much improved tests * Test for input value mismatch and then recovery of flow * Import FlowResultType * Implement Entities event setup correctly * Initial quality_scale.yml * Update homeassistant/components/zimi/quality_scale.yml Co-authored-by: Josef Zweck * Update homeassistant/components/zimi/manifest.json Co-authored-by: Josef Zweck * Add link to zcc repo * Update homeassistant/components/zimi/entity.py Co-authored-by: Josef Zweck * Update homeassistant/components/zimi/entity.py Co-authored-by: Josef Zweck * Removed unecessary f-strings * Filled in all of the quality scale * Updated in line with latest documentation improvements * FIx missing import for Entity * Update homeassistant/components/zimi/strings.json Co-authored-by: Josef Zweck * Update homeassistant/components/zimi/strings.json Co-authored-by: Josef Zweck * Simplify logger and throw * Update homeassistant/components/zimi/helpers.py Co-authored-by: Josef Zweck * Re-factor config_flow with multi-stage steps * Add comments to notify * Don't set hw_version * Update homeassistant/components/zimi/light.py Co-authored-by: Josef Zweck * Update homeassistant/components/zimi/light.py Co-authored-by: Josef Zweck * Update homeassistant/components/zimi/quality_scale.yml Co-authored-by: Josef Zweck * mark docs-troubleshooting done * Update with zcc-helper version supporting PEP 625 sdist rules on PyPi * Comment re characteristic ID * Pulls in latest zcc that closes UDP listening port correctly after discovery timeout * Re-factored config_flow 1. Try discovery and auto-populate 2. Try manual configuration (with optional values for port and mac) In most cases, auto-discovery does it all. Discovery will only fail if UDP broadcast is not possible to/from zcc. * Do not show error message if discovery fails * Refactor with self.data and async_show_step_finish() * Update homeassistant/components/zimi/light.py Co-authored-by: Josef Zweck * Update homeassistant/components/zimi/config_flow.py Co-authored-by: Josef Zweck * Update homeassistant/components/zimi/config_flow.py Co-authored-by: Josef Zweck * Update homeassistant/components/zimi/quality_scale.yml Co-authored-by: Josef Zweck * Update homeassistant/components/zimi/quality_scale.yml Co-authored-by: Josef Zweck * Update homeassistant/components/zimi/entity.py Co-authored-by: Josef Zweck * Update homeassistant/components/zimi/light.py Co-authored-by: Josef Zweck * refactor import to use ConfigFlow * Change status for discovery * Add dynamic title to config flow * string * Revert title from form but add IP:port to static title * Automatically finish configuration if possible, if not show form * Use StrEnum instead of Exception class * Remove MAC from user forms * Disconnect api before form completion * Assign to self.mac instead of returning as detail * Updated test suite * Update test status * mark action exemptions todo * Remove mac related error cases from flow completely * Remove unused MAC error strings * Moved error details to logs Removed _error_tuple Removed error details * Update homeassistant/components/zimi/config_flow.py Co-authored-by: Josef Zweck * rename check_errors * Update homeassistant/components/zimi/config_flow.py Co-authored-by: Josef Zweck * Update homeassistant/components/zimi/config_flow.py Co-authored-by: Josef Zweck * Update zcc-helper and support HA devices via zcc manufacter_info fields * Partial implementation - Use updated zcc-helper to discover multiple controllers * Config_flow with support for auto-discovery of one or more zcc or fallback to manual configuration. * Don't re-connect to api if validate_connection already did * Make fast=False is used for creation * Pull in improved zcc_helper version to address data completeness after machine_info implementation * Update homeassistant/components/zimi/config_flow.py Co-authored-by: Josef Zweck * Import and use ConfigFlowResult * Latest zcc to fix discovers() return value bug * Update config_flow.py * Update homeassistant/components/zimi/manifest.json Co-authored-by: Josef Zweck * Use latest release version of 3.3 (no changes to rc4) * Improved sentence casing * Update strings.json * Update homeassistant/components/zimi/entity.py Co-authored-by: Joost Lekkerkerker * Remove superflous logging Use Zimi network_name as ZCC name Cleanup device info inputs * Remove __del__ * Rename arguments * Update homeassistant/components/zimi/config_flow.py Co-authored-by: Martin Hjelmare * Move PLATFORMS to init * Update homeassistant/components/zimi/light.py Co-authored-by: Martin Hjelmare * Remove debug at init * Update homeassistant/components/zimi/helpers.py Co-authored-by: Martin Hjelmare * Remove _attr_has_entity = False * More naming changes * Revised config_flow to use zcc-helper for validation using new zcc-helper version * Update homeassistant/components/zimi/__init__.py Co-authored-by: Martin Hjelmare * Update homeassistant/components/zimi/__init__.py Co-authored-by: Martin Hjelmare * Removed commented enum * s/_entity/_device/g * Update homeassistant/components/zimi/entity.py Co-authored-by: Martin Hjelmare * Update homeassistant/components/zimi/helpers.py Co-authored-by: Martin Hjelmare * Don't log error when raising exception * Updated tests for new config_flow * Refactor with new zcc that uses Exception classes to pass errors * Updated tests for config_flow to use Exceptions * Device name is based on model * Device name is None Maps better to ZCC concept where devices do not have a name but the individual entities have names. * Fix quality filename * Bump zcc-helper to 3.4 release version * Remove name override * Bump zcc-helper to 3.4.1 with new device_name attribute used to populate devinfo * Update homeassistant/components/zimi/light.py Co-authored-by: Martin Hjelmare * Add missing transalation picked up by CI * Update homeassistant/components/zimi/light.py Co-authored-by: Martin Hjelmare * Bump zcc-helper to only classify light and dimmer controlPointType as lights * Bump to non dev version of zcc-helper * Ruff fixes * Add missing data description for pytest * Remove confusing comment * Update homeassistant/components/zimi/config_flow.py Co-authored-by: Martin Hjelmare * Update homeassistant/components/zimi/config_flow.py Co-authored-by: Martin Hjelmare * Update homeassistant/components/zimi/config_flow.py Co-authored-by: Martin Hjelmare * Update homeassistant/components/zimi/config_flow.py Co-authored-by: Martin Hjelmare * Update homeassistant/components/zimi/config_flow.py Co-authored-by: Martin Hjelmare * Update homeassistant/components/zimi/config_flow.py Co-authored-by: Martin Hjelmare * Update homeassistant/components/zimi/config_flow.py Co-authored-by: Martin Hjelmare * Update homeassistant/components/zimi/config_flow.py Co-authored-by: Martin Hjelmare * Update homeassistant/components/zimi/strings.json Co-authored-by: Martin Hjelmare * Update homeassistant/components/zimi/strings.json Co-authored-by: Martin Hjelmare * Update homeassistant/components/zimi/strings.json Co-authored-by: Martin Hjelmare * Update homeassistant/components/zimi/strings.json Co-authored-by: Martin Hjelmare * Update homeassistant/components/zimi/strings.json Co-authored-by: Martin Hjelmare * Update homeassistant/components/zimi/config_flow.py Co-authored-by: Martin Hjelmare * Update homeassistant/components/zimi/config_flow.py Co-authored-by: Martin Hjelmare * Update homeassistant/components/zimi/const.py Co-authored-by: Martin Hjelmare * Update homeassistant/components/zimi/config_flow.py Co-authored-by: Martin Hjelmare * Update homeassistant/components/zimi/config_flow.py Co-authored-by: Martin Hjelmare * Update homeassistant/components/zimi/const.py Co-authored-by: Martin Hjelmare * Update homeassistant/components/zimi/const.py Co-authored-by: Martin Hjelmare * Update homeassistant/components/zimi/strings.json Co-authored-by: Martin Hjelmare * Update homeassistant/components/zimi/strings.json Co-authored-by: Martin Hjelmare * Update tests/components/zimi/test_config_flow.py Co-authored-by: Martin Hjelmare * Update homeassistant/components/zimi/light.py Co-authored-by: Martin Hjelmare * f-strings * Update tests/components/zimi/test_config_flow.py Co-authored-by: Martin Hjelmare * Update tests/components/zimi/test_config_flow.py Co-authored-by: Martin Hjelmare * Assert result type, step and errors between each step * test for duplicate entry * Update tests/components/zimi/test_config_flow.py Co-authored-by: Martin Hjelmare * Update tests/components/zimi/test_config_flow.py Co-authored-by: Martin Hjelmare * Update tests/components/zimi/test_config_flow.py Co-authored-by: Martin Hjelmare * Update tests/components/zimi/test_config_flow.py Co-authored-by: Martin Hjelmare * Update tests/components/zimi/test_config_flow.py Co-authored-by: Martin Hjelmare * Remove duplicate test for discovery failure * Calculate brightness * Don't re-raise Exception in helper * Fix ruff and mypi errors * Add tests for missing connection exceptions * Added standard invalid_host and timeout strings * Explain limitations in discovery. * Update quality_scale.yaml * Update quality_scale.yaml * Removed duplicate strings with reference --------- Co-authored-by: markhannon Co-authored-by: Josef Zweck <24647999+zweckj@users.noreply.github.com> Co-authored-by: Josef Zweck Co-authored-by: Joost Lekkerkerker Co-authored-by: Martin Hjelmare --- CODEOWNERS | 2 + homeassistant/components/zimi/__init__.py | 67 ++++ homeassistant/components/zimi/config_flow.py | 172 ++++++++ homeassistant/components/zimi/const.py | 3 + homeassistant/components/zimi/entity.py | 66 ++++ homeassistant/components/zimi/helpers.py | 38 ++ homeassistant/components/zimi/light.py | 103 +++++ homeassistant/components/zimi/manifest.json | 10 + .../components/zimi/quality_scale.yaml | 99 +++++ homeassistant/components/zimi/strings.json | 46 +++ homeassistant/generated/config_flows.py | 1 + homeassistant/generated/integrations.json | 6 + requirements_all.txt | 3 + requirements_test_all.txt | 3 + tests/components/zimi/__init__.py | 1 + tests/components/zimi/test_config_flow.py | 371 ++++++++++++++++++ 16 files changed, 991 insertions(+) create mode 100644 homeassistant/components/zimi/__init__.py create mode 100644 homeassistant/components/zimi/config_flow.py create mode 100644 homeassistant/components/zimi/const.py create mode 100644 homeassistant/components/zimi/entity.py create mode 100644 homeassistant/components/zimi/helpers.py create mode 100644 homeassistant/components/zimi/light.py create mode 100644 homeassistant/components/zimi/manifest.json create mode 100644 homeassistant/components/zimi/quality_scale.yaml create mode 100644 homeassistant/components/zimi/strings.json create mode 100644 tests/components/zimi/__init__.py create mode 100644 tests/components/zimi/test_config_flow.py diff --git a/CODEOWNERS b/CODEOWNERS index 490f97879a4..752bbb31460 100644 --- a/CODEOWNERS +++ b/CODEOWNERS @@ -1796,6 +1796,8 @@ build.json @home-assistant/supervisor /tests/components/zeversolar/ @kvanzuijlen /homeassistant/components/zha/ @dmulcahey @adminiuga @puddly @TheJulianJES /tests/components/zha/ @dmulcahey @adminiuga @puddly @TheJulianJES +/homeassistant/components/zimi/ @markhannon +/tests/components/zimi/ @markhannon /homeassistant/components/zodiac/ @JulienTant /tests/components/zodiac/ @JulienTant /homeassistant/components/zone/ @home-assistant/core diff --git a/homeassistant/components/zimi/__init__.py b/homeassistant/components/zimi/__init__.py new file mode 100644 index 00000000000..db91f7816c4 --- /dev/null +++ b/homeassistant/components/zimi/__init__.py @@ -0,0 +1,67 @@ +"""The zcc integration.""" + +from __future__ import annotations + +import logging + +from zcc import ControlPoint, ControlPointError + +from homeassistant.config_entries import ConfigEntry +from homeassistant.const import CONF_HOST, CONF_PORT, Platform +from homeassistant.core import HomeAssistant +from homeassistant.exceptions import ConfigEntryNotReady +from homeassistant.helpers import device_registry as dr +from homeassistant.helpers.device_registry import CONNECTION_NETWORK_MAC + +from .const import DOMAIN +from .helpers import async_connect_to_controller + +PLATFORMS = [Platform.LIGHT] + +_LOGGER = logging.getLogger(__name__) + + +type ZimiConfigEntry = ConfigEntry[ControlPoint] + + +async def async_setup_entry(hass: HomeAssistant, entry: ZimiConfigEntry) -> bool: + """Connect to Zimi Controller and register device.""" + + try: + api = await async_connect_to_controller( + host=entry.data[CONF_HOST], + port=entry.data[CONF_PORT], + ) + + except ControlPointError as error: + raise ConfigEntryNotReady(f"Zimi setup failed: {error}") from error + + _LOGGER.debug("\n%s", api.describe()) + + entry.runtime_data = api + + device_registry = dr.async_get(hass) + device_registry.async_get_or_create( + config_entry_id=entry.entry_id, + identifiers={(DOMAIN, api.mac)}, + manufacturer=api.brand, + name=f"{api.network_name}", + model="Zimi Cloud Connect", + sw_version=api.firmware_version, + connections={(CONNECTION_NETWORK_MAC, api.mac)}, + ) + + await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS) + + _LOGGER.debug("Zimi setup complete") + + return True + + +async def async_unload_entry(hass: HomeAssistant, entry: ZimiConfigEntry) -> bool: + """Unload a config entry.""" + + api = entry.runtime_data + api.disconnect() + + return await hass.config_entries.async_unload_platforms(entry, PLATFORMS) diff --git a/homeassistant/components/zimi/config_flow.py b/homeassistant/components/zimi/config_flow.py new file mode 100644 index 00000000000..1037a05a2ce --- /dev/null +++ b/homeassistant/components/zimi/config_flow.py @@ -0,0 +1,172 @@ +"""Config flow for zcc integration.""" + +from __future__ import annotations + +import logging +from typing import Any + +import voluptuous as vol +from zcc import ( + ControlPoint, + ControlPointCannotConnectError, + ControlPointConnectionRefusedError, + ControlPointDescription, + ControlPointDiscoveryService, + ControlPointError, + ControlPointInvalidHostError, + ControlPointTimeoutError, +) + +from homeassistant.config_entries import ConfigFlow, ConfigFlowResult +from homeassistant.const import CONF_HOST, CONF_MAC, CONF_PORT +from homeassistant.helpers.device_registry import format_mac +from homeassistant.helpers.selector import ( + SelectOptionDict, + SelectSelector, + SelectSelectorConfig, + SelectSelectorMode, +) + +from .const import DOMAIN + +_LOGGER = logging.getLogger(__name__) +DEFAULT_PORT = 5003 +STEP_MANUAL_DATA_SCHEMA = vol.Schema( + { + vol.Required(CONF_HOST): str, + vol.Required(CONF_PORT, default=DEFAULT_PORT): int, + } +) + +SELECTED_HOST_AND_PORT = "selected_host_and_port" + + +class ZimiConfigFlow(ConfigFlow, domain=DOMAIN): + """Handle a config flow for zcc.""" + + api: ControlPoint = None + api_descriptions: list[ControlPointDescription] + data: dict[str, Any] + + async def async_step_user( + self, user_input: dict[str, Any] | None = None + ) -> ConfigFlowResult: + """Handle the initial auto-discovery step.""" + + self.data = {} + + try: + self.api_descriptions = await ControlPointDiscoveryService().discovers() + except ControlPointError: + # ControlPointError is expected if no zcc are found on LAN + return await self.async_step_manual() + + if len(self.api_descriptions) == 1: + self.data[CONF_HOST] = self.api_descriptions[0].host + self.data[CONF_PORT] = self.api_descriptions[0].port + await self.check_connection(self.data[CONF_HOST], self.data[CONF_PORT]) + return await self.create_entry() + + return await self.async_step_selection() + + async def async_step_selection( + self, user_input: dict[str, Any] | None = None + ) -> ConfigFlowResult: + """Handle selection of zcc to configure if multiple are discovered.""" + + errors: dict[str, str] | None = {} + + if user_input is not None: + self.data[CONF_HOST] = user_input[SELECTED_HOST_AND_PORT].split(":")[0] + self.data[CONF_PORT] = int(user_input[SELECTED_HOST_AND_PORT].split(":")[1]) + errors = await self.check_connection( + self.data[CONF_HOST], self.data[CONF_PORT] + ) + if not errors: + return await self.create_entry() + + available_options = [ + SelectOptionDict( + label=f"{description.host}:{description.port}", + value=f"{description.host}:{description.port}", + ) + for description in self.api_descriptions + ] + + available_schema = vol.Schema( + { + vol.Required( + SELECTED_HOST_AND_PORT, default=available_options[0]["value"] + ): SelectSelector( + SelectSelectorConfig( + options=available_options, + mode=SelectSelectorMode.DROPDOWN, + ) + ) + } + ) + + return self.async_show_form( + step_id="selection", data_schema=available_schema, errors=errors + ) + + async def async_step_manual( + self, user_input: dict[str, Any] | None = None + ) -> ConfigFlowResult: + """Handle manual configuration step if needed.""" + + errors: dict[str, str] | None = {} + + if user_input is not None: + self.data = {**self.data, **user_input} + + errors = await self.check_connection( + self.data[CONF_HOST], self.data[CONF_PORT] + ) + + if not errors: + return await self.create_entry() + + return self.async_show_form( + step_id="manual", + data_schema=self.add_suggested_values_to_schema( + STEP_MANUAL_DATA_SCHEMA, self.data + ), + errors=errors, + ) + + async def check_connection(self, host: str, port: int) -> dict[str, str] | None: + """Check connection to zcc. + + Stores mac and returns None if successful, otherwise returns error message. + """ + + try: + result = await ControlPointDiscoveryService().validate_connection( + self.data[CONF_HOST], self.data[CONF_PORT] + ) + except ControlPointInvalidHostError: + return {"base": "invalid_host"} + except ControlPointConnectionRefusedError: + return {"base": "connection_refused"} + except ControlPointCannotConnectError: + return {"base": "cannot_connect"} + except ControlPointTimeoutError: + return {"base": "timeout"} + except Exception: + _LOGGER.exception("Unexpected error") + return {"base": "unknown"} + + self.data[CONF_MAC] = format_mac(result.mac) + + return None + + async def create_entry(self) -> ConfigFlowResult: + """Create entry for zcc.""" + + await self.async_set_unique_id(self.data[CONF_MAC]) + self._abort_if_unique_id_configured() + return self.async_create_entry( + title=f"ZIMI Controller ({self.data[CONF_HOST]}:{self.data[CONF_PORT]})", + data=self.data, + ) diff --git a/homeassistant/components/zimi/const.py b/homeassistant/components/zimi/const.py new file mode 100644 index 00000000000..1a426875b75 --- /dev/null +++ b/homeassistant/components/zimi/const.py @@ -0,0 +1,3 @@ +"""Constants for the zcc integration.""" + +DOMAIN = "zimi" diff --git a/homeassistant/components/zimi/entity.py b/homeassistant/components/zimi/entity.py new file mode 100644 index 00000000000..64781454b2c --- /dev/null +++ b/homeassistant/components/zimi/entity.py @@ -0,0 +1,66 @@ +"""Base entity for zimi integrations.""" + +from __future__ import annotations + +import logging + +from zcc import ControlPoint +from zcc.device import ControlPointDevice + +from homeassistant.helpers.device_registry import DeviceInfo +from homeassistant.helpers.entity import Entity + +from .const import DOMAIN + +_LOGGER = logging.getLogger(__name__) + + +class ZimiEntity(Entity): + """Representation of a Zimi API entity.""" + + _attr_should_poll = False + _attr_has_entity_name = True + + def __init__(self, device: ControlPointDevice, api: ControlPoint) -> None: + """Initialize an HA Entity which is a ZimiDevice.""" + + self._device = device + self._attr_unique_id = self._device.identifier + self._attr_device_info = DeviceInfo( + identifiers={(DOMAIN, self._device.manufacture_info.identifier)}, + manufacturer=self._device.manufacture_info.manufacturer, + model=self._device.manufacture_info.model, + name=self._device.manufacture_info.name, + hw_version=device.manufacture_info.hwVersion, + sw_version=device.manufacture_info.firmwareVersion, + suggested_area=device.room, + via_device=(DOMAIN, api.mac), + ) + self._attr_name = self._device.name.strip() + self._attr_suggested_area = self._device.room + + @property + def available(self) -> bool: + """Return True if Home Assistant is able to read the state and control the underlying device.""" + return self._device.is_connected + + async def async_added_to_hass(self) -> None: + """Subscribe to the events.""" + await super().async_added_to_hass() + self._device.subscribe(self) + + async def async_will_remove_from_hass(self) -> None: + """Cleanup ZimiLight with removal of notification prior to removal.""" + self._device.unsubscribe(self) + await super().async_will_remove_from_hass() + + def notify(self, _observable: object) -> None: + """Receive notification from device that state has changed. + + No data is fetched for the notification but schedule_update_ha_state is called. + """ + + _LOGGER.debug( + "Received notification() for %s in %s", self._device.name, self._device.room + ) + self.schedule_update_ha_state(force_refresh=True) diff --git a/homeassistant/components/zimi/helpers.py b/homeassistant/components/zimi/helpers.py new file mode 100644 index 00000000000..81d9a986f46 --- /dev/null +++ b/homeassistant/components/zimi/helpers.py @@ -0,0 +1,38 @@ +"""The zcc integration helpers.""" + +from __future__ import annotations + +import logging + +from zcc import ControlPoint, ControlPointDescription + +from homeassistant.exceptions import ConfigEntryNotReady + +_LOGGER = logging.getLogger(__name__) + + +async def async_connect_to_controller( + host: str, port: int, fast: bool = False +) -> ControlPoint: + """Connect to Zimi Cloud Controller with defined parameters.""" + + _LOGGER.debug("Connecting to %s:%d", host, port) + + api = ControlPoint( + description=ControlPointDescription( + host=host, + port=port, + ) + ) + await api.connect(fast=fast) + + if api.ready: + _LOGGER.debug("Connected") + + if not fast: + api.start_watchdog() + _LOGGER.debug("Started watchdog") + + return api + + raise ConfigEntryNotReady("Connection failed: not ready") diff --git a/homeassistant/components/zimi/light.py b/homeassistant/components/zimi/light.py new file mode 100644 index 00000000000..a93bbb53b3d --- /dev/null +++ b/homeassistant/components/zimi/light.py @@ -0,0 +1,103 @@ +"""Light platform for zcc integration.""" + +from __future__ import annotations + +import logging +from typing import Any + +from zcc import ControlPoint +from zcc.device import ControlPointDevice + +from homeassistant.components.light import ATTR_BRIGHTNESS, ColorMode, LightEntity +from homeassistant.core import HomeAssistant +from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback + +from . import ZimiConfigEntry +from .entity import ZimiEntity + +_LOGGER = logging.getLogger(__name__) + + +async def async_setup_entry( + hass: HomeAssistant, + config_entry: ZimiConfigEntry, + async_add_entities: AddConfigEntryEntitiesCallback, +) -> None: + """Set up the Zimi Light platform.""" + + api = config_entry.runtime_data + + lights: list[ZimiLight | ZimiDimmer] = [ + ZimiLight(device, api) for device in api.lights if device.type != "dimmer" + ] + + lights.extend( + [ZimiDimmer(device, api) for device in api.lights if device.type == "dimmer"] + ) + + async_add_entities(lights) + + +class ZimiLight(ZimiEntity, LightEntity): + """Representation of a Zimi Light.""" + + def __init__(self, device: ControlPointDevice, api: ControlPoint) -> None: + """Initialize a ZimiLight.""" + + super().__init__(device, api) + + self._attr_color_mode = ColorMode.ONOFF + self._attr_supported_color_modes = {ColorMode.ONOFF} + + @property + def is_on(self) -> bool: + """Return true if light is on.""" + return self._device.is_on + + async def async_turn_on(self, **kwargs: Any) -> None: + """Instruct the light to turn on (with optional brightness).""" + + _LOGGER.debug( + "Sending turn_on() for %s in %s", self._device.name, self._device.room + ) + + await self._device.turn_on() + + async def async_turn_off(self, **kwargs: Any) -> None: + """Instruct the light to turn off.""" + + _LOGGER.debug( + "Sending turn_off() for %s in %s", self._device.name, self._device.room + ) + + await self._device.turn_off() + + +class ZimiDimmer(ZimiLight): + """Zimi Light supporting dimming.""" + + def __init__(self, device: ControlPointDevice, api: ControlPoint) -> None: + """Initialize a ZimiDimmer.""" + super().__init__(device, api) + self._attr_color_mode = ColorMode.BRIGHTNESS + self._attr_supported_color_modes = {ColorMode.BRIGHTNESS} + if self._device.type != "dimmer": + raise ValueError("ZimiDimmer needs a dimmable light") + + async def async_turn_on(self, **kwargs: Any) -> None: + """Instruct the light to turn on (with optional brightness).""" + + brightness = kwargs.get(ATTR_BRIGHTNESS, 255) * 100 / 255 + _LOGGER.debug( + "Sending turn_on(brightness=%d) for %s in %s", + brightness, + self._device.name, + self._device.room, + ) + + await self._device.set_brightness(brightness) + + @property + def brightness(self) -> int | None: + """Return the brightness of the light.""" + return round(self._device.brightness * 255 / 100) diff --git a/homeassistant/components/zimi/manifest.json b/homeassistant/components/zimi/manifest.json new file mode 100644 index 00000000000..d0dd3e09e06 --- /dev/null +++ b/homeassistant/components/zimi/manifest.json @@ -0,0 +1,10 @@ +{ + "domain": "zimi", + "name": "zimi", + "codeowners": ["@markhannon"], + "config_flow": true, + "documentation": "https://www.home-assistant.io/integrations/zimi", + "iot_class": "local_push", + "quality_scale": "bronze", + "requirements": ["zcc-helper==3.5"] +} diff --git a/homeassistant/components/zimi/quality_scale.yaml b/homeassistant/components/zimi/quality_scale.yaml new file mode 100644 index 00000000000..98e6c5b627c --- /dev/null +++ b/homeassistant/components/zimi/quality_scale.yaml @@ -0,0 +1,99 @@ +rules: + # Bronze + action-setup: + status: exempt + comment: | + There are no service actions. + appropriate-polling: + status: done + comment: | + There is no polling of the entities. + brands: done + common-modules: done + config-flow-test-coverage: done + config-flow: done + dependency-transparency: + status: done + comment: | + https://mark_hannon@bitbucket.org/mark_hannon/zcc.git + docs-actions: + status: exempt + comment: | + There are no service actions. + docs-high-level-description: done + docs-installation-instructions: done + docs-removal-instructions: done + entity-event-setup: done + entity-unique-id: done + has-entity-name: done + runtime-data: done + test-before-configure: done + test-before-setup: done + unique-config-entry: done + + # Silver + config-entry-unloading: done + log-when-unavailable: todo + entity-unavailable: done + action-exceptions: todo + reauthentication-flow: + status: exempt + comment: | + There is no user authentication needed. + parallel-updates: + status: todo + comment: | + Test of parallel updates will be done before setting. + test-coverage: todo + integration-owner: done + docs-installation-parameters: done + docs-configuration-parameters: + status: exempt + comment: | + This integration has no options flow + + # Gold + entity-translations: todo + entity-device-class: + status: todo + comment: | + Will set device classes for subsequent entities - not relevant for light. + devices: done + entity-category: todo + entity-disabled-by-default: todo + discovery: + status: todo + comment: > + Discovery is supported for the case where the Zimi Cloud Controller(s) are + connected to a local LAN network. Discover is not supported if the Zimi + Cloud Controller(s) are not connected to the local LAN network. + stale-devices: todo + diagnostics: todo + exception-translations: todo + icon-translations: todo + reconfiguration-flow: todo + dynamic-devices: + status: todo + comment: | + New devices will be automatically added - but only when the zcc connection is re-established. + discovery-update-info: + status: todo + comment: > + Discovery is not supported. + repair-issues: todo + docs-use-cases: todo + docs-supported-devices: done + docs-supported-functions: todo + docs-troubleshooting: done + docs-data-update: done + docs-known-limitations: done + docs-examples: todo + + # Platinum + async-dependency: done + inject-websession: + status: exempt + comment: | + This integration does not use web sessions. + strict-typing: + status: todo diff --git a/homeassistant/components/zimi/strings.json b/homeassistant/components/zimi/strings.json new file mode 100644 index 00000000000..530eb86ef05 --- /dev/null +++ b/homeassistant/components/zimi/strings.json @@ -0,0 +1,46 @@ +{ + "config": { + "step": { + "user": { + "title": "Zimi - Discover device(s)", + "description": "Discover and auto-configure Zimi Cloud Connect device." + }, + "selection": { + "title": "Zimi - Select device", + "description": "Select Zimi Cloud Connect device to configure.", + "data": { + "host": "[%key:common::config_flow::data::host%]", + "port": "[%key:common::config_flow::data::port%]", + "selected_host_and_port": "Selected ZCC" + }, + "data_description": { + "host": "Mandatory - ZCC IP address.", + "port": "Mandatory - ZCC port number (default=5003).", + "selected_host_and_port": "Selected ZCC IP address and port number" + } + }, + "manual": { + "title": "Zimi - Configure device", + "description": "Enter details of your Zimi Cloud Connect device.", + "data": { + "host": "[%key:common::config_flow::data::host%]", + "port": "[%key:common::config_flow::data::port%]" + }, + "data_description": { + "host": "[%key:component::zimi::config::step::selection::data_description::host%]", + "port": "[%key:component::zimi::config::step::selection::data_description::port%]" + } + } + }, + "error": { + "cannot_connect": "[%key:common::config_flow::error::cannot_connect%]", + "unknown": "[%key:common::config_flow::error::unknown%]", + "timeout": "[%key:common::config_flow::error::timeout_connect%]", + "invalid_host": "[%key:common::config_flow::error::invalid_host%]", + "connection_refused": "Connection refused" + }, + "abort": { + "already_configured": "[%key:common::config_flow::abort::already_configured_device%]" + } + } +} diff --git a/homeassistant/generated/config_flows.py b/homeassistant/generated/config_flows.py index 8174dfc60b1..680d0a7bb2c 100644 --- a/homeassistant/generated/config_flows.py +++ b/homeassistant/generated/config_flows.py @@ -736,6 +736,7 @@ FLOWS = { "zerproc", "zeversolar", "zha", + "zimi", "zodiac", "zwave_js", "zwave_me", diff --git a/homeassistant/generated/integrations.json b/homeassistant/generated/integrations.json index 5e97e4c6626..1b9e9216827 100644 --- a/homeassistant/generated/integrations.json +++ b/homeassistant/generated/integrations.json @@ -7630,6 +7630,12 @@ "config_flow": false, "iot_class": "local_polling" }, + "zimi": { + "name": "zimi", + "integration_type": "hub", + "config_flow": true, + "iot_class": "local_push" + }, "zodiac": { "integration_type": "hub", "config_flow": true, diff --git a/requirements_all.txt b/requirements_all.txt index 9d116efa284..8f902317db7 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -3155,6 +3155,9 @@ zabbix-utils==2.0.2 # homeassistant.components.zamg zamg==0.3.6 +# homeassistant.components.zimi +zcc-helper==3.5 + # homeassistant.components.zeroconf zeroconf==0.147.0 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index b14067bfd17..79c1bcc79f2 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -2554,6 +2554,9 @@ yt-dlp[default]==2025.03.31 # homeassistant.components.zamg zamg==0.3.6 +# homeassistant.components.zimi +zcc-helper==3.5 + # homeassistant.components.zeroconf zeroconf==0.147.0 diff --git a/tests/components/zimi/__init__.py b/tests/components/zimi/__init__.py new file mode 100644 index 00000000000..0e95ffc9c33 --- /dev/null +++ b/tests/components/zimi/__init__.py @@ -0,0 +1 @@ +"""Tests for the zimi component.""" diff --git a/tests/components/zimi/test_config_flow.py b/tests/components/zimi/test_config_flow.py new file mode 100644 index 00000000000..9ec0c624b6f --- /dev/null +++ b/tests/components/zimi/test_config_flow.py @@ -0,0 +1,371 @@ +"""Tests for the zimi config flow.""" + +from unittest.mock import MagicMock, patch + +import pytest +from zcc import ( + ControlPointCannotConnectError, + ControlPointConnectionRefusedError, + ControlPointDescription, + ControlPointError, + ControlPointInvalidHostError, + ControlPointTimeoutError, +) + +from homeassistant import config_entries +from homeassistant.components.zimi.const import DOMAIN +from homeassistant.const import CONF_HOST, CONF_PORT +from homeassistant.core import HomeAssistant +from homeassistant.data_entry_flow import FlowResultType +from homeassistant.helpers.device_registry import format_mac + +from tests.common import MockConfigEntry + +INPUT_MAC = "aa:bb:cc:dd:ee:ff" +INPUT_MAC_EXTRA = "aa:bb:cc:dd:ee:ee" +INPUT_HOST = "192.168.1.100" +INPUT_HOST_EXTRA = "192.168.1.101" +INPUT_PORT = 5003 +INPUT_PORT_EXTRA = 5004 + +INVALID_INPUT_MAC = "xyz" +MISMATCHED_INPUT_MAC = "aa:bb:cc:dd:ee:ee" +SELECTED_HOST_AND_PORT = "selected_host_and_port" + + +@pytest.fixture +def discovery_mock(): + """Mock the ControlPointDiscoveryService.""" + with patch( + "homeassistant.components.zimi.config_flow.ControlPointDiscoveryService", + autospec=True, + ) as mock: + mock.return_value = mock + yield mock + + +async def test_user_discovery_success( + hass: HomeAssistant, + discovery_mock: MagicMock, +) -> None: + """Test user form transitions to creation if zcc discovery succeeds.""" + + discovery_mock.discovers.return_value = [ + ControlPointDescription(host=INPUT_HOST, port=INPUT_PORT) + ] + + discovery_mock.return_value.validate_connection.return_value = ( + ControlPointDescription(host=INPUT_HOST, port=INPUT_PORT, mac=INPUT_MAC) + ) + + result = await hass.config_entries.flow.async_init( + DOMAIN, context={"source": config_entries.SOURCE_USER} + ) + + assert result["type"] is FlowResultType.CREATE_ENTRY + assert result["data"] == { + "host": INPUT_HOST, + "port": INPUT_PORT, + "mac": format_mac(INPUT_MAC), + } + + +async def test_user_discovery_success_selection( + hass: HomeAssistant, + discovery_mock: MagicMock, +) -> None: + """Test user form transitions via selection to creation if zcc discovery succeeds has multiple hosts.""" + + discovery_mock.discovers.return_value = [ + ControlPointDescription(host=INPUT_HOST, port=INPUT_PORT), + ControlPointDescription(host=INPUT_HOST_EXTRA, port=INPUT_PORT_EXTRA), + ] + + result = await hass.config_entries.flow.async_init( + DOMAIN, context={"source": config_entries.SOURCE_USER} + ) + + assert result["type"] is FlowResultType.FORM + assert result["step_id"] == "selection" + assert result["errors"] == {} + + discovery_mock.return_value.validate_connection.return_value = ( + ControlPointDescription( + host=INPUT_HOST_EXTRA, port=INPUT_PORT_EXTRA, mac=INPUT_MAC_EXTRA + ) + ) + + result = await hass.config_entries.flow.async_configure( + result["flow_id"], + { + SELECTED_HOST_AND_PORT: f"{INPUT_HOST_EXTRA}:{INPUT_PORT_EXTRA!s}", + }, + ) + + assert result["type"] is FlowResultType.CREATE_ENTRY + assert result["data"] == { + "host": INPUT_HOST_EXTRA, + "port": INPUT_PORT_EXTRA, + "mac": format_mac(INPUT_MAC_EXTRA), + } + + +async def test_user_discovery_duplicates( + hass: HomeAssistant, + discovery_mock: MagicMock, +) -> None: + """Test that flow is aborted if duplicates are added.""" + + MockConfigEntry( + domain=DOMAIN, + unique_id=INPUT_MAC, + data={ + CONF_HOST: INPUT_HOST, + CONF_PORT: INPUT_PORT, + "mac": format_mac(INPUT_MAC), + }, + ).add_to_hass(hass) + + discovery_mock.discovers.return_value = [ + ControlPointDescription(host=INPUT_HOST, port=INPUT_PORT) + ] + + discovery_mock.return_value.validate_connection.return_value = ( + ControlPointDescription(host=INPUT_HOST, port=INPUT_PORT, mac=INPUT_MAC) + ) + + result = await hass.config_entries.flow.async_init( + DOMAIN, context={"source": config_entries.SOURCE_USER} + ) + + assert result["type"] is FlowResultType.ABORT + assert result["reason"] == "already_configured" + + +async def test_finish_manual_success( + hass: HomeAssistant, + discovery_mock: MagicMock, +) -> None: + """Test manual form transitions to creation with valid data.""" + + discovery_mock.discovers.side_effect = ControlPointError("Discovery failed") + discovery_mock.return_value.validate_connection.return_value = ( + ControlPointDescription(host=INPUT_HOST, port=INPUT_PORT, mac=INPUT_MAC) + ) + + result = await hass.config_entries.flow.async_init( + DOMAIN, context={"source": config_entries.SOURCE_USER} + ) + + assert result["type"] is FlowResultType.FORM + assert result["step_id"] == "manual" + assert result["errors"] == {} + + result = await hass.config_entries.flow.async_configure( + result["flow_id"], + { + CONF_HOST: INPUT_HOST, + CONF_PORT: INPUT_PORT, + }, + ) + + assert result["type"] is FlowResultType.CREATE_ENTRY + assert result["title"] == f"ZIMI Controller ({INPUT_HOST}:{INPUT_PORT})" + assert result["data"] == { + "host": INPUT_HOST, + "port": INPUT_PORT, + "mac": format_mac(INPUT_MAC), + } + + +async def test_manual_cannot_connect( + hass: HomeAssistant, + discovery_mock: MagicMock, +) -> None: + """Test manual form transitions via cannot_connect to creation.""" + + discovery_mock.discovers.side_effect = ControlPointError("Discovery failed") + + result = await hass.config_entries.flow.async_init( + DOMAIN, context={"source": config_entries.SOURCE_USER} + ) + + assert result["type"] is FlowResultType.FORM + assert result["step_id"] == "manual" + assert result["errors"] == {} + + # First attempt fails with CANNOT_CONNECT when attempting to connect + discovery_mock.return_value.validate_connection.side_effect = ( + ControlPointCannotConnectError + ) + + result = await hass.config_entries.flow.async_configure( + result["flow_id"], + { + CONF_HOST: INPUT_HOST, + CONF_PORT: INPUT_PORT, + }, + ) + + assert result["type"] is FlowResultType.FORM + assert result["step_id"] == "manual" + assert result["errors"] == {"base": "cannot_connect"} + + # Second attempt succeeds + discovery_mock.return_value.validate_connection.side_effect = None + discovery_mock.return_value.validate_connection.return_value = ( + ControlPointDescription(host=INPUT_HOST, port=INPUT_PORT, mac=INPUT_MAC) + ) + + result = await hass.config_entries.flow.async_configure( + result["flow_id"], + { + CONF_HOST: INPUT_HOST, + CONF_PORT: INPUT_PORT, + }, + ) + + assert result["type"] is FlowResultType.CREATE_ENTRY + assert result["title"] == f"ZIMI Controller ({INPUT_HOST}:{INPUT_PORT})" + assert result["data"] == { + "host": INPUT_HOST, + "port": INPUT_PORT, + "mac": format_mac(INPUT_MAC), + } + + +async def test_manual_gethostbyname_error( + hass: HomeAssistant, + discovery_mock: MagicMock, +) -> None: + """Test manual form transitions via gethostbyname failure to creation.""" + + discovery_mock.discovers.side_effect = ControlPointError("Discovery failed") + + result = await hass.config_entries.flow.async_init( + DOMAIN, context={"source": config_entries.SOURCE_USER} + ) + + assert result["type"] is FlowResultType.FORM + assert result["step_id"] == "manual" + assert result["errors"] == {} + + # First attempt fails with name lookup failure when attempting to connect + discovery_mock.return_value.validate_connection.side_effect = ( + ControlPointInvalidHostError + ) + + result = await hass.config_entries.flow.async_configure( + result["flow_id"], + { + CONF_HOST: INPUT_HOST, + CONF_PORT: INPUT_PORT, + }, + ) + + assert result["type"] is FlowResultType.FORM + assert result["step_id"] + assert result["errors"] == {"base": "invalid_host"} + + # Second attempt succeeds + discovery_mock.return_value.validate_connection.side_effect = None + discovery_mock.return_value.validate_connection.return_value = ( + ControlPointDescription(host=INPUT_HOST, port=INPUT_PORT, mac=INPUT_MAC) + ) + + result = await hass.config_entries.flow.async_configure( + result["flow_id"], + { + CONF_HOST: INPUT_HOST, + CONF_PORT: INPUT_PORT, + }, + ) + + assert result["type"] is FlowResultType.CREATE_ENTRY + assert result["title"] == f"ZIMI Controller ({INPUT_HOST}:{INPUT_PORT})" + assert result["data"] == { + "host": INPUT_HOST, + "port": INPUT_PORT, + "mac": format_mac(INPUT_MAC), + } + + +@pytest.mark.parametrize( + ("side_effect", "error_expected"), + [ + ( + ControlPointInvalidHostError, + {"base": "invalid_host"}, + ), + ( + ControlPointConnectionRefusedError, + {"base": "connection_refused"}, + ), + ( + ControlPointCannotConnectError, + {"base": "cannot_connect"}, + ), + ( + ControlPointTimeoutError, + {"base": "timeout"}, + ), + ( + Exception, + {"base": "unknown"}, + ), + ], +) +async def test_manual_connection_errors( + hass: HomeAssistant, + discovery_mock: MagicMock, + side_effect: Exception, + error_expected: dict, +) -> None: + """Test manual form connection errors.""" + + discovery_mock.discovers.side_effect = ControlPointError("Discovery failed") + + result = await hass.config_entries.flow.async_init( + DOMAIN, context={"source": config_entries.SOURCE_USER} + ) + + assert result["type"] is FlowResultType.FORM + assert result["step_id"] == "manual" + assert result["errors"] == {} + + # First attempt fails with connection errors + discovery_mock.return_value.validate_connection.side_effect = side_effect + + result = await hass.config_entries.flow.async_configure( + result["flow_id"], + { + CONF_HOST: INPUT_HOST, + CONF_PORT: INPUT_PORT, + }, + ) + + assert result["type"] is FlowResultType.FORM + assert result["step_id"] == "manual" + assert result["errors"] == error_expected + + # Second attempt succeeds + discovery_mock.return_value.validate_connection.side_effect = None + discovery_mock.return_value.validate_connection.return_value = ( + ControlPointDescription(host=INPUT_HOST, port=INPUT_PORT, mac=INPUT_MAC) + ) + + result = await hass.config_entries.flow.async_configure( + result["flow_id"], + { + CONF_HOST: INPUT_HOST, + CONF_PORT: INPUT_PORT, + }, + ) + + assert result["type"] is FlowResultType.CREATE_ENTRY + assert result["title"] == f"ZIMI Controller ({INPUT_HOST}:{INPUT_PORT})" + assert result["data"] == { + "host": INPUT_HOST, + "port": INPUT_PORT, + "mac": format_mac(INPUT_MAC), + } From 2c368c79d124c061dda84b3dae39cf722f71396d Mon Sep 17 00:00:00 2001 From: Oliver <10700296+ol-iver@users.noreply.github.com> Date: Sun, 4 May 2025 16:41:44 +0200 Subject: [PATCH 57/90] Update `denonavr` to `1.1.0` (#144199) --- homeassistant/components/denonavr/manifest.json | 2 +- requirements_all.txt | 2 +- requirements_test_all.txt | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/denonavr/manifest.json b/homeassistant/components/denonavr/manifest.json index 328ab504bd1..3cf2e5b5bda 100644 --- a/homeassistant/components/denonavr/manifest.json +++ b/homeassistant/components/denonavr/manifest.json @@ -6,7 +6,7 @@ "documentation": "https://www.home-assistant.io/integrations/denonavr", "iot_class": "local_push", "loggers": ["denonavr"], - "requirements": ["denonavr==1.0.1"], + "requirements": ["denonavr==1.1.0"], "ssdp": [ { "manufacturer": "Denon", diff --git a/requirements_all.txt b/requirements_all.txt index 8f902317db7..e212af09a19 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -776,7 +776,7 @@ deluge-client==1.10.2 demetriek==1.2.0 # homeassistant.components.denonavr -denonavr==1.0.1 +denonavr==1.1.0 # homeassistant.components.devialet devialet==1.5.7 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index 79c1bcc79f2..e1d54e6f30b 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -667,7 +667,7 @@ deluge-client==1.10.2 demetriek==1.2.0 # homeassistant.components.denonavr -denonavr==1.0.1 +denonavr==1.1.0 # homeassistant.components.devialet devialet==1.5.7 From 11993532041d277411425b65cb3ae93a3fcc9023 Mon Sep 17 00:00:00 2001 From: Norbert Rittel Date: Sun, 4 May 2025 17:55:58 +0200 Subject: [PATCH 58/90] Fix sentence-casing of "Phone number" in `peco` (#144208) --- homeassistant/components/peco/strings.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/homeassistant/components/peco/strings.json b/homeassistant/components/peco/strings.json index cdf5bb497db..c4683056dd7 100644 --- a/homeassistant/components/peco/strings.json +++ b/homeassistant/components/peco/strings.json @@ -4,7 +4,7 @@ "user": { "data": { "county": "County", - "phone_number": "Phone Number" + "phone_number": "Phone number" }, "data_description": { "county": "County used for outage number retrieval", From 490bb46a8224487fc55214774dba5038c33e1f05 Mon Sep 17 00:00:00 2001 From: Norbert Rittel Date: Sun, 4 May 2025 17:56:25 +0200 Subject: [PATCH 59/90] Make spelling of "Auto-charge" switch consistent in TechnoVE (#144206) * Make spelling of "Auto-charge" switch consistent in TechnoVE Also fix sentence-casing in "Charging enabled" switch. * Update test_switch.ambr --- homeassistant/components/technove/strings.json | 4 ++-- tests/components/technove/snapshots/test_switch.ambr | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/homeassistant/components/technove/strings.json b/homeassistant/components/technove/strings.json index 05260845a03..29aba780f26 100644 --- a/homeassistant/components/technove/strings.json +++ b/homeassistant/components/technove/strings.json @@ -76,10 +76,10 @@ }, "switch": { "auto_charge": { - "name": "Auto charge" + "name": "Auto-charge" }, "session_active": { - "name": "Charging Enabled" + "name": "Charging enabled" } } }, diff --git a/tests/components/technove/snapshots/test_switch.ambr b/tests/components/technove/snapshots/test_switch.ambr index a5f8411747b..0e93143ffed 100644 --- a/tests/components/technove/snapshots/test_switch.ambr +++ b/tests/components/technove/snapshots/test_switch.ambr @@ -24,7 +24,7 @@ }), 'original_device_class': None, 'original_icon': None, - 'original_name': 'Auto charge', + 'original_name': 'Auto-charge', 'platform': 'technove', 'previous_unique_id': None, 'supported_features': 0, @@ -36,7 +36,7 @@ # name: test_switches[switch.technove_station_auto_charge-state] StateSnapshot({ 'attributes': ReadOnlyDict({ - 'friendly_name': 'TechnoVE Station Auto charge', + 'friendly_name': 'TechnoVE Station Auto-charge', }), 'context': , 'entity_id': 'switch.technove_station_auto_charge', @@ -71,7 +71,7 @@ }), 'original_device_class': None, 'original_icon': None, - 'original_name': 'Charging Enabled', + 'original_name': 'Charging enabled', 'platform': 'technove', 'previous_unique_id': None, 'supported_features': 0, @@ -83,7 +83,7 @@ # name: test_switches[switch.technove_station_charging_enabled-state] StateSnapshot({ 'attributes': ReadOnlyDict({ - 'friendly_name': 'TechnoVE Station Charging Enabled', + 'friendly_name': 'TechnoVE Station Charging enabled', }), 'context': , 'entity_id': 'switch.technove_station_charging_enabled', From 8048d2bfb846c10cac308aa438fc8bd906484a8d Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Sun, 4 May 2025 12:00:40 -0400 Subject: [PATCH 60/90] Fix intent TurnOn creating stack trace for buttons (#144205) --- homeassistant/components/intent/__init__.py | 28 +++- tests/components/intent/test_init.py | 135 ++++++++++++++++---- 2 files changed, 140 insertions(+), 23 deletions(-) diff --git a/homeassistant/components/intent/__init__.py b/homeassistant/components/intent/__init__.py index dfbe8d0135c..72853276ab3 100644 --- a/homeassistant/components/intent/__init__.py +++ b/homeassistant/components/intent/__init__.py @@ -10,6 +10,11 @@ from aiohttp import web import voluptuous as vol from homeassistant.components import http, sensor +from homeassistant.components.button import ( + DOMAIN as BUTTON_DOMAIN, + SERVICE_PRESS as SERVICE_PRESS_BUTTON, + ButtonDeviceClass, +) from homeassistant.components.climate import DOMAIN as CLIMATE_DOMAIN from homeassistant.components.cover import ( ATTR_POSITION, @@ -20,6 +25,7 @@ from homeassistant.components.cover import ( CoverDeviceClass, ) from homeassistant.components.http.data_validator import RequestDataValidator +from homeassistant.components.input_button import DOMAIN as INPUT_BUTTON_DOMAIN from homeassistant.components.lock import ( DOMAIN as LOCK_DOMAIN, SERVICE_LOCK, @@ -80,6 +86,7 @@ __all__ = [ ] ONOFF_DEVICE_CLASSES = { + ButtonDeviceClass, CoverDeviceClass, ValveDeviceClass, SwitchDeviceClass, @@ -103,7 +110,7 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: intent.INTENT_TURN_ON, HOMEASSISTANT_DOMAIN, SERVICE_TURN_ON, - description="Turns on/opens a device or entity. For locks, this performs a 'lock' action. Use for requests like 'turn on', 'activate', 'enable', or 'lock'.", + description="Turns on/opens/presses a device or entity. For locks, this performs a 'lock' action. Use for requests like 'turn on', 'activate', 'enable', or 'lock'.", device_classes=ONOFF_DEVICE_CLASSES, ), ) @@ -168,6 +175,25 @@ class OnOffIntentHandler(intent.ServiceIntentHandler): """Call service on entity with handling for special cases.""" hass = intent_obj.hass + if state.domain in (BUTTON_DOMAIN, INPUT_BUTTON_DOMAIN): + if service != SERVICE_TURN_ON: + raise intent.IntentHandleError( + f"Entity {state.entity_id} cannot be turned off" + ) + + await self._run_then_background( + hass.async_create_task( + hass.services.async_call( + state.domain, + SERVICE_PRESS_BUTTON, + {ATTR_ENTITY_ID: state.entity_id}, + context=intent_obj.context, + blocking=True, + ) + ) + ) + return + if state.domain == COVER_DOMAIN: # on = open # off = close diff --git a/tests/components/intent/test_init.py b/tests/components/intent/test_init.py index 0db9682d0ad..3779930e360 100644 --- a/tests/components/intent/test_init.py +++ b/tests/components/intent/test_init.py @@ -2,8 +2,10 @@ import pytest -from homeassistant.components.cover import SERVICE_OPEN_COVER -from homeassistant.components.lock import SERVICE_LOCK +from homeassistant.components.button import SERVICE_PRESS +from homeassistant.components.cover import SERVICE_CLOSE_COVER, SERVICE_OPEN_COVER +from homeassistant.components.lock import SERVICE_LOCK, SERVICE_UNLOCK +from homeassistant.components.valve import SERVICE_CLOSE_VALVE, SERVICE_OPEN_VALVE from homeassistant.const import ( ATTR_DEVICE_CLASS, ATTR_FRIENDLY_NAME, @@ -121,41 +123,130 @@ async def test_turn_on_intent(hass: HomeAssistant) -> None: assert call.data == {"entity_id": ["light.test_light"]} -async def test_translated_turn_on_intent( +@pytest.mark.parametrize("domain", ["button", "input_button"]) +async def test_turn_on_intent_button( + hass: HomeAssistant, entity_registry: er.EntityRegistry, domain +) -> None: + """Test HassTurnOn intent on button domains.""" + assert await async_setup_component(hass, "intent", {}) + + button = entity_registry.async_get_or_create(domain, "test", "button_uid") + + hass.states.async_set(button.entity_id, "unknown") + button_service_calls = async_mock_service(hass, domain, SERVICE_PRESS) + + with pytest.raises(intent.IntentHandleError): + await intent.async_handle( + hass, "test", "HassTurnOff", {"name": {"value": button.entity_id}} + ) + + await intent.async_handle( + hass, "test", "HassTurnOn", {"name": {"value": button.entity_id}} + ) + + assert len(button_service_calls) == 1 + call = button_service_calls[0] + assert call.domain == domain + assert call.service == SERVICE_PRESS + assert call.data == {"entity_id": button.entity_id} + + +async def test_turn_on_off_intent_valve( hass: HomeAssistant, entity_registry: er.EntityRegistry ) -> None: - """Test HassTurnOn intent on domains which don't have the intent.""" - result = await async_setup_component(hass, "homeassistant", {}) - result = await async_setup_component(hass, "intent", {}) - await hass.async_block_till_done() - assert result + """Test HassTurnOn/Off intent on valve domains.""" + assert await async_setup_component(hass, "intent", {}) + + valve = entity_registry.async_get_or_create("valve", "test", "valve_uid") + + hass.states.async_set(valve.entity_id, "closed") + open_calls = async_mock_service(hass, "valve", SERVICE_OPEN_VALVE) + close_calls = async_mock_service(hass, "valve", SERVICE_CLOSE_VALVE) + + await intent.async_handle( + hass, "test", "HassTurnOn", {"name": {"value": valve.entity_id}} + ) + + assert len(open_calls) == 1 + call = open_calls[0] + assert call.domain == "valve" + assert call.service == SERVICE_OPEN_VALVE + assert call.data == {"entity_id": valve.entity_id} + + await intent.async_handle( + hass, "test", "HassTurnOff", {"name": {"value": valve.entity_id}} + ) + + assert len(close_calls) == 1 + call = close_calls[0] + assert call.domain == "valve" + assert call.service == SERVICE_CLOSE_VALVE + assert call.data == {"entity_id": valve.entity_id} + + +async def test_turn_on_off_intent_cover( + hass: HomeAssistant, entity_registry: er.EntityRegistry +) -> None: + """Test HassTurnOn/Off intent on cover domains.""" + assert await async_setup_component(hass, "intent", {}) cover = entity_registry.async_get_or_create("cover", "test", "cover_uid") - lock = entity_registry.async_get_or_create("lock", "test", "lock_uid") hass.states.async_set(cover.entity_id, "closed") - hass.states.async_set(lock.entity_id, "unlocked") - cover_service_calls = async_mock_service(hass, "cover", SERVICE_OPEN_COVER) - lock_service_calls = async_mock_service(hass, "lock", SERVICE_LOCK) + open_calls = async_mock_service(hass, "cover", SERVICE_OPEN_COVER) + close_calls = async_mock_service(hass, "cover", SERVICE_CLOSE_COVER) await intent.async_handle( hass, "test", "HassTurnOn", {"name": {"value": cover.entity_id}} ) + + assert len(open_calls) == 1 + call = open_calls[0] + assert call.domain == "cover" + assert call.service == SERVICE_OPEN_COVER + assert call.data == {"entity_id": cover.entity_id} + + await intent.async_handle( + hass, "test", "HassTurnOff", {"name": {"value": cover.entity_id}} + ) + + assert len(close_calls) == 1 + call = close_calls[0] + assert call.domain == "cover" + assert call.service == SERVICE_CLOSE_COVER + assert call.data == {"entity_id": cover.entity_id} + + +async def test_turn_on_off_intent_lock( + hass: HomeAssistant, entity_registry: er.EntityRegistry +) -> None: + """Test HassTurnOn/Off intent on lock domains.""" + assert await async_setup_component(hass, "intent", {}) + + lock = entity_registry.async_get_or_create("lock", "test", "lock_uid") + + hass.states.async_set(lock.entity_id, "locked") + unlock_calls = async_mock_service(hass, "lock", SERVICE_UNLOCK) + lock_calls = async_mock_service(hass, "lock", SERVICE_LOCK) + await intent.async_handle( hass, "test", "HassTurnOn", {"name": {"value": lock.entity_id}} ) - await hass.async_block_till_done() - assert len(cover_service_calls) == 1 - call = cover_service_calls[0] - assert call.domain == "cover" - assert call.service == "open_cover" - assert call.data == {"entity_id": cover.entity_id} - - assert len(lock_service_calls) == 1 - call = lock_service_calls[0] + assert len(lock_calls) == 1 + call = lock_calls[0] assert call.domain == "lock" - assert call.service == "lock" + assert call.service == SERVICE_LOCK + assert call.data == {"entity_id": lock.entity_id} + + await intent.async_handle( + hass, "test", "HassTurnOff", {"name": {"value": lock.entity_id}} + ) + + assert len(unlock_calls) == 1 + call = unlock_calls[0] + assert call.domain == "lock" + assert call.service == SERVICE_UNLOCK assert call.data == {"entity_id": lock.entity_id} From 2960271b8155a08fba1990ec55cd2d143efa58db Mon Sep 17 00:00:00 2001 From: Pete Sage <76050312+PeteRager@users.noreply.github.com> Date: Sun, 4 May 2025 12:15:01 -0400 Subject: [PATCH 61/90] bump aiokem to 0.5.10 (#144203) --- homeassistant/components/rehlko/manifest.json | 2 +- requirements_all.txt | 2 +- requirements_test_all.txt | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/rehlko/manifest.json b/homeassistant/components/rehlko/manifest.json index 0c9f0c20e6f..6b2f6190883 100644 --- a/homeassistant/components/rehlko/manifest.json +++ b/homeassistant/components/rehlko/manifest.json @@ -13,5 +13,5 @@ "iot_class": "cloud_polling", "loggers": ["aiokem"], "quality_scale": "silver", - "requirements": ["aiokem==0.5.9"] + "requirements": ["aiokem==0.5.10"] } diff --git a/requirements_all.txt b/requirements_all.txt index e212af09a19..448c24d952c 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -286,7 +286,7 @@ aiokafka==0.10.0 aiokef==0.2.16 # homeassistant.components.rehlko -aiokem==0.5.9 +aiokem==0.5.10 # homeassistant.components.lifx aiolifx-effects==0.3.2 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index e1d54e6f30b..bcbbb58d94f 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -268,7 +268,7 @@ aioimaplib==2.0.1 aiokafka==0.10.0 # homeassistant.components.rehlko -aiokem==0.5.9 +aiokem==0.5.10 # homeassistant.components.lifx aiolifx-effects==0.3.2 From 9cd2080de2d9090a0a3bf3574a1197961df3c13e Mon Sep 17 00:00:00 2001 From: Pete Sage <76050312+PeteRager@users.noreply.github.com> Date: Sun, 4 May 2025 12:41:39 -0400 Subject: [PATCH 62/90] Avoid delaying HA startup in Rehlko (#144202) --- homeassistant/components/rehlko/__init__.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/rehlko/__init__.py b/homeassistant/components/rehlko/__init__.py index 19702527259..49ceb8ac870 100644 --- a/homeassistant/components/rehlko/__init__.py +++ b/homeassistant/components/rehlko/__init__.py @@ -40,7 +40,6 @@ async def async_setup_entry(hass: HomeAssistant, entry: RehlkoConfigEntry) -> bo ) rehlko.set_refresh_token_callback(async_refresh_token_update) - rehlko.set_retry_policy(retry_count=3, retry_delays=[5, 10, 20]) try: await rehlko.authenticate( @@ -48,6 +47,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: RehlkoConfigEntry) -> bo entry.data[CONF_PASSWORD], entry.data.get(CONF_REFRESH_TOKEN), ) + homes = await rehlko.get_homes() except AuthenticationError as ex: raise ConfigEntryAuthFailed( translation_domain=DOMAIN, @@ -60,7 +60,6 @@ async def async_setup_entry(hass: HomeAssistant, entry: RehlkoConfigEntry) -> bo translation_key="cannot_connect", ) from ex coordinators: dict[int, RehlkoUpdateCoordinator] = {} - homes = await rehlko.get_homes() entry.runtime_data = RehlkoRuntimeData( coordinators=coordinators, @@ -86,6 +85,8 @@ async def async_setup_entry(hass: HomeAssistant, entry: RehlkoConfigEntry) -> bo await coordinator.async_config_entry_first_refresh() coordinators[device_id] = coordinator await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS) + # Retrys enabled after successful connection to prevent blocking startup + rehlko.set_retry_policy(retry_count=3, retry_delays=[5, 10, 20]) return True From 429682cecd561e0ce4c95fd2779534edca517709 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sun, 4 May 2025 11:42:07 -0500 Subject: [PATCH 63/90] Remove unnecessary intermediate functions in `entry_data` for ESPHome (#144173) --- .../components/esphome/entry_data.py | 65 +++---------------- 1 file changed, 9 insertions(+), 56 deletions(-) diff --git a/homeassistant/components/esphome/entry_data.py b/homeassistant/components/esphome/entry_data.py index 023c6f70da4..1e6375d8caf 100644 --- a/homeassistant/components/esphome/entry_data.py +++ b/homeassistant/components/esphome/entry_data.py @@ -8,6 +8,7 @@ from collections.abc import Callable, Iterable from dataclasses import dataclass, field from functools import partial import logging +from operator import delitem from typing import TYPE_CHECKING, Any, Final, TypedDict, cast from aioesphomeapi import ( @@ -183,18 +184,7 @@ class RuntimeEntryData: """Register to receive callbacks when static info changes for an EntityInfo type.""" callbacks = self.entity_info_callbacks.setdefault(entity_info_type, []) callbacks.append(callback_) - return partial( - self._async_unsubscribe_register_static_info, callbacks, callback_ - ) - - @callback - def _async_unsubscribe_register_static_info( - self, - callbacks: list[Callable[[list[EntityInfo]], None]], - callback_: Callable[[list[EntityInfo]], None], - ) -> None: - """Unsubscribe to when static info is registered.""" - callbacks.remove(callback_) + return partial(callbacks.remove, callback_) @callback def async_register_key_static_info_updated_callback( @@ -206,18 +196,7 @@ class RuntimeEntryData: callback_key = (type(static_info), static_info.key) callbacks = self.entity_info_key_updated_callbacks.setdefault(callback_key, []) callbacks.append(callback_) - return partial( - self._async_unsubscribe_static_key_info_updated, callbacks, callback_ - ) - - @callback - def _async_unsubscribe_static_key_info_updated( - self, - callbacks: list[Callable[[EntityInfo], None]], - callback_: Callable[[EntityInfo], None], - ) -> None: - """Unsubscribe to when static info is updated .""" - callbacks.remove(callback_) + return partial(callbacks.remove, callback_) @callback def async_set_assist_pipeline_state(self, state: bool) -> None: @@ -232,14 +211,7 @@ class RuntimeEntryData: ) -> CALLBACK_TYPE: """Subscribe to assist pipeline updates.""" self.assist_pipeline_update_callbacks.append(update_callback) - return partial(self._async_unsubscribe_assist_pipeline_update, update_callback) - - @callback - def _async_unsubscribe_assist_pipeline_update( - self, update_callback: CALLBACK_TYPE - ) -> None: - """Unsubscribe to assist pipeline updates.""" - self.assist_pipeline_update_callbacks.remove(update_callback) + return partial(self.assist_pipeline_update_callbacks.remove, update_callback) @callback def async_remove_entities( @@ -337,12 +309,7 @@ class RuntimeEntryData: def async_subscribe_device_updated(self, callback_: CALLBACK_TYPE) -> CALLBACK_TYPE: """Subscribe to state updates.""" self.device_update_subscriptions.add(callback_) - return partial(self._async_unsubscribe_device_update, callback_) - - @callback - def _async_unsubscribe_device_update(self, callback_: CALLBACK_TYPE) -> None: - """Unsubscribe to device updates.""" - self.device_update_subscriptions.remove(callback_) + return partial(self.device_update_subscriptions.remove, callback_) @callback def async_subscribe_static_info_updated( @@ -350,14 +317,7 @@ class RuntimeEntryData: ) -> CALLBACK_TYPE: """Subscribe to static info updates.""" self.static_info_update_subscriptions.add(callback_) - return partial(self._async_unsubscribe_static_info_updated, callback_) - - @callback - def _async_unsubscribe_static_info_updated( - self, callback_: Callable[[list[EntityInfo]], None] - ) -> None: - """Unsubscribe to static info updates.""" - self.static_info_update_subscriptions.remove(callback_) + return partial(self.static_info_update_subscriptions.remove, callback_) @callback def async_subscribe_state_update( @@ -369,14 +329,7 @@ class RuntimeEntryData: """Subscribe to state updates.""" subscription_key = (state_type, state_key) self.state_subscriptions[subscription_key] = entity_callback - return partial(self._async_unsubscribe_state_update, subscription_key) - - @callback - def _async_unsubscribe_state_update( - self, subscription_key: tuple[type[EntityState], int] - ) -> None: - """Unsubscribe to state updates.""" - self.state_subscriptions.pop(subscription_key) + return partial(delitem, self.state_subscriptions, subscription_key) @callback def async_update_state(self, state: EntityState) -> None: @@ -523,7 +476,7 @@ class RuntimeEntryData: ) -> CALLBACK_TYPE: """Register to receive callbacks when the Assist satellite's configuration is updated.""" self.assist_satellite_config_update_callbacks.append(callback_) - return lambda: self.assist_satellite_config_update_callbacks.remove(callback_) + return partial(self.assist_satellite_config_update_callbacks.remove, callback_) @callback def async_assist_satellite_config_updated( @@ -540,7 +493,7 @@ class RuntimeEntryData: ) -> CALLBACK_TYPE: """Register to receive callbacks when the Assist satellite's wake word is set.""" self.assist_satellite_set_wake_word_callbacks.append(callback_) - return lambda: self.assist_satellite_set_wake_word_callbacks.remove(callback_) + return partial(self.assist_satellite_set_wake_word_callbacks.remove, callback_) @callback def async_assist_satellite_set_wake_word(self, wake_word_id: str) -> None: From 8e202bc202898efd316548d0c3b4169a891fb697 Mon Sep 17 00:00:00 2001 From: Norbert Rittel Date: Sun, 4 May 2025 19:13:53 +0200 Subject: [PATCH 64/90] Improve the user-facing strings of `heos` (#144218) --- homeassistant/components/heos/strings.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/heos/strings.json b/homeassistant/components/heos/strings.json index c99d73a70d7..76b71f70e28 100644 --- a/homeassistant/components/heos/strings.json +++ b/homeassistant/components/heos/strings.json @@ -56,8 +56,8 @@ "options": { "step": { "init": { - "title": "HEOS Options", - "description": "You can sign-in to your HEOS Account to access favorites, streaming services, and other features. Clearing the credentials will sign-out of your account.", + "title": "HEOS options", + "description": "You can sign in to your HEOS Account to access favorites, streaming services, and other features. Clearing the credentials will sign out of your account.", "data": { "username": "[%key:common::config_flow::data::username%]", "password": "[%key:common::config_flow::data::password%]" @@ -102,7 +102,7 @@ }, "move_queue_item": { "name": "Move queue item", - "description": "Move one or more items within the play queue.", + "description": "Moves one or more items within the play queue.", "fields": { "queue_ids": { "name": "Queue IDs", From eca811d0d476a74ea23fa0b6d900805d9a0bbf50 Mon Sep 17 00:00:00 2001 From: Norbert Rittel Date: Sun, 4 May 2025 19:35:59 +0200 Subject: [PATCH 65/90] Fix sentence-casing in user-facing strings of `tami4` (#144212) Fix sentence-casing in user-facing string of `tami4` --- homeassistant/components/tami4/strings.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/tami4/strings.json b/homeassistant/components/tami4/strings.json index 040c18fc56d..b89ccbe8bd9 100644 --- a/homeassistant/components/tami4/strings.json +++ b/homeassistant/components/tami4/strings.json @@ -29,17 +29,17 @@ "config": { "step": { "user": { - "title": "SMS Verification", + "title": "SMS verification", "description": "Enter your phone number (same as what you used to register to the tami4 app)", "data": { - "phone": "Phone Number" + "phone": "Phone number" } }, "otp": { "title": "[%key:component::tami4::config::step::user::title%]", "description": "Enter the code you received via SMS", "data": { - "otp": "SMS Code" + "otp": "SMS code" } } }, From 2e7b60c3cae87e9a82597f5c838f6ce757e9fb64 Mon Sep 17 00:00:00 2001 From: Norbert Rittel Date: Sun, 4 May 2025 19:36:24 +0200 Subject: [PATCH 66/90] Fix spelling of "sign in" and "setup" in `verisure` (#144214) - use "sign in" for the verb - use "setup" for the noun - fix sentence-casing of "Verification code" --- homeassistant/components/verisure/strings.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/verisure/strings.json b/homeassistant/components/verisure/strings.json index 051f17262a0..6241225ed4e 100644 --- a/homeassistant/components/verisure/strings.json +++ b/homeassistant/components/verisure/strings.json @@ -3,7 +3,7 @@ "step": { "user": { "data": { - "description": "Sign-in with your Verisure My Pages account.", + "description": "Sign in with your Verisure My Pages account.", "email": "[%key:common::config_flow::data::email%]", "password": "[%key:common::config_flow::data::password%]" } @@ -11,7 +11,7 @@ "mfa": { "data": { "description": "Your account has 2-step verification enabled. Please enter the verification code Verisure sends to you.", - "code": "Verification Code" + "code": "Verification code" } }, "installation": { @@ -37,7 +37,7 @@ "error": { "invalid_auth": "[%key:common::config_flow::error::invalid_auth%]", "unknown": "[%key:common::config_flow::error::unknown%]", - "unknown_mfa": "Unknown error occurred during MFA set up" + "unknown_mfa": "Unknown error occurred during MFA setup" }, "abort": { "already_configured": "[%key:common::config_flow::abort::already_configured_account%]", From c2a69bcb20298820cf040d4156f341b310efa197 Mon Sep 17 00:00:00 2001 From: Norbert Rittel Date: Sun, 4 May 2025 19:36:57 +0200 Subject: [PATCH 67/90] Improve user-facing strings of `blink` (#144219) - treat "sign in" as verb for consistency, removing the hyphen - fix sentence-casing of two strings --- homeassistant/components/blink/strings.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/blink/strings.json b/homeassistant/components/blink/strings.json index 74f8ae1cb28..8f8df125aab 100644 --- a/homeassistant/components/blink/strings.json +++ b/homeassistant/components/blink/strings.json @@ -2,7 +2,7 @@ "config": { "step": { "user": { - "title": "Sign-in with Blink account", + "title": "Sign in with Blink account", "data": { "username": "[%key:common::config_flow::data::username%]", "password": "[%key:common::config_flow::data::password%]" @@ -30,7 +30,7 @@ "step": { "simple_options": { "data": { - "scan_interval": "Scan Interval (seconds)" + "scan_interval": "Scan interval (seconds)" }, "title": "Blink options", "description": "Configure Blink integration" @@ -93,7 +93,7 @@ }, "config_entry_id": { "name": "Integration ID", - "description": "The Blink Integration ID." + "description": "The Blink integration ID." } } } From 9b30f32cad144e10f023d5d962b44d5a29bad251 Mon Sep 17 00:00:00 2001 From: Norbert Rittel Date: Sun, 4 May 2025 20:12:01 +0200 Subject: [PATCH 68/90] =?UTF-8?q?Replace=20"Sign-in=20=E2=80=A6"=20with=20?= =?UTF-8?q?"Sign=20in=20=E2=80=A6"=20in=20`ring`=20(#144222)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The config flow titles in Home Assistant use verbs by default ("Set up …" / "Configure …" / "Select …" etc. Therefore "Sign-in …" (noun) for the initial setup in `ring` is replaced with "Sign in …" (verb). --- homeassistant/components/ring/strings.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/homeassistant/components/ring/strings.json b/homeassistant/components/ring/strings.json index 2d7e0b17da1..d1a3deafa71 100644 --- a/homeassistant/components/ring/strings.json +++ b/homeassistant/components/ring/strings.json @@ -2,7 +2,7 @@ "config": { "step": { "user": { - "title": "Sign-in with Ring account", + "title": "Sign in with Ring account", "data": { "username": "[%key:common::config_flow::data::username%]", "password": "[%key:common::config_flow::data::password%]" From 8eaddbf2b237db9c330c2ff42d6ee7b5e92a0e47 Mon Sep 17 00:00:00 2001 From: Norbert Rittel Date: Sun, 4 May 2025 20:56:33 +0200 Subject: [PATCH 69/90] Replace "log-in" with "log in" in `zwave_me` (#144223) --- homeassistant/components/zwave_me/strings.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/homeassistant/components/zwave_me/strings.json b/homeassistant/components/zwave_me/strings.json index 0c5a1d30976..9bc0d2b8ab7 100644 --- a/homeassistant/components/zwave_me/strings.json +++ b/homeassistant/components/zwave_me/strings.json @@ -2,7 +2,7 @@ "config": { "step": { "user": { - "description": "Input IP address with port and access token of Z-Way server. To get the token go to the Z-Way user interface Smart Home UI > Menu > Settings > Users > Administrator > API token.\n\nExample of connecting to Z-Way running as an add-on:\nURL: {add_on_url}\nToken: {local_token}\n\nExample of connecting to Z-Way in the local network:\nURL: {local_url}\nToken: {local_token}\n\nExample of connecting to Z-Way via remote access find.z-wave.me:\nURL: {find_url}\nToken: {find_token}\n\nExample of connecting to Z-Way with a static public IP address:\nURL: {remote_url}\nToken: {local_token}\n\nWhen connecting via find.z-wave.me you need to use a token with a global scope (log-in to Z-Way via find.z-wave.me for this).", + "description": "Input IP address with port and access token of Z-Way server. To get the token go to the Z-Way user interface Smart Home UI > Menu > Settings > Users > Administrator > API token.\n\nExample of connecting to Z-Way running as an add-on:\nURL: {add_on_url}\nToken: {local_token}\n\nExample of connecting to Z-Way in the local network:\nURL: {local_url}\nToken: {local_token}\n\nExample of connecting to Z-Way via remote access find.z-wave.me:\nURL: {find_url}\nToken: {find_token}\n\nExample of connecting to Z-Way with a static public IP address:\nURL: {remote_url}\nToken: {local_token}\n\nWhen connecting via find.z-wave.me you need to use a token with a global scope (log in to Z-Way via find.z-wave.me for this).", "data": { "url": "[%key:common::config_flow::data::url%]", "token": "[%key:common::config_flow::data::api_token%]" From cad2d72ed98f8ae145fc13ac056420c6cdca3cd4 Mon Sep 17 00:00:00 2001 From: Luke Lashley Date: Sun, 4 May 2025 19:59:49 -0400 Subject: [PATCH 70/90] Bump python-roborock to 2.18.2 (#144235) --- homeassistant/components/roborock/manifest.json | 2 +- requirements_all.txt | 2 +- requirements_test_all.txt | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/roborock/manifest.json b/homeassistant/components/roborock/manifest.json index 531590d5d6e..784d2c6ad27 100644 --- a/homeassistant/components/roborock/manifest.json +++ b/homeassistant/components/roborock/manifest.json @@ -19,7 +19,7 @@ "loggers": ["roborock"], "quality_scale": "silver", "requirements": [ - "python-roborock==2.16.1", + "python-roborock==2.18.2", "vacuum-map-parser-roborock==0.1.2" ] } diff --git a/requirements_all.txt b/requirements_all.txt index 448c24d952c..74b9dc12407 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -2480,7 +2480,7 @@ python-rabbitair==0.0.8 python-ripple-api==0.0.3 # homeassistant.components.roborock -python-roborock==2.16.1 +python-roborock==2.18.2 # homeassistant.components.smarttub python-smarttub==0.0.39 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index bcbbb58d94f..c21f56d0f68 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -2017,7 +2017,7 @@ python-picnic-api2==1.2.4 python-rabbitair==0.0.8 # homeassistant.components.roborock -python-roborock==2.16.1 +python-roborock==2.18.2 # homeassistant.components.smarttub python-smarttub==0.0.39 From e0916fdd26ad97db0a0978627f81318814b9e230 Mon Sep 17 00:00:00 2001 From: Luke Lashley Date: Sun, 4 May 2025 23:02:32 -0400 Subject: [PATCH 71/90] Change roborock to use home_data_v3 (#144238) --- homeassistant/components/roborock/__init__.py | 2 +- tests/components/roborock/conftest.py | 4 ++-- tests/components/roborock/test_init.py | 16 ++++++++-------- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/homeassistant/components/roborock/__init__.py b/homeassistant/components/roborock/__init__.py index 81b412c6770..6697779adf6 100644 --- a/homeassistant/components/roborock/__init__.py +++ b/homeassistant/components/roborock/__init__.py @@ -53,7 +53,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: RoborockConfigEntry) -> ) _LOGGER.debug("Getting home data") try: - home_data = await api_client.get_home_data_v2(user_data) + home_data = await api_client.get_home_data_v3(user_data) except RoborockInvalidCredentials as err: raise ConfigEntryAuthFailed( "Invalid credentials", diff --git a/tests/components/roborock/conftest.py b/tests/components/roborock/conftest.py index d807e35710b..f95e4795d1d 100644 --- a/tests/components/roborock/conftest.py +++ b/tests/components/roborock/conftest.py @@ -72,7 +72,7 @@ def bypass_api_client_fixture() -> None: """Skip calls to the API client.""" with ( patch( - "homeassistant.components.roborock.RoborockApiClient.get_home_data_v2", + "homeassistant.components.roborock.RoborockApiClient.get_home_data_v3", return_value=HOME_DATA, ), patch( @@ -183,7 +183,7 @@ def bypass_api_fixture_v1_only(bypass_api_fixture) -> None: home_data_copy = deepcopy(HOME_DATA) home_data_copy.received_devices = [] with patch( - "homeassistant.components.roborock.RoborockApiClient.get_home_data_v2", + "homeassistant.components.roborock.RoborockApiClient.get_home_data_v3", return_value=home_data_copy, ): yield diff --git a/tests/components/roborock/test_init.py b/tests/components/roborock/test_init.py index a1bcfc462e4..01a8aa26de7 100644 --- a/tests/components/roborock/test_init.py +++ b/tests/components/roborock/test_init.py @@ -54,7 +54,7 @@ async def test_config_entry_not_ready( """Test that when coordinator update fails, entry retries.""" with ( patch( - "homeassistant.components.roborock.RoborockApiClient.get_home_data_v2", + "homeassistant.components.roborock.RoborockApiClient.get_home_data_v3", ), patch( "homeassistant.components.roborock.coordinator.RoborockLocalClientV1.get_prop", @@ -71,7 +71,7 @@ async def test_config_entry_not_ready_home_data( """Test that when we fail to get home data, entry retries.""" with ( patch( - "homeassistant.components.roborock.RoborockApiClient.get_home_data_v2", + "homeassistant.components.roborock.RoborockApiClient.get_home_data_v3", side_effect=RoborockException(), ), patch( @@ -164,7 +164,7 @@ async def test_reauth_started( ) -> None: """Test reauth flow started.""" with patch( - "homeassistant.components.roborock.RoborockApiClient.get_home_data_v2", + "homeassistant.components.roborock.RoborockApiClient.get_home_data_v3", side_effect=RoborockInvalidCredentials(), ): await async_setup_component(hass, DOMAIN, {}) @@ -249,7 +249,7 @@ async def test_not_supported_protocol( home_data_copy = deepcopy(HOME_DATA) home_data_copy.received_devices[0].pv = "random" with patch( - "homeassistant.components.roborock.RoborockApiClient.get_home_data_v2", + "homeassistant.components.roborock.RoborockApiClient.get_home_data_v3", return_value=home_data_copy, ): await hass.config_entries.async_setup(mock_roborock_entry.entry_id) @@ -267,7 +267,7 @@ async def test_not_supported_a01_device( home_data_copy = deepcopy(HOME_DATA) home_data_copy.products[2].category = "random" with patch( - "homeassistant.components.roborock.RoborockApiClient.get_home_data_v2", + "homeassistant.components.roborock.RoborockApiClient.get_home_data_v3", return_value=home_data_copy, ): await async_setup_component(hass, DOMAIN, {}) @@ -282,7 +282,7 @@ async def test_invalid_user_agreement( ) -> None: """Test that we fail setting up if the user agreement is out of date.""" with patch( - "homeassistant.components.roborock.RoborockApiClient.get_home_data_v2", + "homeassistant.components.roborock.RoborockApiClient.get_home_data_v3", side_effect=RoborockInvalidUserAgreement(), ): await hass.config_entries.async_setup(mock_roborock_entry.entry_id) @@ -299,7 +299,7 @@ async def test_no_user_agreement( ) -> None: """Test that we fail setting up if the user has no agreement.""" with patch( - "homeassistant.components.roborock.RoborockApiClient.get_home_data_v2", + "homeassistant.components.roborock.RoborockApiClient.get_home_data_v3", side_effect=RoborockNoUserAgreement(), ): await hass.config_entries.async_setup(mock_roborock_entry.entry_id) @@ -330,7 +330,7 @@ async def test_stale_device( with ( patch( - "homeassistant.components.roborock.RoborockApiClient.get_home_data_v2", + "homeassistant.components.roborock.RoborockApiClient.get_home_data_v3", return_value=hd, ), patch( From c6b9a40234c4f621d8159da94eb2c799634b3065 Mon Sep 17 00:00:00 2001 From: Allen Porter Date: Sun, 4 May 2025 20:05:33 -0700 Subject: [PATCH 72/90] Increase the local calendar update interval to avoid re-parsing the calendar state unnecessarily (#144234) --- homeassistant/components/local_calendar/calendar.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/homeassistant/components/local_calendar/calendar.py b/homeassistant/components/local_calendar/calendar.py index df6f994a46c..252fe703d6c 100644 --- a/homeassistant/components/local_calendar/calendar.py +++ b/homeassistant/components/local_calendar/calendar.py @@ -36,6 +36,11 @@ _LOGGER = logging.getLogger(__name__) PRODID = "-//homeassistant.io//local_calendar 1.0//EN" +# The calendar on disk is only changed when this entity is updated, so there +# is no need to poll for changes. The calendar enttiy base class will handle +# refreshing the entity state based on the start or end time of the event. +SCAN_INTERVAL = timedelta(days=1) + async def async_setup_entry( hass: HomeAssistant, From 68d62ab58e3d63502da90acfba21f1553bbd90ab Mon Sep 17 00:00:00 2001 From: Allen Porter Date: Sun, 4 May 2025 20:06:27 -0700 Subject: [PATCH 73/90] Update local calendar to process calendar events in the executor (#144233) --- .../components/local_calendar/calendar.py | 29 ++++++++++++------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/homeassistant/components/local_calendar/calendar.py b/homeassistant/components/local_calendar/calendar.py index 252fe703d6c..8534cc1bfbf 100644 --- a/homeassistant/components/local_calendar/calendar.py +++ b/homeassistant/components/local_calendar/calendar.py @@ -94,20 +94,27 @@ class LocalCalendarEntity(CalendarEntity): self, hass: HomeAssistant, start_date: datetime, end_date: datetime ) -> list[CalendarEvent]: """Get all events in a specific time frame.""" - events = self._calendar.timeline_tz(start_date.tzinfo).overlapping( - start_date, - end_date, - ) - return [_get_calendar_event(event) for event in events] + + def events_in_range() -> list[CalendarEvent]: + events = self._calendar.timeline_tz(start_date.tzinfo).overlapping( + start_date, + end_date, + ) + return [_get_calendar_event(event) for event in events] + + return await self.hass.async_add_executor_job(events_in_range) async def async_update(self) -> None: """Update entity state with the next upcoming event.""" - now = dt_util.now() - events = self._calendar.timeline_tz(now.tzinfo).active_after(now) - if event := next(events, None): - self._event = _get_calendar_event(event) - else: - self._event = None + + def next_event() -> CalendarEvent | None: + now = dt_util.now() + events = self._calendar.timeline_tz(now.tzinfo).active_after(now) + if event := next(events, None): + return _get_calendar_event(event) + return None + + self._event = await self.hass.async_add_executor_job(next_event) async def _async_store(self) -> None: """Persist the calendar to disk.""" From fa6a2f08ab2c49775b3c0e12ff0c77d5db92bd19 Mon Sep 17 00:00:00 2001 From: Allen Porter Date: Sun, 4 May 2025 20:07:02 -0700 Subject: [PATCH 74/90] Update remote calendar to do all event handling in an executor (#144232) --- .../components/remote_calendar/calendar.py | 43 ++++++++++++++----- 1 file changed, 32 insertions(+), 11 deletions(-) diff --git a/homeassistant/components/remote_calendar/calendar.py b/homeassistant/components/remote_calendar/calendar.py index bd83a5f18cc..2f60918f010 100644 --- a/homeassistant/components/remote_calendar/calendar.py +++ b/homeassistant/components/remote_calendar/calendar.py @@ -29,7 +29,7 @@ async def async_setup_entry( """Set up the remote calendar platform.""" coordinator = entry.runtime_data entity = RemoteCalendarEntity(coordinator, entry) - async_add_entities([entity]) + async_add_entities([entity], True) class RemoteCalendarEntity( @@ -48,25 +48,46 @@ class RemoteCalendarEntity( super().__init__(coordinator) self._attr_name = entry.data[CONF_CALENDAR_NAME] self._attr_unique_id = entry.entry_id + self._event: CalendarEvent | None = None @property def event(self) -> CalendarEvent | None: """Return the next upcoming event.""" - now = dt_util.now() - events = self.coordinator.data.timeline_tz(now.tzinfo).active_after(now) - if event := next(events, None): - return _get_calendar_event(event) - return None + return self._event async def async_get_events( self, hass: HomeAssistant, start_date: datetime, end_date: datetime ) -> list[CalendarEvent]: """Get all events in a specific time frame.""" - events = self.coordinator.data.timeline_tz(start_date.tzinfo).overlapping( - start_date, - end_date, - ) - return [_get_calendar_event(event) for event in events] + + def events_in_range() -> list[CalendarEvent]: + """Return all events in the given time range.""" + events = self.coordinator.data.timeline_tz(start_date.tzinfo).overlapping( + start_date, + end_date, + ) + return [_get_calendar_event(event) for event in events] + + return await self.hass.async_add_executor_job(events_in_range) + + async def async_update(self) -> None: + """Refresh the timeline. + + This is called when the coordinator updates. Creating the timeline may + require walking through the entire calendar and handling recurring + events, so it is done as a separate task without blocking the event loop. + """ + await super().async_update() + + def next_timeline_event() -> CalendarEvent | None: + """Return the next active event.""" + now = dt_util.now() + events = self.coordinator.data.timeline_tz(now.tzinfo).active_after(now) + if event := next(events, None): + return _get_calendar_event(event) + return None + + self._event = await self.hass.async_add_executor_job(next_timeline_event) def _get_calendar_event(event: Event) -> CalendarEvent: From e2a813714079d53b5eeff53227cb7933cb4f1bf1 Mon Sep 17 00:00:00 2001 From: Allen Porter Date: Sun, 4 May 2025 20:40:49 -0700 Subject: [PATCH 75/90] Bump ical to 9.2.0 (#144240) --- homeassistant/components/google/manifest.json | 2 +- homeassistant/components/local_calendar/manifest.json | 2 +- homeassistant/components/local_todo/manifest.json | 2 +- homeassistant/components/remote_calendar/manifest.json | 2 +- requirements_all.txt | 2 +- requirements_test_all.txt | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/homeassistant/components/google/manifest.json b/homeassistant/components/google/manifest.json index 2bedc7a3163..32af3e675b3 100644 --- a/homeassistant/components/google/manifest.json +++ b/homeassistant/components/google/manifest.json @@ -7,5 +7,5 @@ "documentation": "https://www.home-assistant.io/integrations/google", "iot_class": "cloud_polling", "loggers": ["googleapiclient"], - "requirements": ["gcal-sync==7.0.0", "oauth2client==4.1.3", "ical==9.1.0"] + "requirements": ["gcal-sync==7.0.0", "oauth2client==4.1.3", "ical==9.2.0"] } diff --git a/homeassistant/components/local_calendar/manifest.json b/homeassistant/components/local_calendar/manifest.json index 90cd5a6d2ac..eba26e88d5a 100644 --- a/homeassistant/components/local_calendar/manifest.json +++ b/homeassistant/components/local_calendar/manifest.json @@ -7,5 +7,5 @@ "documentation": "https://www.home-assistant.io/integrations/local_calendar", "iot_class": "local_polling", "loggers": ["ical"], - "requirements": ["ical==9.1.0"] + "requirements": ["ical==9.2.0"] } diff --git a/homeassistant/components/local_todo/manifest.json b/homeassistant/components/local_todo/manifest.json index a630c18c669..fb48ca72337 100644 --- a/homeassistant/components/local_todo/manifest.json +++ b/homeassistant/components/local_todo/manifest.json @@ -5,5 +5,5 @@ "config_flow": true, "documentation": "https://www.home-assistant.io/integrations/local_todo", "iot_class": "local_polling", - "requirements": ["ical==9.1.0"] + "requirements": ["ical==9.2.0"] } diff --git a/homeassistant/components/remote_calendar/manifest.json b/homeassistant/components/remote_calendar/manifest.json index da078395484..b31fa3389dc 100644 --- a/homeassistant/components/remote_calendar/manifest.json +++ b/homeassistant/components/remote_calendar/manifest.json @@ -8,5 +8,5 @@ "iot_class": "cloud_polling", "loggers": ["ical"], "quality_scale": "silver", - "requirements": ["ical==9.1.0"] + "requirements": ["ical==9.2.0"] } diff --git a/requirements_all.txt b/requirements_all.txt index 74b9dc12407..8ebee15acc5 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -1200,7 +1200,7 @@ ibmiotf==0.3.4 # homeassistant.components.local_calendar # homeassistant.components.local_todo # homeassistant.components.remote_calendar -ical==9.1.0 +ical==9.2.0 # homeassistant.components.caldav icalendar==6.1.0 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index c21f56d0f68..cadd68bb101 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -1021,7 +1021,7 @@ ibeacon-ble==1.2.0 # homeassistant.components.local_calendar # homeassistant.components.local_todo # homeassistant.components.remote_calendar -ical==9.1.0 +ical==9.2.0 # homeassistant.components.caldav icalendar==6.1.0 From e3b3c32751007a73ec4743e222f1a92a19a49756 Mon Sep 17 00:00:00 2001 From: Brett Adams Date: Mon, 5 May 2025 14:28:01 +1000 Subject: [PATCH 76/90] Add valet switch to Teslemetry (#144167) * Add valet switch * Add snapshot --- homeassistant/components/teslemetry/switch.py | 10 +++ .../teslemetry/snapshots/test_switch.ambr | 62 +++++++++++++++++++ 2 files changed, 72 insertions(+) diff --git a/homeassistant/components/teslemetry/switch.py b/homeassistant/components/teslemetry/switch.py index acd17ac4165..f1082122e5c 100644 --- a/homeassistant/components/teslemetry/switch.py +++ b/homeassistant/components/teslemetry/switch.py @@ -60,6 +60,16 @@ VEHICLE_DESCRIPTIONS: tuple[TeslemetrySwitchEntityDescription, ...] = ( off_func=lambda api: api.set_sentry_mode(on=False), scopes=[Scope.VEHICLE_CMDS], ), + TeslemetrySwitchEntityDescription( + key="vehicle_state_valet_mode", + streaming_listener=lambda vehicle, value: vehicle.listen_ValetModeEnabled( + value + ), + streaming_firmware="2024.44.25", + on_func=lambda api: api.set_valet_mode(on=True, password=""), + off_func=lambda api: api.set_valet_mode(on=False, password=""), + scopes=[Scope.VEHICLE_CMDS], + ), TeslemetrySwitchEntityDescription( key="climate_state_auto_seat_climate_left", streaming_listener=lambda vehicle, callback: vehicle.listen_AutoSeatClimateLeft( diff --git a/tests/components/teslemetry/snapshots/test_switch.ambr b/tests/components/teslemetry/snapshots/test_switch.ambr index 0586b454a91..ffbfc06026e 100644 --- a/tests/components/teslemetry/snapshots/test_switch.ambr +++ b/tests/components/teslemetry/snapshots/test_switch.ambr @@ -383,6 +383,54 @@ 'state': 'off', }) # --- +# name: test_switch[switch.test_valet_mode-entry] + EntityRegistryEntrySnapshot({ + 'aliases': set({ + }), + 'area_id': None, + 'capabilities': None, + 'config_entry_id': , + 'config_subentry_id': , + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'switch', + 'entity_category': None, + 'entity_id': 'switch.test_valet_mode', + 'has_entity_name': True, + 'hidden_by': None, + 'icon': None, + 'id': , + 'labels': set({ + }), + 'name': None, + 'options': dict({ + }), + 'original_device_class': , + 'original_icon': None, + 'original_name': 'Valet mode', + 'platform': 'teslemetry', + 'previous_unique_id': None, + 'supported_features': 0, + 'translation_key': 'vehicle_state_valet_mode', + 'unique_id': 'LRW3F7EK4NC700000-vehicle_state_valet_mode', + 'unit_of_measurement': None, + }) +# --- +# name: test_switch[switch.test_valet_mode-state] + StateSnapshot({ + 'attributes': ReadOnlyDict({ + 'device_class': 'switch', + 'friendly_name': 'Test Valet mode', + }), + 'context': , + 'entity_id': 'switch.test_valet_mode', + 'last_changed': , + 'last_reported': , + 'last_updated': , + 'state': 'off', + }) +# --- # name: test_switch_alt[switch.energy_site_allow_charging_from_grid-statealt] StateSnapshot({ 'attributes': ReadOnlyDict({ @@ -495,6 +543,20 @@ 'state': 'off', }) # --- +# name: test_switch_alt[switch.test_valet_mode-statealt] + StateSnapshot({ + 'attributes': ReadOnlyDict({ + 'device_class': 'switch', + 'friendly_name': 'Test Valet mode', + }), + 'context': , + 'entity_id': 'switch.test_valet_mode', + 'last_changed': , + 'last_reported': , + 'last_updated': , + 'state': 'off', + }) +# --- # name: test_switch_streaming[switch.test_auto_seat_climate_left] 'on' # --- From 41ecb24135193935235510f09fa731fbe852d173 Mon Sep 17 00:00:00 2001 From: Brett Adams Date: Mon, 5 May 2025 14:54:00 +1000 Subject: [PATCH 77/90] Set api type more specifically in Teslemetry (#144178) * Set api type more specifically * remove extra spacing * Fix class after rebase --------- Co-authored-by: Allen Porter --- homeassistant/components/teslemetry/button.py | 2 ++ homeassistant/components/teslemetry/climate.py | 2 -- homeassistant/components/teslemetry/cover.py | 6 ++++++ homeassistant/components/teslemetry/entity.py | 3 ++- homeassistant/components/teslemetry/lock.py | 5 +++++ homeassistant/components/teslemetry/media_player.py | 1 - homeassistant/components/teslemetry/number.py | 1 + homeassistant/components/teslemetry/select.py | 1 + homeassistant/components/teslemetry/switch.py | 7 ++++--- 9 files changed, 21 insertions(+), 7 deletions(-) diff --git a/homeassistant/components/teslemetry/button.py b/homeassistant/components/teslemetry/button.py index 6cb9d996b95..2de2868551b 100644 --- a/homeassistant/components/teslemetry/button.py +++ b/homeassistant/components/teslemetry/button.py @@ -7,6 +7,7 @@ from dataclasses import dataclass from typing import Any from tesla_fleet_api.const import Scope +from tesla_fleet_api.teslemetry import Vehicle from homeassistant.components.button import ButtonEntity, ButtonEntityDescription from homeassistant.core import HomeAssistant @@ -76,6 +77,7 @@ async def async_setup_entry( class TeslemetryButtonEntity(TeslemetryVehiclePollingEntity, ButtonEntity): """Base class for Teslemetry buttons.""" + api: Vehicle entity_description: TeslemetryButtonEntityDescription def __init__( diff --git a/homeassistant/components/teslemetry/climate.py b/homeassistant/components/teslemetry/climate.py index 0a1c23adcb0..1bc52b23026 100644 --- a/homeassistant/components/teslemetry/climate.py +++ b/homeassistant/components/teslemetry/climate.py @@ -91,7 +91,6 @@ class TeslemetryClimateEntity(TeslemetryRootEntity, ClimateEntity): """Vehicle Climate Control.""" api: Vehicle - _attr_precision = PRECISION_HALVES _attr_temperature_unit = UnitOfTemperature.CELSIUS _attr_hvac_modes = [HVACMode.HEAT_COOL, HVACMode.OFF] @@ -372,7 +371,6 @@ class TeslemetryCabinOverheatProtectionEntity(TeslemetryRootEntity, ClimateEntit """Vehicle Cabin Overheat Protection.""" api: Vehicle - _attr_precision = PRECISION_WHOLE _attr_target_temperature_step = 5 _attr_min_temp = 30 diff --git a/homeassistant/components/teslemetry/cover.py b/homeassistant/components/teslemetry/cover.py index de036edc32a..be85a877c86 100644 --- a/homeassistant/components/teslemetry/cover.py +++ b/homeassistant/components/teslemetry/cover.py @@ -6,6 +6,7 @@ from itertools import chain from typing import Any from tesla_fleet_api.const import Scope, SunRoofCommand, Trunk, WindowCommand +from tesla_fleet_api.teslemetry import Vehicle from teslemetry_stream import Signal from teslemetry_stream.const import WindowState @@ -103,6 +104,7 @@ class CoverRestoreEntity(RestoreEntity, CoverEntity): class TeslemetryWindowEntity(TeslemetryRootEntity, CoverEntity): """Base class for window cover entities.""" + api: Vehicle _attr_device_class = CoverDeviceClass.WINDOW _attr_supported_features = CoverEntityFeature.OPEN | CoverEntityFeature.CLOSE @@ -224,6 +226,7 @@ class TeslemetryChargePortEntity( ): """Base class for for charge port cover entities.""" + api: Vehicle _attr_device_class = CoverDeviceClass.DOOR _attr_supported_features = CoverEntityFeature.OPEN | CoverEntityFeature.CLOSE @@ -304,6 +307,7 @@ class TeslemetryStreamingChargePortEntity( class TeslemetryFrontTrunkEntity(TeslemetryRootEntity, CoverEntity): """Base class for the front trunk cover entities.""" + api: Vehicle _attr_device_class = CoverDeviceClass.DOOR _attr_supported_features = CoverEntityFeature.OPEN @@ -365,6 +369,7 @@ class TeslemetryStreamingFrontTrunkEntity( class TeslemetryRearTrunkEntity(TeslemetryRootEntity, CoverEntity): """Cover entity for the rear trunk.""" + api: Vehicle _attr_device_class = CoverDeviceClass.DOOR _attr_supported_features = CoverEntityFeature.OPEN | CoverEntityFeature.CLOSE @@ -433,6 +438,7 @@ class TeslemetryStreamingRearTrunkEntity( class TeslemetrySunroofEntity(TeslemetryVehiclePollingEntity, CoverEntity): """Cover entity for the sunroof.""" + api: Vehicle _attr_device_class = CoverDeviceClass.WINDOW _attr_supported_features = ( CoverEntityFeature.OPEN | CoverEntityFeature.CLOSE | CoverEntityFeature.STOP diff --git a/homeassistant/components/teslemetry/entity.py b/homeassistant/components/teslemetry/entity.py index 4930129642f..170d4e3a3ae 100644 --- a/homeassistant/components/teslemetry/entity.py +++ b/homeassistant/components/teslemetry/entity.py @@ -26,7 +26,6 @@ class TeslemetryRootEntity(Entity): _attr_has_entity_name = True scoped: bool - api: Vehicle | EnergySite def raise_for_scope(self, scope: Scope): """Raise an error if a scope is not available.""" @@ -248,6 +247,8 @@ class TeslemetryWallConnectorEntity(TeslemetryPollingEntity): class TeslemetryVehicleStreamEntity(TeslemetryRootEntity): """Parent class for Teslemetry Vehicle Stream entities.""" + api: Vehicle + def __init__(self, data: TeslemetryVehicleData, key: str) -> None: """Initialize common aspects of a Teslemetry entity.""" self.vehicle = data diff --git a/homeassistant/components/teslemetry/lock.py b/homeassistant/components/teslemetry/lock.py index 75cf72c9c88..fda52357f5c 100644 --- a/homeassistant/components/teslemetry/lock.py +++ b/homeassistant/components/teslemetry/lock.py @@ -6,6 +6,7 @@ from itertools import chain from typing import Any from tesla_fleet_api.const import Scope +from tesla_fleet_api.teslemetry import Vehicle from homeassistant.components.lock import LockEntity from homeassistant.core import HomeAssistant @@ -64,6 +65,8 @@ async def async_setup_entry( class TeslemetryVehicleLockEntity(TeslemetryRootEntity, LockEntity): """Base vehicle lock entity for Teslemetry.""" + api: Vehicle + async def async_lock(self, **kwargs: Any) -> None: """Lock the doors.""" self.raise_for_scope(Scope.VEHICLE_CMDS) @@ -135,6 +138,8 @@ class TeslemetryStreamingVehicleLockEntity( class TeslemetryCableLockEntity(TeslemetryRootEntity, LockEntity): """Base cable Lock entity for Teslemetry.""" + api: Vehicle + async def async_lock(self, **kwargs: Any) -> None: """Charge cable Lock cannot be manually locked.""" raise ServiceValidationError( diff --git a/homeassistant/components/teslemetry/media_player.py b/homeassistant/components/teslemetry/media_player.py index 11615d94614..bf1fffed583 100644 --- a/homeassistant/components/teslemetry/media_player.py +++ b/homeassistant/components/teslemetry/media_player.py @@ -63,7 +63,6 @@ class TeslemetryMediaEntity(TeslemetryRootEntity, MediaPlayerEntity): """Base vehicle media player class.""" api: Vehicle - _attr_device_class = MediaPlayerDeviceClass.SPEAKER _attr_volume_step = VOLUME_STEP diff --git a/homeassistant/components/teslemetry/number.py b/homeassistant/components/teslemetry/number.py index 466fc9f5ee6..bb9f5b588a0 100644 --- a/homeassistant/components/teslemetry/number.py +++ b/homeassistant/components/teslemetry/number.py @@ -172,6 +172,7 @@ async def async_setup_entry( class TeslemetryVehicleNumberEntity(TeslemetryRootEntity, NumberEntity): """Vehicle number entity base class.""" + api: Vehicle entity_description: TeslemetryNumberVehicleEntityDescription async def async_set_native_value(self, value: float) -> None: diff --git a/homeassistant/components/teslemetry/select.py b/homeassistant/components/teslemetry/select.py index be90636497e..c24c47feb2e 100644 --- a/homeassistant/components/teslemetry/select.py +++ b/homeassistant/components/teslemetry/select.py @@ -208,6 +208,7 @@ async def async_setup_entry( class TeslemetrySelectEntity(TeslemetryRootEntity, SelectEntity): """Parent vehicle select entity class.""" + api: Vehicle entity_description: TeslemetrySelectEntityDescription _climate: bool = False diff --git a/homeassistant/components/teslemetry/switch.py b/homeassistant/components/teslemetry/switch.py index f1082122e5c..f607429be46 100644 --- a/homeassistant/components/teslemetry/switch.py +++ b/homeassistant/components/teslemetry/switch.py @@ -8,7 +8,7 @@ from itertools import chain from typing import Any from tesla_fleet_api.const import AutoSeat, Scope -from tesla_fleet_api.teslemetry.vehicles import TeslemetryVehicle +from tesla_fleet_api.teslemetry import Vehicle from teslemetry_stream import TeslemetryStreamVehicle from homeassistant.components.switch import ( @@ -38,8 +38,8 @@ PARALLEL_UPDATES = 0 class TeslemetrySwitchEntityDescription(SwitchEntityDescription): """Describes Teslemetry Switch entity.""" - on_func: Callable[[TeslemetryVehicle], Awaitable[dict[str, Any]]] - off_func: Callable[[TeslemetryVehicle], Awaitable[dict[str, Any]]] + on_func: Callable[[Vehicle], Awaitable[dict[str, Any]]] + off_func: Callable[[Vehicle], Awaitable[dict[str, Any]]] scopes: list[Scope] value_func: Callable[[StateType], bool] = bool streaming_listener: Callable[ @@ -176,6 +176,7 @@ async def async_setup_entry( class TeslemetryVehicleSwitchEntity(TeslemetryRootEntity, SwitchEntity): """Base class for all Teslemetry switch entities.""" + api: Vehicle _attr_device_class = SwitchDeviceClass.SWITCH entity_description: TeslemetrySwitchEntityDescription From 65da1e79b9d1dfa99cfd43886a063ed03ac3c6d0 Mon Sep 17 00:00:00 2001 From: Norbert Rittel Date: Mon, 5 May 2025 09:39:23 +0200 Subject: [PATCH 78/90] Change some strings to international English in `fronius` (#144244) Change to international English in `fronius` --- homeassistant/components/fronius/strings.json | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/homeassistant/components/fronius/strings.json b/homeassistant/components/fronius/strings.json index 7c42cca29de..ef55c51cb14 100644 --- a/homeassistant/components/fronius/strings.json +++ b/homeassistant/components/fronius/strings.json @@ -140,16 +140,16 @@ "ac_module_temperature_sensor_faulty_l3": "AC module temperature sensor faulty (L3)", "dc_module_temperature_sensor_faulty": "DC module temperature sensor faulty", "internal_processor_status": "Warning about the internal processor status. See status code for more information", - "eeprom_reinitialised": "EEPROM has been re-initialised", - "initialisation_error_usb_flash_drive_not_supported": "Initialisation error – USB flash drive is not supported", - "initialisation_error_usb_stick_over_current": "Initialisation error – Overcurrent on USB stick", + "eeprom_reinitialised": "EEPROM has been re-initialized", + "initialisation_error_usb_flash_drive_not_supported": "Initialization error – USB flash drive is not supported", + "initialisation_error_usb_stick_over_current": "Initialization error – Overcurrent on USB stick", "no_usb_flash_drive_connected": "No USB flash drive connected", - "update_file_not_recognised_or_missing": "Update file not recognised or not present", + "update_file_not_recognised_or_missing": "Update file not recognized or not present", "update_file_does_not_match_device": "Update file does not match the device, update file too old", "write_or_read_error_occurred": "Write or read error occurred", "file_could_not_be_opened": "File could not be opened", "log_file_cannot_be_saved": "Log file cannot be saved (e.g. USB flash drive is write protected or full)", - "initialisation_error_file_system_error_on_usb": "Initialisation error in file system on USB flash drive", + "initialisation_error_file_system_error_on_usb": "Initialization error in file system on USB flash drive", "error_during_logging_data_recording": "Error during recording of logging data", "error_during_update_process": "Error occurred during update process", "update_file_corrupt": "Update file corrupt", From aa062515b8c59ae09ff8fe2ff92fb43a42af7b2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ville=20Skytt=C3=A4?= Date: Mon, 5 May 2025 10:46:30 +0300 Subject: [PATCH 79/90] Remove unused huawei_lte YAML schemas, error out on YAML config (#144217) --- .../components/huawei_lte/__init__.py | 32 +------------------ 1 file changed, 1 insertion(+), 31 deletions(-) diff --git a/homeassistant/components/huawei_lte/__init__.py b/homeassistant/components/huawei_lte/__init__.py index be9d02e45fd..6126968eab6 100644 --- a/homeassistant/components/huawei_lte/__init__.py +++ b/homeassistant/components/huawei_lte/__init__.py @@ -23,7 +23,6 @@ from huawei_lte_api.exceptions import ( from requests.exceptions import Timeout import voluptuous as vol -from homeassistant.components.notify import DOMAIN as NOTIFY_DOMAIN from homeassistant.config_entries import ConfigEntry from homeassistant.const import ( ATTR_HW_VERSION, @@ -90,36 +89,7 @@ _LOGGER = logging.getLogger(__name__) SCAN_INTERVAL = timedelta(seconds=30) -NOTIFY_SCHEMA = vol.Any( - None, - vol.Schema( - { - vol.Optional(CONF_NAME): cv.string, - vol.Optional(CONF_RECIPIENT): vol.Any( - None, vol.All(cv.ensure_list, [cv.string]) - ), - } - ), -) - -CONFIG_SCHEMA = vol.Schema( - { - DOMAIN: vol.All( - cv.ensure_list, - [ - vol.Schema( - { - vol.Required(CONF_URL): cv.url, - vol.Optional(CONF_USERNAME): cv.string, - vol.Optional(CONF_PASSWORD): cv.string, - vol.Optional(NOTIFY_DOMAIN): NOTIFY_SCHEMA, - } - ) - ], - ) - }, - extra=vol.ALLOW_EXTRA, -) +CONFIG_SCHEMA = cv.config_entry_only_config_schema(DOMAIN) SERVICE_SCHEMA = vol.Schema({vol.Optional(CONF_URL): cv.url}) From 58906008b969312da91fc7494c54b68616424a2b Mon Sep 17 00:00:00 2001 From: Michael <35783820+mib1185@users.noreply.github.com> Date: Mon, 5 May 2025 10:39:06 +0200 Subject: [PATCH 80/90] Add last attempted automatic backup sensor (#144194) add last_attempted_automatic_backup sensor --- .../components/backup/coordinator.py | 2 + homeassistant/components/backup/sensor.py | 6 +++ homeassistant/components/backup/strings.json | 3 ++ .../backup/snapshots/test_sensors.ambr | 48 +++++++++++++++++++ tests/components/backup/test_sensors.py | 4 ++ 5 files changed, 63 insertions(+) diff --git a/homeassistant/components/backup/coordinator.py b/homeassistant/components/backup/coordinator.py index 377f23567e0..dba05ba0225 100644 --- a/homeassistant/components/backup/coordinator.py +++ b/homeassistant/components/backup/coordinator.py @@ -30,6 +30,7 @@ class BackupCoordinatorData: """Class to hold backup data.""" backup_manager_state: BackupManagerState + last_attempted_automatic_backup: datetime | None last_successful_automatic_backup: datetime | None next_scheduled_automatic_backup: datetime | None @@ -70,6 +71,7 @@ class BackupDataUpdateCoordinator(DataUpdateCoordinator[BackupCoordinatorData]): """Update backup manager data.""" return BackupCoordinatorData( self.backup_manager.state, + self.backup_manager.config.data.last_attempted_automatic_backup, self.backup_manager.config.data.last_completed_automatic_backup, self.backup_manager.config.data.schedule.next_automatic_backup, ) diff --git a/homeassistant/components/backup/sensor.py b/homeassistant/components/backup/sensor.py index 59e98ae7c2d..08e7ec49e3d 100644 --- a/homeassistant/components/backup/sensor.py +++ b/homeassistant/components/backup/sensor.py @@ -46,6 +46,12 @@ BACKUP_MANAGER_DESCRIPTIONS = ( device_class=SensorDeviceClass.TIMESTAMP, value_fn=lambda data: data.last_successful_automatic_backup, ), + BackupSensorEntityDescription( + key="last_attempted_automatic_backup", + translation_key="last_attempted_automatic_backup", + device_class=SensorDeviceClass.TIMESTAMP, + value_fn=lambda data: data.last_attempted_automatic_backup, + ), ) diff --git a/homeassistant/components/backup/strings.json b/homeassistant/components/backup/strings.json index 357bcdbb72f..37adf9e9faf 100644 --- a/homeassistant/components/backup/strings.json +++ b/homeassistant/components/backup/strings.json @@ -37,6 +37,9 @@ "next_scheduled_automatic_backup": { "name": "Next scheduled automatic backup" }, + "last_attempted_automatic_backup": { + "name": "Last attempted automatic backup" + }, "last_successful_automatic_backup": { "name": "Last successful automatic backup" } diff --git a/tests/components/backup/snapshots/test_sensors.ambr b/tests/components/backup/snapshots/test_sensors.ambr index be12afdbf1e..b68d706dfb3 100644 --- a/tests/components/backup/snapshots/test_sensors.ambr +++ b/tests/components/backup/snapshots/test_sensors.ambr @@ -62,6 +62,54 @@ 'state': 'idle', }) # --- +# name: test_sensors[sensor.backup_last_attempted_automatic_backup-entry] + EntityRegistryEntrySnapshot({ + 'aliases': set({ + }), + 'area_id': None, + 'capabilities': None, + 'config_entry_id': , + 'config_subentry_id': , + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'sensor', + 'entity_category': None, + 'entity_id': 'sensor.backup_last_attempted_automatic_backup', + 'has_entity_name': True, + 'hidden_by': None, + 'icon': None, + 'id': , + 'labels': set({ + }), + 'name': None, + 'options': dict({ + }), + 'original_device_class': , + 'original_icon': None, + 'original_name': 'Last attempted automatic backup', + 'platform': 'backup', + 'previous_unique_id': None, + 'supported_features': 0, + 'translation_key': 'last_attempted_automatic_backup', + 'unique_id': 'last_attempted_automatic_backup', + 'unit_of_measurement': None, + }) +# --- +# name: test_sensors[sensor.backup_last_attempted_automatic_backup-state] + StateSnapshot({ + 'attributes': ReadOnlyDict({ + 'device_class': 'timestamp', + 'friendly_name': 'Backup Last attempted automatic backup', + }), + 'context': , + 'entity_id': 'sensor.backup_last_attempted_automatic_backup', + 'last_changed': , + 'last_reported': , + 'last_updated': , + 'state': 'unknown', + }) +# --- # name: test_sensors[sensor.backup_last_successful_automatic_backup-entry] EntityRegistryEntrySnapshot({ 'aliases': set({ diff --git a/tests/components/backup/test_sensors.py b/tests/components/backup/test_sensors.py index bee61887ea5..6ff1aca7c6d 100644 --- a/tests/components/backup/test_sensors.py +++ b/tests/components/backup/test_sensors.py @@ -104,6 +104,8 @@ async def test_sensor_updates( ) await hass.async_block_till_done(wait_background_tasks=True) + state = hass.states.get("sensor.backup_last_attempted_automatic_backup") + assert state.state == "2024-11-11T03:45:00+00:00" state = hass.states.get("sensor.backup_last_successful_automatic_backup") assert state.state == "2024-11-11T03:45:00+00:00" state = hass.states.get("sensor.backup_next_scheduled_automatic_backup") @@ -113,6 +115,8 @@ async def test_sensor_updates( async_fire_time_changed(hass) await hass.async_block_till_done() + state = hass.states.get("sensor.backup_last_attempted_automatic_backup") + assert state.state == "2024-11-13T11:00:00+00:00" state = hass.states.get("sensor.backup_last_successful_automatic_backup") assert state.state == "2024-11-13T11:00:00+00:00" state = hass.states.get("sensor.backup_next_scheduled_automatic_backup") From 66b2e06cd3c8209fb6ff0da792d6e71d15f8ad7b Mon Sep 17 00:00:00 2001 From: tronikos Date: Mon, 5 May 2025 02:35:32 -0700 Subject: [PATCH 81/90] Fix Invalid statistic_id for Opower: National Grid (#144243) Co-authored-by: J. Nick Koston --- homeassistant/components/opower/coordinator.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/homeassistant/components/opower/coordinator.py b/homeassistant/components/opower/coordinator.py index dd0b2c87bb5..a8d24b68fd2 100644 --- a/homeassistant/components/opower/coordinator.py +++ b/homeassistant/components/opower/coordinator.py @@ -113,14 +113,16 @@ class OpowerCoordinator(DataUpdateCoordinator[dict[str, Forecast]]): _LOGGER.error("Error getting accounts: %s", err) raise for account in accounts: - id_prefix = "_".join( + id_prefix = ( ( - self.api.utility.subdomain(), - account.meter_type.name.lower(), - # Some utilities like AEP have "-" in their account id. - # Replace it with "_" to avoid "Invalid statistic_id" - account.utility_account_id.replace("-", "_").lower(), + f"{self.api.utility.subdomain()}_{account.meter_type.name}_" + f"{account.utility_account_id}" ) + # Some utilities like AEP have "-" in their account id. + # Other utilities like ngny-gas have "-" in their subdomain. + # Replace it with "_" to avoid "Invalid statistic_id" + .replace("-", "_") + .lower() ) cost_statistic_id = f"{DOMAIN}:{id_prefix}_energy_cost" compensation_statistic_id = f"{DOMAIN}:{id_prefix}_energy_compensation" From d88cd72d133e199822af8990fe1ce629a94e2118 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Mon, 5 May 2025 11:58:24 +0200 Subject: [PATCH 82/90] Move more SamsungTV test constants to fixture files (#144249) * Add SSDP fixtures to SamsungTV * Adjust * Improve * Improve --- tests/components/samsungtv/const.py | 45 ++++------ .../fixtures/ssdp_device_main_tv_agent.json | 11 +++ .../ssdp_service_remote_control_receiver.json | 11 +++ .../ssdp_service_rendering_control.json | 11 +++ .../components/samsungtv/test_config_flow.py | 90 ++++++------------- 5 files changed, 77 insertions(+), 91 deletions(-) create mode 100644 tests/components/samsungtv/fixtures/ssdp_device_main_tv_agent.json create mode 100644 tests/components/samsungtv/fixtures/ssdp_service_remote_control_receiver.json create mode 100644 tests/components/samsungtv/fixtures/ssdp_service_rendering_control.json diff --git a/tests/components/samsungtv/const.py b/tests/components/samsungtv/const.py index 5d09087dadd..e4977a536b0 100644 --- a/tests/components/samsungtv/const.py +++ b/tests/components/samsungtv/const.py @@ -2,6 +2,7 @@ from homeassistant.components.samsungtv.const import ( CONF_SESSION_ID, + DOMAIN, METHOD_LEGACY, METHOD_WEBSOCKET, ) @@ -15,13 +16,9 @@ from homeassistant.const import ( CONF_PORT, CONF_TOKEN, ) -from homeassistant.helpers.service_info.ssdp import ( - ATTR_UPNP_FRIENDLY_NAME, - ATTR_UPNP_MANUFACTURER, - ATTR_UPNP_MODEL_NAME, - ATTR_UPNP_UDN, - SsdpServiceInfo, -) +from homeassistant.helpers.service_info.ssdp import SsdpServiceInfo + +from tests.common import load_json_object_fixture MOCK_CONFIG = { CONF_HOST: "fake_host", @@ -59,28 +56,6 @@ MOCK_ENTRY_WS_WITH_MAC = { CONF_TOKEN: "123456789", } -MOCK_SSDP_DATA_RENDERING_CONTROL_ST = SsdpServiceInfo( - ssdp_usn="mock_usn", - ssdp_st="urn:schemas-upnp-org:service:RenderingControl:1", - ssdp_location="https://fake_host:12345/test", - upnp={ - ATTR_UPNP_FRIENDLY_NAME: "[TV] fake_name", - ATTR_UPNP_MANUFACTURER: "Samsung fake_manufacturer", - ATTR_UPNP_MODEL_NAME: "fake_model", - ATTR_UPNP_UDN: "uuid:0d1cef00-00dc-1000-9c80-4844f7b172de", - }, -) -MOCK_SSDP_DATA_MAIN_TV_AGENT_ST = SsdpServiceInfo( - ssdp_usn="mock_usn", - ssdp_st="urn:samsung.com:service:MainTVAgent2:1", - ssdp_location="https://fake_host:12345/tv_agent", - upnp={ - ATTR_UPNP_FRIENDLY_NAME: "[TV] fake_name", - ATTR_UPNP_MANUFACTURER: "Samsung fake_manufacturer", - ATTR_UPNP_MODEL_NAME: "fake_model", - ATTR_UPNP_UDN: "uuid:0d1cef00-00dc-1000-9c80-4844f7b172de", - }, -) SAMPLE_DEVICE_INFO_WIFI = { "id": "uuid:be9554b9-c9fb-41f4-8920-22da015376a4", @@ -92,3 +67,15 @@ SAMPLE_DEVICE_INFO_WIFI = { "networkType": "wireless", }, } + +MOCK_SSDP_DATA = SsdpServiceInfo( + **load_json_object_fixture("ssdp_service_remote_control_receiver.json", DOMAIN) +) + +MOCK_SSDP_DATA_RENDERING_CONTROL_ST = SsdpServiceInfo( + **load_json_object_fixture("ssdp_service_rendering_control.json", DOMAIN) +) + +MOCK_SSDP_DATA_MAIN_TV_AGENT_ST = SsdpServiceInfo( + **load_json_object_fixture("ssdp_device_main_tv_agent.json", DOMAIN) +) diff --git a/tests/components/samsungtv/fixtures/ssdp_device_main_tv_agent.json b/tests/components/samsungtv/fixtures/ssdp_device_main_tv_agent.json new file mode 100644 index 00000000000..2970f14bf5f --- /dev/null +++ b/tests/components/samsungtv/fixtures/ssdp_device_main_tv_agent.json @@ -0,0 +1,11 @@ +{ + "ssdp_usn": "uuid:0d1cef00-00dc-1000-9c80-4844f7b172de::urn:samsung.com:service:MainTVAgent2:1", + "ssdp_st": "urn:samsung.com:service:MainTVAgent2:1", + "upnp": { + "friendlyName": "[TV] fake_name", + "manufacturer": "Samsung fake_manufacturer", + "modelName": "fake_model", + "UDN": "uuid:0d1cef00-00dc-1000-9c80-4844f7b172de" + }, + "ssdp_location": "https://fake_host:12345/tv_agent" +} diff --git a/tests/components/samsungtv/fixtures/ssdp_service_remote_control_receiver.json b/tests/components/samsungtv/fixtures/ssdp_service_remote_control_receiver.json new file mode 100644 index 00000000000..b2f5f27a8b4 --- /dev/null +++ b/tests/components/samsungtv/fixtures/ssdp_service_remote_control_receiver.json @@ -0,0 +1,11 @@ +{ + "ssdp_usn": "uuid:0d1cef00-00dc-1000-9c80-4844f7b172de::urn:samsung.com:device:RemoteControlReceiver:1", + "ssdp_st": "urn:samsung.com:device:RemoteControlReceiver:1", + "upnp": { + "friendlyName": "[TV] fake_name", + "manufacturer": "Samsung fake_manufacturer", + "modelName": "fake_model", + "UDN": "uuid:0d1cef00-00dc-1000-9c80-4844f7b172de" + }, + "ssdp_location": "http://fake_host:7676/smp_7_" +} diff --git a/tests/components/samsungtv/fixtures/ssdp_service_rendering_control.json b/tests/components/samsungtv/fixtures/ssdp_service_rendering_control.json new file mode 100644 index 00000000000..4074a39703e --- /dev/null +++ b/tests/components/samsungtv/fixtures/ssdp_service_rendering_control.json @@ -0,0 +1,11 @@ +{ + "ssdp_usn": "uuid:0d1cef00-00dc-1000-9c80-4844f7b172de::urn:schemas-upnp-org:service:RenderingControl:1", + "ssdp_st": "urn:schemas-upnp-org:service:RenderingControl:1", + "upnp": { + "friendlyName": "[TV] fake_name", + "manufacturer": "Samsung fake_manufacturer", + "modelName": "fake_model", + "UDN": "uuid:0d1cef00-00dc-1000-9c80-4844f7b172de" + }, + "ssdp_location": "https://fake_host:12345/test" +} diff --git a/tests/components/samsungtv/test_config_flow.py b/tests/components/samsungtv/test_config_flow.py index 12c222033e0..b15c007c109 100644 --- a/tests/components/samsungtv/test_config_flow.py +++ b/tests/components/samsungtv/test_config_flow.py @@ -51,8 +51,6 @@ from homeassistant.helpers.service_info.dhcp import DhcpServiceInfo from homeassistant.helpers.service_info.ssdp import ( ATTR_UPNP_FRIENDLY_NAME, ATTR_UPNP_MANUFACTURER, - ATTR_UPNP_MODEL_NAME, - ATTR_UPNP_UDN, SsdpServiceInfo, ) from homeassistant.helpers.service_info.zeroconf import ZeroconfServiceInfo @@ -61,6 +59,7 @@ from homeassistant.setup import async_setup_component from .const import ( MOCK_ENTRYDATA_ENCRYPTED_WS, MOCK_ENTRYDATA_WS, + MOCK_SSDP_DATA, MOCK_SSDP_DATA_MAIN_TV_AGENT_ST, MOCK_SSDP_DATA_RENDERING_CONTROL_ST, ) @@ -84,49 +83,7 @@ MOCK_IMPORT_WSDATA = { CONF_PORT: 8002, } MOCK_USER_DATA = {CONF_HOST: "fake_host", CONF_NAME: "fake_name"} -MOCK_SSDP_DATA = SsdpServiceInfo( - ssdp_usn="mock_usn", - ssdp_st="mock_st", - ssdp_location="https://fake_host:12345/test", - upnp={ - ATTR_UPNP_FRIENDLY_NAME: "[TV] fake_name", - ATTR_UPNP_MANUFACTURER: "Samsung fake_manufacturer", - ATTR_UPNP_MODEL_NAME: "fake_model", - ATTR_UPNP_UDN: "uuid:0d1cef00-00dc-1000-9c80-4844f7b172de", - }, -) -MOCK_SSDP_DATA_NO_MANUFACTURER = SsdpServiceInfo( - ssdp_usn="mock_usn", - ssdp_st="mock_st", - ssdp_location="https://fake_host:12345/test", - upnp={ - ATTR_UPNP_FRIENDLY_NAME: "[TV] fake_name", - ATTR_UPNP_UDN: "uuid:0d1cef00-00dc-1000-9c80-4844f7b172de", - }, -) -MOCK_SSDP_DATA_NOPREFIX = SsdpServiceInfo( - ssdp_usn="mock_usn", - ssdp_st="mock_st", - ssdp_location="http://fake2_host:12345/test", - upnp={ - ATTR_UPNP_FRIENDLY_NAME: "fake2_name", - ATTR_UPNP_MANUFACTURER: "Samsung fake2_manufacturer", - ATTR_UPNP_MODEL_NAME: "fake2_model", - ATTR_UPNP_UDN: "uuid:0d1cef00-00dc-1000-9c80-4844f7b172df", - }, -) -MOCK_SSDP_DATA_WRONGMODEL = SsdpServiceInfo( - ssdp_usn="mock_usn", - ssdp_st="mock_st", - ssdp_location="http://fake2_host:12345/test", - upnp={ - ATTR_UPNP_FRIENDLY_NAME: "fake2_name", - ATTR_UPNP_MANUFACTURER: "fake2_manufacturer", - ATTR_UPNP_MODEL_NAME: "HW-Qfake", - ATTR_UPNP_UDN: "uuid:0d1cef00-00dc-1000-9c80-4844f7b172df", - }, -) MOCK_DHCP_DATA = DhcpServiceInfo( ip="fake_host", macaddress="aabbccddeeff", hostname="fake_hostname" ) @@ -540,13 +497,16 @@ async def test_ssdp(hass: HomeAssistant) -> None: @pytest.mark.usefixtures("remote", "rest_api_failing") async def test_ssdp_no_manufacturer(hass: HomeAssistant) -> None: """Test starting a flow from discovery when the manufacturer data is missing.""" + ssdp_data = deepcopy(MOCK_SSDP_DATA) + ssdp_data.upnp.pop(ATTR_UPNP_MANUFACTURER) + result = await hass.config_entries.flow.async_init( DOMAIN, context={"source": config_entries.SOURCE_SSDP}, - data=MOCK_SSDP_DATA_NO_MANUFACTURER, + data=ssdp_data, ) assert result["type"] is FlowResultType.ABORT - assert result["reason"] == "not_supported" + assert result["reason"] == RESULT_NOT_SUPPORTED @pytest.mark.parametrize( @@ -566,12 +526,17 @@ async def test_ssdp_legacy_not_remote_control_receiver_udn( @pytest.mark.usefixtures("remote", "rest_api_failing") async def test_ssdp_noprefix(hass: HomeAssistant) -> None: - """Test starting a flow from discovery without prefixes.""" + """Test starting a flow from discovery when friendly name doesn't start with [TV].""" + ssdp_data = deepcopy(MOCK_SSDP_DATA) + ssdp_data.upnp[ATTR_UPNP_FRIENDLY_NAME] = ssdp_data.upnp[ATTR_UPNP_FRIENDLY_NAME][ + 4: + ] + # confirm to add the entry result = await hass.config_entries.flow.async_init( DOMAIN, context={"source": config_entries.SOURCE_SSDP}, - data=MOCK_SSDP_DATA_NOPREFIX, + data=ssdp_data, ) assert result["type"] is FlowResultType.FORM assert result["step_id"] == "confirm" @@ -580,12 +545,12 @@ async def test_ssdp_noprefix(hass: HomeAssistant) -> None: result["flow_id"], user_input="whatever" ) assert result["type"] is FlowResultType.CREATE_ENTRY - assert result["title"] == "fake2_model" - assert result["data"][CONF_HOST] == "fake2_host" - assert result["data"][CONF_NAME] == "fake2_model" - assert result["data"][CONF_MANUFACTURER] == "Samsung fake2_manufacturer" - assert result["data"][CONF_MODEL] == "fake2_model" - assert result["result"].unique_id == "0d1cef00-00dc-1000-9c80-4844f7b172df" + assert result["title"] == "fake_model" + assert result["data"][CONF_HOST] == "fake_host" + assert result["data"][CONF_NAME] == "fake_model" + assert result["data"][CONF_MANUFACTURER] == "Samsung fake_manufacturer" + assert result["data"][CONF_MODEL] == "fake_model" + assert result["result"].unique_id == "0d1cef00-00dc-1000-9c80-4844f7b172de" @pytest.mark.usefixtures("remotews", "rest_api_failing") @@ -797,14 +762,15 @@ async def test_ssdp_websocket_cannot_connect(hass: HomeAssistant) -> None: @pytest.mark.usefixtures("remote") -async def test_ssdp_model_not_supported(hass: HomeAssistant) -> None: +async def test_ssdp_wrong_manufacturer(hass: HomeAssistant) -> None: """Test starting a flow from discovery.""" - + ssdp_data = deepcopy(MOCK_SSDP_DATA) + ssdp_data.upnp[ATTR_UPNP_MANUFACTURER] = ssdp_data.upnp[ATTR_UPNP_MANUFACTURER][7:] # confirm to add the entry result = await hass.config_entries.flow.async_init( DOMAIN, context={"source": config_entries.SOURCE_SSDP}, - data=MOCK_SSDP_DATA_WRONGMODEL, + data=ssdp_data, ) assert result["type"] is FlowResultType.ABORT assert result["reason"] == RESULT_NOT_SUPPORTED @@ -1100,7 +1066,7 @@ async def test_zeroconf_ignores_soundbar(hass: HomeAssistant, rest_api: Mock) -> ) await hass.async_block_till_done() assert result["type"] is FlowResultType.ABORT - assert result["reason"] == "not_supported" + assert result["reason"] == RESULT_NOT_SUPPORTED @pytest.mark.usefixtures("remote", "remotews", "remoteencws", "rest_api_failing") @@ -1113,7 +1079,7 @@ async def test_zeroconf_no_device_info(hass: HomeAssistant) -> None: ) await hass.async_block_till_done() assert result["type"] is FlowResultType.ABORT - assert result["reason"] == "not_supported" + assert result["reason"] == RESULT_NOT_SUPPORTED @pytest.mark.usefixtures("remotews", "rest_api", "remoteencws_failing") @@ -1493,7 +1459,7 @@ async def test_update_zeroconf_discovery_preserved_unique_id( ) await hass.async_block_till_done() assert result["type"] is FlowResultType.ABORT - assert result["reason"] == "not_supported" + assert result["reason"] == RESULT_NOT_SUPPORTED assert entry.data[CONF_MAC] == "aa:bb:zz:ee:rr:oo" assert entry.unique_id == "original" @@ -1752,7 +1718,7 @@ async def test_update_legacy_missing_mac_from_dhcp_no_unique_id( assert len(mock_setup_entry.mock_calls) == 1 assert result["type"] is FlowResultType.ABORT - assert result["reason"] == "not_supported" + assert result["reason"] == RESULT_NOT_SUPPORTED assert entry.data[CONF_MAC] == "aa:bb:cc:dd:ee:ff" assert entry.unique_id is None @@ -1905,7 +1871,7 @@ async def test_form_reauth_websocket_not_supported(hass: HomeAssistant) -> None: await hass.async_block_till_done() assert result2["type"] is FlowResultType.ABORT - assert result2["reason"] == "not_supported" + assert result2["reason"] == RESULT_NOT_SUPPORTED @pytest.mark.usefixtures("remoteencws", "rest_api") From 9e4a20c267c9ec95830b811884dbf327dc4d3eea Mon Sep 17 00:00:00 2001 From: John Hillery <34005807+jrhillery@users.noreply.github.com> Date: Mon, 5 May 2025 06:40:37 -0400 Subject: [PATCH 83/90] Bump nexia to 2.9.0 (#144153) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Abílio Costa Co-authored-by: J. Nick Koston Co-authored-by: Robert Resch --- homeassistant/components/nexia/manifest.json | 2 +- requirements_all.txt | 2 +- requirements_test_all.txt | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/nexia/manifest.json b/homeassistant/components/nexia/manifest.json index e8a1b53cc08..0c01820055e 100644 --- a/homeassistant/components/nexia/manifest.json +++ b/homeassistant/components/nexia/manifest.json @@ -12,5 +12,5 @@ "documentation": "https://www.home-assistant.io/integrations/nexia", "iot_class": "cloud_polling", "loggers": ["nexia"], - "requirements": ["nexia==2.7.0"] + "requirements": ["nexia==2.9.0"] } diff --git a/requirements_all.txt b/requirements_all.txt index 8ebee15acc5..7fb2f03f158 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -1496,7 +1496,7 @@ nettigo-air-monitor==4.1.0 neurio==0.3.1 # homeassistant.components.nexia -nexia==2.7.0 +nexia==2.9.0 # homeassistant.components.nextcloud nextcloudmonitor==1.5.1 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index cadd68bb101..6f3df86cc20 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -1260,7 +1260,7 @@ netmap==0.7.0.2 nettigo-air-monitor==4.1.0 # homeassistant.components.nexia -nexia==2.7.0 +nexia==2.9.0 # homeassistant.components.nextcloud nextcloudmonitor==1.5.1 From 445b38f25d8276da1ae8a42e89cc2b6dec7e734c Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 5 May 2025 12:51:19 +0200 Subject: [PATCH 84/90] Bump github/codeql-action from 3.28.16 to 3.28.17 (#144245) Bumps [github/codeql-action](https://github.com/github/codeql-action) from 3.28.16 to 3.28.17. - [Release notes](https://github.com/github/codeql-action/releases) - [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md) - [Commits](https://github.com/github/codeql-action/compare/v3.28.16...v3.28.17) --- updated-dependencies: - dependency-name: github/codeql-action dependency-version: 3.28.17 dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/codeql.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index c6181121043..7cc5ae34bee 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -24,11 +24,11 @@ jobs: uses: actions/checkout@v4.2.2 - name: Initialize CodeQL - uses: github/codeql-action/init@v3.28.16 + uses: github/codeql-action/init@v3.28.17 with: languages: python - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@v3.28.16 + uses: github/codeql-action/analyze@v3.28.17 with: category: "/language:python" From 3390dc0dbb45b4b2be57a3e75fd8b619af4baeb4 Mon Sep 17 00:00:00 2001 From: Allen Porter Date: Mon, 5 May 2025 04:13:08 -0700 Subject: [PATCH 85/90] Fix Office 365 calendars to be compatible with rfc5545 (#144230) --- .../components/remote_calendar/config_flow.py | 13 +---- .../components/remote_calendar/coordinator.py | 12 +--- .../components/remote_calendar/ics.py | 44 ++++++++++++++ .../snapshots/test_calendar.ambr | 19 ++++++ .../remote_calendar/test_calendar.py | 30 ++++++++++ .../testdata/office365_invalid_tzid.ics | 58 +++++++++++++++++++ 6 files changed, 157 insertions(+), 19 deletions(-) create mode 100644 homeassistant/components/remote_calendar/ics.py create mode 100644 tests/components/remote_calendar/snapshots/test_calendar.ambr create mode 100644 tests/components/remote_calendar/testdata/office365_invalid_tzid.ics diff --git a/homeassistant/components/remote_calendar/config_flow.py b/homeassistant/components/remote_calendar/config_flow.py index 802a7eb7cea..558a3d668ae 100644 --- a/homeassistant/components/remote_calendar/config_flow.py +++ b/homeassistant/components/remote_calendar/config_flow.py @@ -5,8 +5,6 @@ import logging from typing import Any from httpx import HTTPError, InvalidURL -from ical.calendar_stream import IcsCalendarStream -from ical.exceptions import CalendarParseError import voluptuous as vol from homeassistant.config_entries import ConfigFlow, ConfigFlowResult @@ -14,6 +12,7 @@ from homeassistant.const import CONF_URL from homeassistant.helpers.httpx_client import get_async_client from .const import CONF_CALENDAR_NAME, DOMAIN +from .ics import InvalidIcsException, parse_calendar _LOGGER = logging.getLogger(__name__) @@ -64,15 +63,9 @@ class RemoteCalendarConfigFlow(ConfigFlow, domain=DOMAIN): _LOGGER.debug("An error occurred: %s", err) else: try: - await self.hass.async_add_executor_job( - IcsCalendarStream.calendar_from_ics, res.text - ) - except CalendarParseError as err: + await parse_calendar(self.hass, res.text) + except InvalidIcsException: errors["base"] = "invalid_ics_file" - _LOGGER.error("Error reading the calendar information: %s", err.message) - _LOGGER.debug( - "Additional calendar error detail: %s", str(err.detailed_error) - ) else: return self.async_create_entry( title=user_input[CONF_CALENDAR_NAME], data=user_input diff --git a/homeassistant/components/remote_calendar/coordinator.py b/homeassistant/components/remote_calendar/coordinator.py index 6caec297c1a..1eead7682d3 100644 --- a/homeassistant/components/remote_calendar/coordinator.py +++ b/homeassistant/components/remote_calendar/coordinator.py @@ -5,8 +5,6 @@ import logging from httpx import HTTPError, InvalidURL from ical.calendar import Calendar -from ical.calendar_stream import IcsCalendarStream -from ical.exceptions import CalendarParseError from homeassistant.config_entries import ConfigEntry from homeassistant.const import CONF_URL @@ -15,6 +13,7 @@ from homeassistant.helpers.httpx_client import get_async_client from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed from .const import DOMAIN +from .ics import InvalidIcsException, parse_calendar type RemoteCalendarConfigEntry = ConfigEntry[RemoteCalendarDataUpdateCoordinator] @@ -56,14 +55,9 @@ class RemoteCalendarDataUpdateCoordinator(DataUpdateCoordinator[Calendar]): translation_placeholders={"err": str(err)}, ) from err try: - # calendar_from_ics will dynamically load packages - # the first time it is called, so we need to do it - # in a separate thread to avoid blocking the event loop self.ics = res.text - return await self.hass.async_add_executor_job( - IcsCalendarStream.calendar_from_ics, self.ics - ) - except CalendarParseError as err: + return await parse_calendar(self.hass, res.text) + except InvalidIcsException as err: raise UpdateFailed( translation_domain=DOMAIN, translation_key="unable_to_parse", diff --git a/homeassistant/components/remote_calendar/ics.py b/homeassistant/components/remote_calendar/ics.py new file mode 100644 index 00000000000..d0920d7ae32 --- /dev/null +++ b/homeassistant/components/remote_calendar/ics.py @@ -0,0 +1,44 @@ +"""Module for parsing ICS content. + +This module exists to fix known issues where calendar providers return calendars +that do not follow rfcc5545. This module will attempt to fix the calendar and return +a valid calendar object. +""" + +import logging + +from ical.calendar import Calendar +from ical.calendar_stream import IcsCalendarStream +from ical.compat import enable_compat_mode +from ical.exceptions import CalendarParseError + +from homeassistant.core import HomeAssistant + +_LOGGER = logging.getLogger(__name__) + + +class InvalidIcsException(Exception): + """Exception to indicate that the ICS content is invalid.""" + + +def _compat_calendar_from_ics(ics: str) -> Calendar: + """Parse the ICS content and return a Calendar object. + + This function is called in a separate thread to avoid blocking the event + loop while loading packages or parsing the ICS content for large calendars. + + It uses the `enable_compat_mode` context manager to fix known issues with + calendar providers that return invalid calendars. + """ + with enable_compat_mode(ics) as compat_ics: + return IcsCalendarStream.calendar_from_ics(compat_ics) + + +async def parse_calendar(hass: HomeAssistant, ics: str) -> Calendar: + """Parse the ICS content and return a Calendar object.""" + try: + return await hass.async_add_executor_job(_compat_calendar_from_ics, ics) + except CalendarParseError as err: + _LOGGER.error("Error parsing calendar information: %s", err.message) + _LOGGER.debug("Additional calendar error detail: %s", str(err.detailed_error)) + raise InvalidIcsException(err.message) from err diff --git a/tests/components/remote_calendar/snapshots/test_calendar.ambr b/tests/components/remote_calendar/snapshots/test_calendar.ambr new file mode 100644 index 00000000000..e372be5255c --- /dev/null +++ b/tests/components/remote_calendar/snapshots/test_calendar.ambr @@ -0,0 +1,19 @@ +# serializer version: 1 +# name: test_calendar_examples[office365_invalid_tzid] + list([ + dict({ + 'description': None, + 'end': dict({ + 'dateTime': '2024-04-26T15:00:00-06:00', + }), + 'location': '', + 'recurrence_id': None, + 'rrule': None, + 'start': dict({ + 'dateTime': '2024-04-26T14:00:00-06:00', + }), + 'summary': 'Uffe', + 'uid': '040000008200E00074C5B7101A82E00800000000687C546B5596DA01000000000000000010000000309AE93C8C3A94489F90ADBEA30C2F2B', + }), + ]) +# --- diff --git a/tests/components/remote_calendar/test_calendar.py b/tests/components/remote_calendar/test_calendar.py index 6ae817321c3..a0c18383369 100644 --- a/tests/components/remote_calendar/test_calendar.py +++ b/tests/components/remote_calendar/test_calendar.py @@ -1,11 +1,13 @@ """Tests for calendar platform of Remote Calendar.""" from datetime import datetime +import pathlib import textwrap from httpx import Response import pytest import respx +from syrupy.assertion import SnapshotAssertion from homeassistant.const import STATE_OFF, STATE_ON from homeassistant.core import HomeAssistant @@ -21,6 +23,13 @@ from .conftest import ( from tests.common import MockConfigEntry +# Test data files with known calendars from various sources. You can add a new file +# in the testdata directory and add it will be parsed and tested. +TESTDATA_FILES = sorted( + pathlib.Path("tests/components/remote_calendar/testdata/").glob("*.ics") +) +TESTDATA_IDS = [f.stem for f in TESTDATA_FILES] + @respx.mock async def test_empty_calendar( @@ -392,3 +401,24 @@ async def test_all_day_iter_order( events = await get_events("2022-10-06T00:00:00Z", "2022-10-09T00:00:00Z") assert [event["summary"] for event in events] == event_order + + +@respx.mock +@pytest.mark.parametrize("ics_filename", TESTDATA_FILES, ids=TESTDATA_IDS) +async def test_calendar_examples( + hass: HomeAssistant, + config_entry: MockConfigEntry, + get_events: GetEventsFn, + ics_filename: pathlib.Path, + snapshot: SnapshotAssertion, +) -> None: + """Test parsing known calendars form test data files.""" + respx.get(CALENDER_URL).mock( + return_value=Response( + status_code=200, + text=ics_filename.read_text(), + ) + ) + await setup_integration(hass, config_entry) + events = await get_events("1997-07-14T00:00:00", "2025-07-01T00:00:00") + assert events == snapshot diff --git a/tests/components/remote_calendar/testdata/office365_invalid_tzid.ics b/tests/components/remote_calendar/testdata/office365_invalid_tzid.ics new file mode 100644 index 00000000000..bfadba446d2 --- /dev/null +++ b/tests/components/remote_calendar/testdata/office365_invalid_tzid.ics @@ -0,0 +1,58 @@ +BEGIN:VCALENDAR +METHOD:PUBLISH +PRODID:Microsoft Exchange Server 2010 +VERSION:2.0 +X-WR-CALNAME:Kalender +BEGIN:VTIMEZONE +TZID:W. Europe Standard Time +BEGIN:STANDARD +DTSTART:16010101T030000 +TZOFFSETFROM:+0200 +TZOFFSETTO:+0100 +RRULE:FREQ=YEARLY;INTERVAL=1;BYDAY=-1SU;BYMONTH=10 +END:STANDARD +BEGIN:DAYLIGHT +DTSTART:16010101T020000 +TZOFFSETFROM:+0100 +TZOFFSETTO:+0200 +RRULE:FREQ=YEARLY;INTERVAL=1;BYDAY=-1SU;BYMONTH=3 +END:DAYLIGHT +END:VTIMEZONE +BEGIN:VTIMEZONE +TZID:UTC +BEGIN:STANDARD +DTSTART:16010101T000000 +TZOFFSETFROM:+0000 +TZOFFSETTO:+0000 +END:STANDARD +BEGIN:DAYLIGHT +DTSTART:16010101T000000 +TZOFFSETFROM:+0000 +TZOFFSETTO:+0000 +END:DAYLIGHT +END:VTIMEZONE +BEGIN:VEVENT +UID:040000008200E00074C5B7101A82E00800000000687C546B5596DA01000000000000000 + 010000000309AE93C8C3A94489F90ADBEA30C2F2B +SUMMARY:Uffe +DTSTART;TZID=Customized Time Zone:20240426T140000 +DTEND;TZID=Customized Time Zone:20240426T150000 +CLASS:PUBLIC +PRIORITY:5 +DTSTAMP:20250417T155647Z +TRANSP:OPAQUE +STATUS:CONFIRMED +SEQUENCE:0 +LOCATION: +X-MICROSOFT-CDO-APPT-SEQUENCE:0 +X-MICROSOFT-CDO-BUSYSTATUS:BUSY +X-MICROSOFT-CDO-INTENDEDSTATUS:BUSY +X-MICROSOFT-CDO-ALLDAYEVENT:FALSE +X-MICROSOFT-CDO-IMPORTANCE:1 +X-MICROSOFT-CDO-INSTTYPE:0 +X-MICROSOFT-DONOTFORWARDMEETING:FALSE +X-MICROSOFT-DISALLOW-COUNTER:FALSE +X-MICROSOFT-REQUESTEDATTENDANCEMODE:DEFAULT +X-MICROSOFT-ISRESPONSEREQUESTED:FALSE +END:VEVENT +END:VCALENDAR From 0713ac497727afffdbc472da51c2c502974a6f89 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Mon, 5 May 2025 13:47:07 +0200 Subject: [PATCH 86/90] Cleanup invalid CONF_ID from samsungtv tests (#144252) --- tests/components/samsungtv/test_config_flow.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/tests/components/samsungtv/test_config_flow.py b/tests/components/samsungtv/test_config_flow.py index b15c007c109..79e24519a85 100644 --- a/tests/components/samsungtv/test_config_flow.py +++ b/tests/components/samsungtv/test_config_flow.py @@ -35,7 +35,6 @@ from homeassistant.components.samsungtv.const import ( from homeassistant.config_entries import ConfigEntryState from homeassistant.const import ( CONF_HOST, - CONF_ID, CONF_IP_ADDRESS, CONF_MAC, CONF_METHOD, @@ -104,14 +103,12 @@ MOCK_ZEROCONF_DATA = ZeroconfServiceInfo( ) MOCK_OLD_ENTRY = { CONF_HOST: "fake_host", - CONF_ID: "0d1cef00-00dc-1000-9c80-4844f7b172de_old", CONF_IP_ADDRESS: EXISTING_IP, CONF_METHOD: "legacy", CONF_PORT: None, } MOCK_LEGACY_ENTRY = { CONF_HOST: EXISTING_IP, - CONF_ID: "0d1cef00-00dc-1000-9c80-4844f7b172de_old", CONF_METHOD: "legacy", CONF_PORT: None, } @@ -1296,7 +1293,6 @@ async def test_update_old_entry(hass: HomeAssistant) -> None: config_entries_domain = hass.config_entries.async_entries(DOMAIN) assert len(config_entries_domain) == 1 assert entry is config_entries_domain[0] - assert entry.data[CONF_ID] == "0d1cef00-00dc-1000-9c80-4844f7b172de_old" assert entry.data[CONF_IP_ADDRESS] == EXISTING_IP assert not entry.unique_id @@ -1315,7 +1311,6 @@ async def test_update_old_entry(hass: HomeAssistant) -> None: entry2 = config_entries_domain[0] # check updated device info - assert entry2.data.get(CONF_ID) is not None assert entry2.data.get(CONF_IP_ADDRESS) is not None assert entry2.unique_id == "be9554b9-c9fb-41f4-8920-22da015376a4" From a073a6b01efd433ef4d02d73ff0a2e0b9f27f515 Mon Sep 17 00:00:00 2001 From: Markus Jacobsen Date: Mon, 5 May 2025 14:23:02 +0200 Subject: [PATCH 87/90] Fix hassfest expecting strings file for custom components (#135789) Co-authored-by: Joost Lekkerkerker Co-authored-by: Robert Resch --- script/hassfest/services.py | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/script/hassfest/services.py b/script/hassfest/services.py index 3a0ebed76fe..70f0a63ca76 100644 --- a/script/hassfest/services.py +++ b/script/hassfest/services.py @@ -233,7 +233,7 @@ def validate_services(config: Config, integration: Integration) -> None: # noqa ) if service_schema is None: continue - if "name" not in service_schema: + if "name" not in service_schema and integration.core: try: strings["services"][service_name]["name"] except KeyError: @@ -242,7 +242,7 @@ def validate_services(config: Config, integration: Integration) -> None: # noqa f"Service {service_name} has no name {error_msg_suffix}", ) - if "description" not in service_schema: + if "description" not in service_schema and integration.core: try: strings["services"][service_name]["description"] except KeyError: @@ -257,7 +257,7 @@ def validate_services(config: Config, integration: Integration) -> None: # noqa if "fields" in field_schema: # This is a section continue - if "name" not in field_schema: + if "name" not in field_schema and integration.core: try: strings["services"][service_name]["fields"][field_name]["name"] except KeyError: @@ -266,7 +266,7 @@ def validate_services(config: Config, integration: Integration) -> None: # noqa f"Service {service_name} has a field {field_name} with no name {error_msg_suffix}", ) - if "description" not in field_schema: + if "description" not in field_schema and integration.core: try: strings["services"][service_name]["fields"][field_name][ "description" @@ -296,13 +296,14 @@ def validate_services(config: Config, integration: Integration) -> None: # noqa if "fields" not in section_schema: # This is not a section continue - try: - strings["services"][service_name]["sections"][section_name]["name"] - except KeyError: - integration.add_error( - "services", - f"Service {service_name} has a section {section_name} with no name {error_msg_suffix}", - ) + if "name" not in section_schema and integration.core: + try: + strings["services"][service_name]["sections"][section_name]["name"] + except KeyError: + integration.add_error( + "services", + f"Service {service_name} has a section {section_name} with no name {error_msg_suffix}", + ) def validate(integrations: dict[str, Integration], config: Config) -> None: From c14ddedfae455c4a4cd61b03d64e0b316443c291 Mon Sep 17 00:00:00 2001 From: Luca De Petrillo <972242+lukakama@users.noreply.github.com> Date: Mon, 5 May 2025 14:30:36 +0200 Subject: [PATCH 88/90] Fix message corruption in picotts component (#141182) --- homeassistant/components/picotts/tts.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/picotts/tts.py b/homeassistant/components/picotts/tts.py index 44d33145b3d..54caf1a2b26 100644 --- a/homeassistant/components/picotts/tts.py +++ b/homeassistant/components/picotts/tts.py @@ -56,10 +56,15 @@ class PicoProvider(Provider): with tempfile.NamedTemporaryFile(suffix=".wav", delete=False) as tmpf: fname = tmpf.name - cmd = ["pico2wave", "--wave", fname, "-l", language, "--", message] - subprocess.call(cmd) + cmd = ["pico2wave", "--wave", fname, "-l", language] + result = subprocess.run(cmd, text=True, input=message, check=False) data = None try: + if result.returncode != 0: + _LOGGER.error( + "Error running pico2wave, return code: %s", result.returncode + ) + return (None, None) with open(fname, "rb") as voice: data = voice.read() except OSError: From 0043b18135fbc6675719782f0892f4b92cfa9f3f Mon Sep 17 00:00:00 2001 From: tronikos Date: Mon, 5 May 2025 05:36:58 -0700 Subject: [PATCH 89/90] Use names instead of statistic IDs in the Opower repair issue (#144018) * Use names instead of statistic IDs in the Opower repair issue * target_ids --- homeassistant/components/opower/coordinator.py | 2 +- homeassistant/components/opower/strings.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/opower/coordinator.py b/homeassistant/components/opower/coordinator.py index a8d24b68fd2..d03c30b7db0 100644 --- a/homeassistant/components/opower/coordinator.py +++ b/homeassistant/components/opower/coordinator.py @@ -443,7 +443,7 @@ class OpowerCoordinator(DataUpdateCoordinator[dict[str, Forecast]]): "energy_settings": "/config/energy", "target_ids": "\n".join( { - v + str(metadata_map[v]["name"]) for k, v in migration_map.items() if k in need_migration_source_ids } diff --git a/homeassistant/components/opower/strings.json b/homeassistant/components/opower/strings.json index b0516f266a1..f65aeb011ee 100644 --- a/homeassistant/components/opower/strings.json +++ b/homeassistant/components/opower/strings.json @@ -35,7 +35,7 @@ "issues": { "return_to_grid_migration": { "title": "Return to grid statistics for account: {utility_account_id}", - "description": "We found negative values in your existing consumption statistics, likely because you have solar. We split those in separate return statistics for a better experience in the Energy dashboard.\n\nPlease visit the [Energy configuration page]({energy_settings}) to add the following statistics in the **Return to grid** section:\n\n{target_ids}" + "description": "We found negative values in your existing consumption statistics, likely because you have solar. We split those in separate return statistics for a better experience in the Energy dashboard.\n\nPlease visit the [Energy configuration page]({energy_settings}) to add the following statistics in the **Return to grid** section:\n\n{target_ids}\n\nOnce you have added them, ignore this issue." } } } From aa8dfa760dc7603e6688fa9260cb5ccb4ea4a36b Mon Sep 17 00:00:00 2001 From: Luke Lashley Date: Mon, 5 May 2025 10:40:48 -0400 Subject: [PATCH 90/90] Bump Roborock Map Parser to 0.1.4 (#144260) Bump to 0.1.4 --- homeassistant/components/roborock/manifest.json | 2 +- requirements_all.txt | 2 +- requirements_test_all.txt | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/roborock/manifest.json b/homeassistant/components/roborock/manifest.json index 784d2c6ad27..444232b5843 100644 --- a/homeassistant/components/roborock/manifest.json +++ b/homeassistant/components/roborock/manifest.json @@ -20,6 +20,6 @@ "quality_scale": "silver", "requirements": [ "python-roborock==2.18.2", - "vacuum-map-parser-roborock==0.1.2" + "vacuum-map-parser-roborock==0.1.4" ] } diff --git a/requirements_all.txt b/requirements_all.txt index 7fb2f03f158..d21445b678d 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -3007,7 +3007,7 @@ url-normalize==2.2.1 uvcclient==0.12.1 # homeassistant.components.roborock -vacuum-map-parser-roborock==0.1.2 +vacuum-map-parser-roborock==0.1.4 # homeassistant.components.vallox vallox-websocket-api==5.3.0 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index 6f3df86cc20..838c5f4285a 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -2430,7 +2430,7 @@ url-normalize==2.2.1 uvcclient==0.12.1 # homeassistant.components.roborock -vacuum-map-parser-roborock==0.1.2 +vacuum-map-parser-roborock==0.1.4 # homeassistant.components.vallox vallox-websocket-api==5.3.0