From 21032ea7cd0ce7905a22f1eb0a5377233fcdba7b Mon Sep 17 00:00:00 2001 From: Teynar <97400690+teynar@users.noreply.github.com> Date: Sun, 16 Feb 2025 10:21:34 +0100 Subject: [PATCH 01/52] Add missing unit for Withings snore sensor (#138517) --- homeassistant/components/withings/sensor.py | 3 +++ tests/components/withings/snapshots/test_sensor.ambr | 11 ++++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/withings/sensor.py b/homeassistant/components/withings/sensor.py index 96cb433deba..28a0fbd1492 100644 --- a/homeassistant/components/withings/sensor.py +++ b/homeassistant/components/withings/sensor.py @@ -425,6 +425,9 @@ SLEEP_SENSORS = [ key="sleep_snoring", value_fn=lambda sleep_summary: sleep_summary.snoring, translation_key="snoring", + native_unit_of_measurement=UnitOfTime.SECONDS, + suggested_unit_of_measurement=UnitOfTime.MINUTES, + device_class=SensorDeviceClass.DURATION, state_class=SensorStateClass.MEASUREMENT, entity_registry_enabled_default=False, ), diff --git a/tests/components/withings/snapshots/test_sensor.ambr b/tests/components/withings/snapshots/test_sensor.ambr index 543cba05e21..ec9fc1ed3fc 100644 --- a/tests/components/withings/snapshots/test_sensor.ambr +++ b/tests/components/withings/snapshots/test_sensor.ambr @@ -3198,8 +3198,11 @@ }), 'name': None, 'options': dict({ + 'sensor.private': dict({ + 'suggested_unit_of_measurement': , + }), }), - 'original_device_class': None, + 'original_device_class': , 'original_icon': None, 'original_name': 'Snoring', 'platform': 'withings', @@ -3207,21 +3210,23 @@ 'supported_features': 0, 'translation_key': 'snoring', 'unique_id': 'withings_12345_sleep_snoring', - 'unit_of_measurement': None, + 'unit_of_measurement': , }) # --- # name: test_all_entities[sensor.henk_snoring-state] StateSnapshot({ 'attributes': ReadOnlyDict({ + 'device_class': 'duration', 'friendly_name': 'henk Snoring', 'state_class': , + 'unit_of_measurement': , }), 'context': , 'entity_id': 'sensor.henk_snoring', 'last_changed': , 'last_reported': , 'last_updated': , - 'state': '1080', + 'state': '18.0', }) # --- # name: test_all_entities[sensor.henk_snoring_episode_count-entry] From 3ce8e1683aac5f721e7720aa2b90f080abb1d630 Mon Sep 17 00:00:00 2001 From: Norbert Rittel Date: Sun, 16 Feb 2025 12:17:21 +0100 Subject: [PATCH 02/52] Fix sentence-casing in ZHA integration, capitalize names (#138636) * Fix sentence-casing in ZHA integration, capitalize names * Reorder title and description keys * Remove wrong trailing commas * Restore accidental deletion Co-authored-by: Franck Nijhof --------- Co-authored-by: Franck Nijhof --- homeassistant/components/zha/strings.json | 42 +++++++++++------------ 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/homeassistant/components/zha/strings.json b/homeassistant/components/zha/strings.json index c73a0989faa..2007adca0da 100644 --- a/homeassistant/components/zha/strings.json +++ b/homeassistant/components/zha/strings.json @@ -3,11 +3,11 @@ "flow_title": "{name}", "step": { "choose_serial_port": { - "title": "Select a Serial Port", + "title": "Select a serial port", + "description": "Select the serial port for your Zigbee radio", "data": { - "path": "Serial Device Path" - }, - "description": "Select the serial port for your Zigbee radio" + "path": "Serial device path" + } }, "confirm": { "description": "Do you want to set up {name}?" @@ -16,14 +16,14 @@ "description": "Do you want to set up {name}?" }, "manual_pick_radio_type": { + "title": "Select a radio type", + "description": "Pick your Zigbee radio type", "data": { - "radio_type": "Radio Type" - }, - "title": "[%key:component::zha::config::step::manual_pick_radio_type::data::radio_type%]", - "description": "Pick your Zigbee radio type" + "radio_type": "Radio type" + } }, "manual_port_config": { - "title": "Serial Port Settings", + "title": "Serial port settings", "description": "Enter the serial port settings", "data": { "path": "Serial device path", @@ -36,7 +36,7 @@ "description": "The radio you are using ({name}) is not recommended and support for it may be removed in the future. Please see the Zigbee Home Automation integration's documentation for [a list of recommended adapters]({docs_recommended_adapters_url})." }, "choose_formation_strategy": { - "title": "Network Formation", + "title": "Network formation", "description": "Choose the network settings for your radio.", "menu_options": { "form_new_network": "Erase network settings and create a new network", @@ -47,21 +47,21 @@ } }, "choose_automatic_backup": { - "title": "Restore Automatic Backup", + "title": "Restore automatic backup", "description": "Restore your network settings from an automatic backup", "data": { "choose_automatic_backup": "Choose an automatic backup" } }, "upload_manual_backup": { - "title": "Upload a Manual Backup", + "title": "Upload a manual backup", "description": "Restore your network settings from an uploaded backup JSON file. You can download one from a different ZHA installation from **Network Settings**, or use a Zigbee2MQTT `coordinator_backup.json` file.", "data": { "uploaded_backup_file": "Upload a file" } }, "maybe_confirm_ezsp_restore": { - "title": "Overwrite Radio IEEE Address", + "title": "Overwrite radio IEEE address", "description": "Your backup has a different IEEE address than your radio. For your network to function properly, the IEEE address of your radio should also be changed.\n\nThis is a permanent operation.", "data": { "overwrite_coordinator_ieee": "Permanently replace the radio IEEE address" @@ -74,10 +74,10 @@ }, "abort": { "single_instance_allowed": "[%key:common::config_flow::abort::single_instance_allowed%]", - "not_zha_device": "This device is not a zha device", - "usb_probe_failed": "Failed to probe the usb device", + "not_zha_device": "This device is not a ZHA device", + "usb_probe_failed": "Failed to probe the USB device", "wrong_firmware_installed": "Your device is running the wrong firmware and cannot be used with ZHA until the correct firmware is installed. [A repair has been created]({repair_url}) with more information and instructions for how to fix this.", - "invalid_zeroconf_data": "The coordinator has invalid zeroconf service info and cannot be identified by ZHA" + "invalid_zeroconf_data": "The coordinator has invalid Zeroconf service info and cannot be identified by ZHA" } }, "options": { @@ -307,7 +307,7 @@ } }, "set_zigbee_cluster_attribute": { - "name": "Set zigbee cluster attribute", + "name": "Set Zigbee cluster attribute", "description": "Sets an attribute value for the specified cluster on the specified entity.", "fields": { "ieee": { @@ -323,7 +323,7 @@ "description": "ZCL cluster to retrieve attributes for." }, "cluster_type": { - "name": "Cluster Type", + "name": "Cluster type", "description": "Type of the cluster." }, "attribute": { @@ -341,7 +341,7 @@ } }, "issue_zigbee_cluster_command": { - "name": "Issue zigbee cluster command", + "name": "Issue Zigbee cluster command", "description": "Issues a command on the specified cluster on the specified entity.", "fields": { "ieee": { @@ -383,8 +383,8 @@ } }, "issue_zigbee_group_command": { - "name": "Issue zigbee group command", - "description": "Issue command on the specified cluster on the specified group.", + "name": "Issue Zigbee group command", + "description": "Issues a command on the specified cluster on the specified group.", "fields": { "group": { "name": "Group", From 95b1cf465b4cfe34a3395d35184dbb8c20117841 Mon Sep 17 00:00:00 2001 From: Josef Zweck Date: Sun, 16 Feb 2025 13:08:01 +0100 Subject: [PATCH 03/52] Use gibibytes for onedrive (#138637) * Use gibibytes for onedrive * also to strings --- homeassistant/components/onedrive/sensor.py | 6 +++--- .../components/onedrive/strings.json | 4 ++-- tests/components/onedrive/const.py | 4 ++-- .../onedrive/snapshots/test_sensor.ambr | 20 +++++++++---------- 4 files changed, 17 insertions(+), 17 deletions(-) diff --git a/homeassistant/components/onedrive/sensor.py b/homeassistant/components/onedrive/sensor.py index 35c59d0c644..0ca2b166e3f 100644 --- a/homeassistant/components/onedrive/sensor.py +++ b/homeassistant/components/onedrive/sensor.py @@ -36,7 +36,7 @@ DRIVE_STATE_ENTITIES: tuple[OneDriveSensorEntityDescription, ...] = ( key="total_size", value_fn=lambda quota: quota.total, native_unit_of_measurement=UnitOfInformation.BYTES, - suggested_unit_of_measurement=UnitOfInformation.GIGABYTES, + suggested_unit_of_measurement=UnitOfInformation.GIBIBYTES, suggested_display_precision=0, device_class=SensorDeviceClass.DATA_SIZE, entity_category=EntityCategory.DIAGNOSTIC, @@ -46,7 +46,7 @@ DRIVE_STATE_ENTITIES: tuple[OneDriveSensorEntityDescription, ...] = ( key="used_size", value_fn=lambda quota: quota.used, native_unit_of_measurement=UnitOfInformation.BYTES, - suggested_unit_of_measurement=UnitOfInformation.GIGABYTES, + suggested_unit_of_measurement=UnitOfInformation.GIBIBYTES, suggested_display_precision=2, device_class=SensorDeviceClass.DATA_SIZE, entity_category=EntityCategory.DIAGNOSTIC, @@ -55,7 +55,7 @@ DRIVE_STATE_ENTITIES: tuple[OneDriveSensorEntityDescription, ...] = ( key="remaining_size", value_fn=lambda quota: quota.remaining, native_unit_of_measurement=UnitOfInformation.BYTES, - suggested_unit_of_measurement=UnitOfInformation.GIGABYTES, + suggested_unit_of_measurement=UnitOfInformation.GIBIBYTES, suggested_display_precision=2, device_class=SensorDeviceClass.DATA_SIZE, entity_category=EntityCategory.DIAGNOSTIC, diff --git a/homeassistant/components/onedrive/strings.json b/homeassistant/components/onedrive/strings.json index 3a9f6d06594..20d139a4bc0 100644 --- a/homeassistant/components/onedrive/strings.json +++ b/homeassistant/components/onedrive/strings.json @@ -32,11 +32,11 @@ "issues": { "drive_full": { "title": "OneDrive data cap exceeded", - "description": "Your OneDrive has exceeded your quota limit. This means your next backup will fail. Please free up some space or upgrade your OneDrive plan. Currently using {used} GB of {total} GB." + "description": "Your OneDrive has exceeded your quota limit. This means your next backup will fail. Please free up some space or upgrade your OneDrive plan. Currently using {used} GiB of {total} GiB." }, "drive_almost_full": { "title": "OneDrive near data cap", - "description": "Your OneDrive is near your quota limit. If you go over this limit your drive will be temporarily frozen and your backups will start failing. Please free up some space or upgrade your OneDrive plan. Currently using {used} GB of {total} GB." + "description": "Your OneDrive is near your quota limit. If you go over this limit your drive will be temporarily frozen and your backups will start failing. Please free up some space or upgrade your OneDrive plan. Currently using {used} GiB of {total} GiB." } }, "exceptions": { diff --git a/tests/components/onedrive/const.py b/tests/components/onedrive/const.py index 44f50aa625d..0c04a6f4c82 100644 --- a/tests/components/onedrive/const.py +++ b/tests/components/onedrive/const.py @@ -110,9 +110,9 @@ MOCK_DRIVE = Drive( owner=IDENTITY_SET, quota=DriveQuota( deleted=5, - remaining=750000000, + remaining=805306368, state=DriveState.NEARING, - total=5000000000, + total=5368709120, used=4250000000, ), ) diff --git a/tests/components/onedrive/snapshots/test_sensor.ambr b/tests/components/onedrive/snapshots/test_sensor.ambr index 43c6921b0e5..742c069f206 100644 --- a/tests/components/onedrive/snapshots/test_sensor.ambr +++ b/tests/components/onedrive/snapshots/test_sensor.ambr @@ -86,7 +86,7 @@ 'suggested_display_precision': 2, }), 'sensor.private': dict({ - 'suggested_unit_of_measurement': , + 'suggested_unit_of_measurement': , }), }), 'original_device_class': , @@ -97,7 +97,7 @@ 'supported_features': 0, 'translation_key': 'remaining_size', 'unique_id': 'mock_drive_id_remaining_size', - 'unit_of_measurement': , + 'unit_of_measurement': , }) # --- # name: test_sensors[sensor.my_drive_remaining_storage-state] @@ -105,7 +105,7 @@ 'attributes': ReadOnlyDict({ 'device_class': 'data_size', 'friendly_name': 'My Drive Remaining storage', - 'unit_of_measurement': , + 'unit_of_measurement': , }), 'context': , 'entity_id': 'sensor.my_drive_remaining_storage', @@ -141,7 +141,7 @@ 'suggested_display_precision': 0, }), 'sensor.private': dict({ - 'suggested_unit_of_measurement': , + 'suggested_unit_of_measurement': , }), }), 'original_device_class': , @@ -152,7 +152,7 @@ 'supported_features': 0, 'translation_key': 'total_size', 'unique_id': 'mock_drive_id_total_size', - 'unit_of_measurement': , + 'unit_of_measurement': , }) # --- # name: test_sensors[sensor.my_drive_total_available_storage-state] @@ -160,7 +160,7 @@ 'attributes': ReadOnlyDict({ 'device_class': 'data_size', 'friendly_name': 'My Drive Total available storage', - 'unit_of_measurement': , + 'unit_of_measurement': , }), 'context': , 'entity_id': 'sensor.my_drive_total_available_storage', @@ -196,7 +196,7 @@ 'suggested_display_precision': 2, }), 'sensor.private': dict({ - 'suggested_unit_of_measurement': , + 'suggested_unit_of_measurement': , }), }), 'original_device_class': , @@ -207,7 +207,7 @@ 'supported_features': 0, 'translation_key': 'used_size', 'unique_id': 'mock_drive_id_used_size', - 'unit_of_measurement': , + 'unit_of_measurement': , }) # --- # name: test_sensors[sensor.my_drive_used_storage-state] @@ -215,13 +215,13 @@ 'attributes': ReadOnlyDict({ 'device_class': 'data_size', 'friendly_name': 'My Drive Used storage', - 'unit_of_measurement': , + 'unit_of_measurement': , }), 'context': , 'entity_id': 'sensor.my_drive_used_storage', 'last_changed': , 'last_reported': , 'last_updated': , - 'state': '4.25', + 'state': '3.95812094211578', }) # --- From 7f3270e982a80b2fd42a26835a827d31206872f8 Mon Sep 17 00:00:00 2001 From: Luca Bensi <130408125+lucab-91@users.noreply.github.com> Date: Sun, 16 Feb 2025 13:09:15 +0100 Subject: [PATCH 04/52] Bump pysmarty2 to 0.10.2 (#138625) --- homeassistant/components/smarty/manifest.json | 2 +- requirements_all.txt | 2 +- requirements_test_all.txt | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/smarty/manifest.json b/homeassistant/components/smarty/manifest.json index ca3133d8add..c295647b8e5 100644 --- a/homeassistant/components/smarty/manifest.json +++ b/homeassistant/components/smarty/manifest.json @@ -7,5 +7,5 @@ "integration_type": "hub", "iot_class": "local_polling", "loggers": ["pymodbus", "pysmarty2"], - "requirements": ["pysmarty2==0.10.1"] + "requirements": ["pysmarty2==0.10.2"] } diff --git a/requirements_all.txt b/requirements_all.txt index b7081812b44..de28799abdd 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -2310,7 +2310,7 @@ pysmartapp==0.3.5 pysmartthings==0.7.8 # homeassistant.components.smarty -pysmarty2==0.10.1 +pysmarty2==0.10.2 # homeassistant.components.smhi pysmhi==1.0.0 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index 4c995a6bead..4e8544fcfbb 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -1882,7 +1882,7 @@ pysmartapp==0.3.5 pysmartthings==0.7.8 # homeassistant.components.smarty -pysmarty2==0.10.1 +pysmarty2==0.10.2 # homeassistant.components.smhi pysmhi==1.0.0 From e767863ea4229ca53d23f0378ad2e29aa153ba37 Mon Sep 17 00:00:00 2001 From: Norbert Rittel Date: Sun, 16 Feb 2025 13:17:47 +0100 Subject: [PATCH 05/52] Replace opentherm_gw action key name with friendly name for UI (#138634) --- homeassistant/components/opentherm_gw/strings.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/opentherm_gw/strings.json b/homeassistant/components/opentherm_gw/strings.json index 405af126c03..b49dea4a267 100644 --- a/homeassistant/components/opentherm_gw/strings.json +++ b/homeassistant/components/opentherm_gw/strings.json @@ -385,7 +385,7 @@ }, "set_central_heating_ovrd": { "name": "Set central heating override", - "description": "Sets the central heating override option on the gateway. When overriding the control setpoint (via a set_control_setpoint action with a value other than 0), the gateway automatically enables the central heating override to start heating. This action can then be used to control the central heating override status. To return control of the central heating to the thermostat, use the set_control_setpoint action with temperature value 0. You will only need this if you are writing your own software thermostat.", + "description": "Sets the central heating override option on the gateway. When overriding the control setpoint (via a 'Set control set point' action with a value other than 0), the gateway automatically enables the central heating override to start heating. This action can then be used to control the central heating override status. To return control of the central heating to the thermostat, use the 'Set control set point' action with temperature value 0. You will only need this if you are writing your own software thermostat.", "fields": { "gateway_id": { "name": "[%key:component::opentherm_gw::services::reset_gateway::fields::gateway_id::name%]", @@ -393,7 +393,7 @@ }, "ch_override": { "name": "Central heating override", - "description": "The desired boolean value for the central heating override." + "description": "Whether to enable or disable the override." } } }, From 9e15a33c42d867b8a48c57f803aece45ac7c3384 Mon Sep 17 00:00:00 2001 From: Norbert Rittel Date: Sun, 16 Feb 2025 14:46:08 +0100 Subject: [PATCH 06/52] Fix sentence-casing and capitalization of "Zigbee" in smlight (#138647) --- homeassistant/components/smlight/strings.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/smlight/strings.json b/homeassistant/components/smlight/strings.json index 21ff5098d27..ca52f6fea38 100644 --- a/homeassistant/components/smlight/strings.json +++ b/homeassistant/components/smlight/strings.json @@ -2,7 +2,7 @@ "config": { "step": { "user": { - "description": "Set up SMLIGHT Zigbee Integration", + "description": "Set up SMLIGHT Zigbee integration", "data": { "host": "[%key:common::config_flow::data::host%]" }, @@ -111,7 +111,7 @@ "name": "Zigbee flash mode" }, "reconnect_zigbee_router": { - "name": "Reconnect zigbee router" + "name": "Reconnect Zigbee router" } }, "switch": { From 2d5e920de0e3dc52be5e072ea7679665aebfc46d Mon Sep 17 00:00:00 2001 From: Jonas Fors Lellky Date: Sun, 16 Feb 2025 14:55:05 +0100 Subject: [PATCH 07/52] Flexit bacnet/quality preparations (#138514) Add data_description for config flow --- homeassistant/components/flexit_bacnet/strings.json | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/homeassistant/components/flexit_bacnet/strings.json b/homeassistant/components/flexit_bacnet/strings.json index f7c54c88050..488d93fbd61 100644 --- a/homeassistant/components/flexit_bacnet/strings.json +++ b/homeassistant/components/flexit_bacnet/strings.json @@ -5,6 +5,10 @@ "data": { "ip_address": "[%key:common::config_flow::data::ip%]", "device_id": "[%key:common::config_flow::data::device%]" + }, + "data_description": { + "ip_address": "The IP address of the Flexit Nordic device", + "device_id": "The device ID of the Flexit Nordic device" } } }, From f67fb9985e378467cc5d8aac07ebd636c1e76bda Mon Sep 17 00:00:00 2001 From: Michael <35783820+mib1185@users.noreply.github.com> Date: Sun, 16 Feb 2025 15:12:16 +0100 Subject: [PATCH 08/52] Allow wifi switches for mesh repeaters in AVM Fritz!Box Tools (#135456) * create wifi switches for mesh slaves, but disable them by default * check if mesh isbased on wifi uplink * fix --- homeassistant/components/fritz/coordinator.py | 7 +++++++ homeassistant/components/fritz/switch.py | 6 +++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/homeassistant/components/fritz/coordinator.py b/homeassistant/components/fritz/coordinator.py index 38d76c92871..d60232ec8ad 100644 --- a/homeassistant/components/fritz/coordinator.py +++ b/homeassistant/components/fritz/coordinator.py @@ -196,6 +196,7 @@ class FritzBoxTools(DataUpdateCoordinator[UpdateCoordinatorDataType]): self.hass = hass self.host = host self.mesh_role = MeshRoles.NONE + self.mesh_wifi_uplink = False self.device_conn_type: str | None = None self.device_is_router: bool = False self.password = password @@ -610,6 +611,12 @@ class FritzBoxTools(DataUpdateCoordinator[UpdateCoordinatorDataType]): ssid=interf.get("ssid", ""), type=interf["type"], ) + + if interf["type"].lower() == "wlan" and interf[ + "name" + ].lower().startswith("uplink"): + self.mesh_wifi_uplink = True + if dr.format_mac(int_mac) == self.mac: self.mesh_role = MeshRoles(node["mesh_role"]) diff --git a/homeassistant/components/fritz/switch.py b/homeassistant/components/fritz/switch.py index 1548f8fc755..8b4816f7451 100644 --- a/homeassistant/components/fritz/switch.py +++ b/homeassistant/components/fritz/switch.py @@ -207,8 +207,9 @@ async def async_all_entities_list( local_ip: str, ) -> list[Entity]: """Get a list of all entities.""" - if avm_wrapper.mesh_role == MeshRoles.SLAVE: + if not avm_wrapper.mesh_wifi_uplink: + return [*await _async_wifi_entities_list(avm_wrapper, device_friendly_name)] return [] return [ @@ -565,6 +566,9 @@ class FritzBoxWifiSwitch(FritzBoxBaseSwitch): self._attributes = {} self._attr_entity_category = EntityCategory.CONFIG + self._attr_entity_registry_enabled_default = ( + avm_wrapper.mesh_role is not MeshRoles.SLAVE + ) self._network_num = network_num switch_info = SwitchInfo( From 7063636db6a03c8b86b95215a3daf11470bce56a Mon Sep 17 00:00:00 2001 From: Jonas Fors Lellky Date: Sun, 16 Feb 2025 17:06:09 +0100 Subject: [PATCH 09/52] Add quality scale bronze for flexit_bacnet (#138309) * Add quality scale bronze for flexit_bacnet * Add new line at end of file * Remove flexit_bacnet from list of integrations without quality scale * Add missing translation strings * Fix review comments * Remove flexit_bacnet from list of integrations without quality scale * Review comment Co-authored-by: Josef Zweck * Review comment Co-authored-by: Josef Zweck * Add the complete list of quality scale rules * Fix lint error * Use correct formatting for todos * Fix lint error * Set all rules above bronze to todo * Update status for rules that are done * Update homeassistant/components/flexit_bacnet/quality_scale.yaml * Update homeassistant/components/flexit_bacnet/quality_scale.yaml --------- Co-authored-by: Josef Zweck --- .../components/flexit_bacnet/manifest.json | 1 + .../flexit_bacnet/quality_scale.yaml | 88 +++++++++++++++++++ script/hassfest/quality_scale.py | 2 - 3 files changed, 89 insertions(+), 2 deletions(-) create mode 100644 homeassistant/components/flexit_bacnet/quality_scale.yaml diff --git a/homeassistant/components/flexit_bacnet/manifest.json b/homeassistant/components/flexit_bacnet/manifest.json index 6f6b094c950..5ef3f11a7b7 100644 --- a/homeassistant/components/flexit_bacnet/manifest.json +++ b/homeassistant/components/flexit_bacnet/manifest.json @@ -6,5 +6,6 @@ "documentation": "https://www.home-assistant.io/integrations/flexit_bacnet", "integration_type": "device", "iot_class": "local_polling", + "quality_scale": "bronze", "requirements": ["flexit_bacnet==2.2.3"] } diff --git a/homeassistant/components/flexit_bacnet/quality_scale.yaml b/homeassistant/components/flexit_bacnet/quality_scale.yaml new file mode 100644 index 00000000000..9b7e4deb4c0 --- /dev/null +++ b/homeassistant/components/flexit_bacnet/quality_scale.yaml @@ -0,0 +1,88 @@ +rules: + # Bronze + action-setup: + status: exempt + comment: | + Integration does not define custom actions. + appropriate-polling: done + brands: done + common-modules: done + config-flow-test-coverage: done + config-flow: done + dependency-transparency: done + docs-actions: + status: exempt + comment: | + This integration does not use any actions. + docs-high-level-description: done + docs-installation-instructions: done + docs-removal-instructions: done + entity-event-setup: + status: exempt + comment: | + Entities don't subscribe to events explicitly + entity-unique-id: done + has-entity-name: done + runtime-data: done + test-before-configure: done + test-before-setup: + status: done + comment: | + Done implicitly with `await coordinator.async_config_entry_first_refresh()`. + unique-config-entry: done + # Silver + action-exceptions: todo + config-entry-unloading: done + docs-configuration-parameters: + status: exempt + comment: | + Integration does not use options flow. + docs-installation-parameters: done + entity-unavailable: + status: done + comment: | + Done implicitly with coordinator. + integration-owner: done + log-when-unavailable: + status: done + comment: | + Done implicitly with coordinator. + parallel-updates: todo + reauthentication-flow: todo + test-coverage: todo + # Gold + entity-translations: done + entity-device-class: done + devices: done + entity-category: todo + entity-disabled-by-default: todo + discovery: todo + stale-devices: + status: exempt + comment: | + Device type integration. + diagnostics: todo + exception-translations: todo + icon-translations: done + reconfiguration-flow: todo + dynamic-devices: + status: exempt + comment: | + Device type integration. + discovery-update-info: todo + repair-issues: + status: exempt + comment: | + This is not applicable for this integration. + docs-use-cases: todo + docs-supported-devices: todo + docs-supported-functions: todo + docs-data-update: done + docs-known-limitations: todo + docs-troubleshooting: todo + docs-examples: todo + + # Platinum + async-dependency: todo + inject-websession: todo + strict-typing: done diff --git a/script/hassfest/quality_scale.py b/script/hassfest/quality_scale.py index 12b5932695d..bd8a5a9f318 100644 --- a/script/hassfest/quality_scale.py +++ b/script/hassfest/quality_scale.py @@ -391,7 +391,6 @@ INTEGRATIONS_WITHOUT_QUALITY_SCALE_FILE = [ "fjaraskupan", "fleetgo", "flexit", - "flexit_bacnet", "flic", "flick_electric", "flipr", @@ -1455,7 +1454,6 @@ INTEGRATIONS_WITHOUT_SCALE = [ "fjaraskupan", "fleetgo", "flexit", - "flexit_bacnet", "flic", "flick_electric", "flipr", From e0b50ee1e21e5d8b1986519a4104b6d9a3ad3c7a Mon Sep 17 00:00:00 2001 From: Keilin Bickar Date: Sun, 16 Feb 2025 13:04:45 -0500 Subject: [PATCH 10/52] Bump sense_energy to 0.13.5 (#138659) --- homeassistant/components/emulated_kasa/manifest.json | 2 +- homeassistant/components/sense/manifest.json | 2 +- requirements_all.txt | 2 +- requirements_test_all.txt | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/homeassistant/components/emulated_kasa/manifest.json b/homeassistant/components/emulated_kasa/manifest.json index da3912a9d25..384dd3556a9 100644 --- a/homeassistant/components/emulated_kasa/manifest.json +++ b/homeassistant/components/emulated_kasa/manifest.json @@ -6,5 +6,5 @@ "iot_class": "local_push", "loggers": ["sense_energy"], "quality_scale": "internal", - "requirements": ["sense-energy==0.13.4"] + "requirements": ["sense-energy==0.13.5"] } diff --git a/homeassistant/components/sense/manifest.json b/homeassistant/components/sense/manifest.json index 966488b6a48..a7cee28f9c9 100644 --- a/homeassistant/components/sense/manifest.json +++ b/homeassistant/components/sense/manifest.json @@ -20,5 +20,5 @@ "documentation": "https://www.home-assistant.io/integrations/sense", "iot_class": "cloud_polling", "loggers": ["sense_energy"], - "requirements": ["sense-energy==0.13.4"] + "requirements": ["sense-energy==0.13.5"] } diff --git a/requirements_all.txt b/requirements_all.txt index de28799abdd..abbda498827 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -2688,7 +2688,7 @@ sendgrid==6.8.2 # homeassistant.components.emulated_kasa # homeassistant.components.sense -sense-energy==0.13.4 +sense-energy==0.13.5 # homeassistant.components.sensirion_ble sensirion-ble==0.1.1 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index 4e8544fcfbb..f6223d56c2f 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -2167,7 +2167,7 @@ securetar==2025.1.4 # homeassistant.components.emulated_kasa # homeassistant.components.sense -sense-energy==0.13.4 +sense-energy==0.13.5 # homeassistant.components.sensirion_ble sensirion-ble==0.1.1 From ccd0e27e84bf66c83e76685125e54122eea9fdbb Mon Sep 17 00:00:00 2001 From: Michael <35783820+mib1185@users.noreply.github.com> Date: Sun, 16 Feb 2025 20:00:17 +0100 Subject: [PATCH 11/52] Allow renaming of backup files in Synology DSM (#138652) * get backup base file name from meta file * use BackupNotFound --- .../components/synology_dsm/backup.py | 23 ++++++++++++------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/homeassistant/components/synology_dsm/backup.py b/homeassistant/components/synology_dsm/backup.py index 83c3455bdf1..670c4c9bef0 100644 --- a/homeassistant/components/synology_dsm/backup.py +++ b/homeassistant/components/synology_dsm/backup.py @@ -14,6 +14,7 @@ from homeassistant.components.backup import ( AgentBackup, BackupAgent, BackupAgentError, + BackupNotFound, suggested_filename, ) from homeassistant.config_entries import ConfigEntry @@ -101,6 +102,7 @@ class SynologyDSMBackupAgent(BackupAgent): ) syno_data: SynologyDSMData = hass.data[DOMAIN][entry.unique_id] self.api = syno_data.api + self.backup_base_names: dict[str, str] = {} @property def _file_station(self) -> SynoFileStation: @@ -109,18 +111,19 @@ class SynologyDSMBackupAgent(BackupAgent): assert self.api.file_station return self.api.file_station - async def _async_suggested_filenames( + async def _async_backup_filenames( self, backup_id: str, ) -> tuple[str, str]: - """Suggest filenames for the backup. + """Return the actual backup filenames. :param backup_id: The ID of the backup that was returned in async_list_backups. :return: A tuple of tar_filename and meta_filename """ - if (backup := await self.async_get_backup(backup_id)) is None: - raise BackupAgentError("Backup not found") - return suggested_filenames(backup) + if await self.async_get_backup(backup_id) is None: + raise BackupNotFound + base_name = self.backup_base_names[backup_id] + return (f"{base_name}.tar", f"{base_name}_meta.json") async def async_download_backup( self, @@ -132,7 +135,7 @@ class SynologyDSMBackupAgent(BackupAgent): :param backup_id: The ID of the backup that was returned in async_list_backups. :return: An async iterator that yields bytes. """ - (filename_tar, _) = await self._async_suggested_filenames(backup_id) + (filename_tar, _) = await self._async_backup_filenames(backup_id) try: resp = await self._file_station.download_file( @@ -193,7 +196,7 @@ class SynologyDSMBackupAgent(BackupAgent): :param backup_id: The ID of the backup that was returned in async_list_backups. """ try: - (filename_tar, filename_meta) = await self._async_suggested_filenames( + (filename_tar, filename_meta) = await self._async_backup_filenames( backup_id ) except BackupAgentError: @@ -247,6 +250,7 @@ class SynologyDSMBackupAgent(BackupAgent): assert files backups: dict[str, AgentBackup] = {} + backup_base_names: dict[str, str] = {} for file in files: if file.name.endswith("_meta.json"): try: @@ -255,7 +259,10 @@ class SynologyDSMBackupAgent(BackupAgent): LOGGER.error("Failed to download meta data: %s", err) continue agent_backup = AgentBackup.from_dict(meta_data) - backups[agent_backup.backup_id] = agent_backup + backup_id = agent_backup.backup_id + backups[backup_id] = agent_backup + backup_base_names[backup_id] = file.name.replace("_meta.json", "") + self.backup_base_names = backup_base_names return backups async def async_get_backup( From 0b7ec9644889a88d4f27bc342dc3681269202ee4 Mon Sep 17 00:00:00 2001 From: Martin Hjelmare Date: Sun, 16 Feb 2025 21:17:26 +0100 Subject: [PATCH 12/52] Improve remember the milk storage (#138618) --- .../components/remember_the_milk/__init__.py | 67 +++++--- tests/components/remember_the_milk/const.py | 2 +- .../components/remember_the_milk/test_init.py | 155 ++++++++++++------ 3 files changed, 148 insertions(+), 76 deletions(-) diff --git a/homeassistant/components/remember_the_milk/__init__.py b/homeassistant/components/remember_the_milk/__init__.py index 0d1c54efb56..2a95ed46b20 100644 --- a/homeassistant/components/remember_the_milk/__init__.py +++ b/homeassistant/components/remember_the_milk/__init__.py @@ -2,7 +2,7 @@ import json import logging -import os +from pathlib import Path from rtmapi import Rtm import voluptuous as vol @@ -160,56 +160,64 @@ class RememberTheMilkConfiguration: This class stores the authentication token it get from the backend. """ - def __init__(self, hass): + def __init__(self, hass: HomeAssistant) -> None: """Create new instance of configuration.""" self._config_file_path = hass.config.path(CONFIG_FILE_NAME) - if not os.path.isfile(self._config_file_path): - self._config = {} - return + self._config = {} + _LOGGER.debug("Loading configuration from file: %s", self._config_file_path) try: - _LOGGER.debug("Loading configuration from file: %s", self._config_file_path) - with open(self._config_file_path, encoding="utf8") as config_file: - self._config = json.load(config_file) - except ValueError: - _LOGGER.error( - "Failed to load configuration file, creating a new one: %s", + self._config = json.loads( + Path(self._config_file_path).read_text(encoding="utf8") + ) + except FileNotFoundError: + _LOGGER.debug("Missing configuration file: %s", self._config_file_path) + except OSError: + _LOGGER.debug( + "Failed to read from configuration file, %s, using empty configuration", + self._config_file_path, + ) + except ValueError: + _LOGGER.error( + "Failed to parse configuration file, %s, using empty configuration", self._config_file_path, ) - self._config = {} - def save_config(self): + def _save_config(self) -> None: """Write the configuration to a file.""" - with open(self._config_file_path, "w", encoding="utf8") as config_file: - json.dump(self._config, config_file) + Path(self._config_file_path).write_text( + json.dumps(self._config), encoding="utf8" + ) - def get_token(self, profile_name): + def get_token(self, profile_name: str) -> str | None: """Get the server token for a profile.""" if profile_name in self._config: return self._config[profile_name][CONF_TOKEN] return None - def set_token(self, profile_name, token): + def set_token(self, profile_name: str, token: str) -> None: """Store a new server token for a profile.""" self._initialize_profile(profile_name) self._config[profile_name][CONF_TOKEN] = token - self.save_config() + self._save_config() - def delete_token(self, profile_name): + def delete_token(self, profile_name: str) -> None: """Delete a token for a profile. Usually called when the token has expired. """ self._config.pop(profile_name, None) - self.save_config() + self._save_config() - def _initialize_profile(self, profile_name): + def _initialize_profile(self, profile_name: str) -> None: """Initialize the data structures for a profile.""" if profile_name not in self._config: self._config[profile_name] = {} if CONF_ID_MAP not in self._config[profile_name]: self._config[profile_name][CONF_ID_MAP] = {} - def get_rtm_id(self, profile_name, hass_id): + def get_rtm_id( + self, profile_name: str, hass_id: str + ) -> tuple[str, str, str] | None: """Get the RTM ids for a Home Assistant task ID. The id of a RTM tasks consists of the tuple: @@ -221,7 +229,14 @@ class RememberTheMilkConfiguration: return None return ids[CONF_LIST_ID], ids[CONF_TIMESERIES_ID], ids[CONF_TASK_ID] - def set_rtm_id(self, profile_name, hass_id, list_id, time_series_id, rtm_task_id): + def set_rtm_id( + self, + profile_name: str, + hass_id: str, + list_id: str, + time_series_id: str, + rtm_task_id: str, + ) -> None: """Add/Update the RTM task ID for a Home Assistant task IS.""" self._initialize_profile(profile_name) id_tuple = { @@ -230,11 +245,11 @@ class RememberTheMilkConfiguration: CONF_TASK_ID: rtm_task_id, } self._config[profile_name][CONF_ID_MAP][hass_id] = id_tuple - self.save_config() + self._save_config() - def delete_rtm_id(self, profile_name, hass_id): + def delete_rtm_id(self, profile_name: str, hass_id: str) -> None: """Delete a key mapping.""" self._initialize_profile(profile_name) if hass_id in self._config[profile_name][CONF_ID_MAP]: del self._config[profile_name][CONF_ID_MAP][hass_id] - self.save_config() + self._save_config() diff --git a/tests/components/remember_the_milk/const.py b/tests/components/remember_the_milk/const.py index 8423c7f4651..3f1d0067219 100644 --- a/tests/components/remember_the_milk/const.py +++ b/tests/components/remember_the_milk/const.py @@ -8,7 +8,7 @@ JSON_STRING = json.dumps( { "myprofile": { "token": "mytoken", - "id_map": {"1234": {"list_id": "0", "timeseries_id": "1", "task_id": "2"}}, + "id_map": {"123": {"list_id": "1", "timeseries_id": "2", "task_id": "3"}}, } } ) diff --git a/tests/components/remember_the_milk/test_init.py b/tests/components/remember_the_milk/test_init.py index 3ada2d343fe..517c8cebc0e 100644 --- a/tests/components/remember_the_milk/test_init.py +++ b/tests/components/remember_the_milk/test_init.py @@ -1,6 +1,9 @@ -"""Tests for the Remember The Milk component.""" +"""Tests for the Remember The Milk integration.""" -from unittest.mock import Mock, mock_open, patch +import json +from unittest.mock import mock_open, patch + +import pytest from homeassistant.components import remember_the_milk as rtm from homeassistant.core import HomeAssistant @@ -8,63 +11,117 @@ from homeassistant.core import HomeAssistant from .const import JSON_STRING, PROFILE, TOKEN -def test_create_new(hass: HomeAssistant) -> None: - """Test creating a new config file.""" - with ( - patch("builtins.open", mock_open()), - patch("os.path.isfile", Mock(return_value=False)), - patch.object(rtm.RememberTheMilkConfiguration, "save_config"), - ): +def test_set_get_delete_token(hass: HomeAssistant) -> None: + """Test set, get and delete token.""" + open_mock = mock_open() + with patch("homeassistant.components.remember_the_milk.Path.open", open_mock): config = rtm.RememberTheMilkConfiguration(hass) + assert open_mock.return_value.write.call_count == 0 + assert config.get_token(PROFILE) is None + assert open_mock.return_value.write.call_count == 0 config.set_token(PROFILE, TOKEN) - assert config.get_token(PROFILE) == TOKEN + assert open_mock.return_value.write.call_count == 1 + assert open_mock.return_value.write.call_args[0][0] == json.dumps( + { + "myprofile": { + "id_map": {}, + "token": "mytoken", + } + } + ) + assert config.get_token(PROFILE) == TOKEN + assert open_mock.return_value.write.call_count == 1 + config.delete_token(PROFILE) + assert open_mock.return_value.write.call_count == 2 + assert open_mock.return_value.write.call_args[0][0] == json.dumps({}) + assert config.get_token(PROFILE) is None + assert open_mock.return_value.write.call_count == 2 -def test_load_config(hass: HomeAssistant) -> None: - """Test loading an existing token from the file.""" +def test_config_load(hass: HomeAssistant) -> None: + """Test loading from the file.""" with ( - patch("builtins.open", mock_open(read_data=JSON_STRING)), - patch("os.path.isfile", Mock(return_value=True)), - ): - config = rtm.RememberTheMilkConfiguration(hass) - assert config.get_token(PROFILE) == TOKEN - - -def test_invalid_data(hass: HomeAssistant) -> None: - """Test starts with invalid data and should not raise an exception.""" - with ( - patch("builtins.open", mock_open(read_data="random characters")), - patch("os.path.isfile", Mock(return_value=True)), - ): - config = rtm.RememberTheMilkConfiguration(hass) - assert config is not None - - -def test_id_map(hass: HomeAssistant) -> None: - """Test the hass to rtm task is mapping.""" - hass_id = "hass-id-1234" - list_id = "mylist" - timeseries_id = "my_timeseries" - rtm_id = "rtm-id-4567" - with ( - patch("builtins.open", mock_open()), - patch("os.path.isfile", Mock(return_value=False)), - patch.object(rtm.RememberTheMilkConfiguration, "save_config"), + patch( + "homeassistant.components.remember_the_milk.Path.open", + mock_open(read_data=JSON_STRING), + ), ): config = rtm.RememberTheMilkConfiguration(hass) + rtm_id = config.get_rtm_id(PROFILE, "123") + assert rtm_id is not None + assert rtm_id == ("1", "2", "3") + + +@pytest.mark.parametrize( + "side_effect", [FileNotFoundError("Missing file"), OSError("IO error")] +) +def test_config_load_file_error(hass: HomeAssistant, side_effect: Exception) -> None: + """Test loading with file error.""" + config = rtm.RememberTheMilkConfiguration(hass) + with ( + patch( + "homeassistant.components.remember_the_milk.Path.open", + side_effect=side_effect, + ), + ): + config = rtm.RememberTheMilkConfiguration(hass) + + # The config should be empty and we should not have any errors + # when trying to access it. + rtm_id = config.get_rtm_id(PROFILE, "123") + assert rtm_id is None + + +def test_config_load_invalid_data(hass: HomeAssistant) -> None: + """Test loading invalid data.""" + config = rtm.RememberTheMilkConfiguration(hass) + with ( + patch( + "homeassistant.components.remember_the_milk.Path.open", + mock_open(read_data="random characters"), + ), + ): + config = rtm.RememberTheMilkConfiguration(hass) + + # The config should be empty and we should not have any errors + # when trying to access it. + rtm_id = config.get_rtm_id(PROFILE, "123") + assert rtm_id is None + + +def test_config_set_delete_id(hass: HomeAssistant) -> None: + """Test setting and deleting an id from the config.""" + hass_id = "123" + list_id = "1" + timeseries_id = "2" + rtm_id = "3" + open_mock = mock_open() + config = rtm.RememberTheMilkConfiguration(hass) + with patch("homeassistant.components.remember_the_milk.Path.open", open_mock): + config = rtm.RememberTheMilkConfiguration(hass) + assert open_mock.return_value.write.call_count == 0 assert config.get_rtm_id(PROFILE, hass_id) is None + assert open_mock.return_value.write.call_count == 0 config.set_rtm_id(PROFILE, hass_id, list_id, timeseries_id, rtm_id) assert (list_id, timeseries_id, rtm_id) == config.get_rtm_id(PROFILE, hass_id) + assert open_mock.return_value.write.call_count == 1 + assert open_mock.return_value.write.call_args[0][0] == json.dumps( + { + "myprofile": { + "id_map": { + "123": {"list_id": "1", "timeseries_id": "2", "task_id": "3"} + } + } + } + ) config.delete_rtm_id(PROFILE, hass_id) assert config.get_rtm_id(PROFILE, hass_id) is None - - -def test_load_key_map(hass: HomeAssistant) -> None: - """Test loading an existing key map from the file.""" - with ( - patch("builtins.open", mock_open(read_data=JSON_STRING)), - patch("os.path.isfile", Mock(return_value=True)), - ): - config = rtm.RememberTheMilkConfiguration(hass) - assert config.get_rtm_id(PROFILE, "1234") == ("0", "1", "2") + assert open_mock.return_value.write.call_count == 2 + assert open_mock.return_value.write.call_args[0][0] == json.dumps( + { + "myprofile": { + "id_map": {}, + } + } + ) From 09df6c870620ac7a04c84d3e38344253e9f2e560 Mon Sep 17 00:00:00 2001 From: Shai Ungar Date: Sun, 16 Feb 2025 22:33:32 +0200 Subject: [PATCH 13/52] Rename "returned" state to "alert" (#138676) Rename "returned" state to "alert" in icons, services, and strings files --- homeassistant/components/seventeentrack/icons.json | 2 +- homeassistant/components/seventeentrack/services.yaml | 2 +- homeassistant/components/seventeentrack/strings.json | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/homeassistant/components/seventeentrack/icons.json b/homeassistant/components/seventeentrack/icons.json index a5cac0a9f84..c48e147e973 100644 --- a/homeassistant/components/seventeentrack/icons.json +++ b/homeassistant/components/seventeentrack/icons.json @@ -19,7 +19,7 @@ "delivered": { "default": "mdi:package" }, - "returned": { + "alert": { "default": "mdi:package" }, "package": { diff --git a/homeassistant/components/seventeentrack/services.yaml b/homeassistant/components/seventeentrack/services.yaml index d4592dc8aab..45d7c0a530a 100644 --- a/homeassistant/components/seventeentrack/services.yaml +++ b/homeassistant/components/seventeentrack/services.yaml @@ -11,7 +11,7 @@ get_packages: - "ready_to_be_picked_up" - "undelivered" - "delivered" - - "returned" + - "alert" translation_key: package_state config_entry_id: required: true diff --git a/homeassistant/components/seventeentrack/strings.json b/homeassistant/components/seventeentrack/strings.json index 982b15ab629..70fea2e2735 100644 --- a/homeassistant/components/seventeentrack/strings.json +++ b/homeassistant/components/seventeentrack/strings.json @@ -57,8 +57,8 @@ "delivered": { "name": "Delivered" }, - "returned": { - "name": "Returned" + "alert": { + "name": "Alert" }, "package": { "name": "Package {name}" @@ -104,7 +104,7 @@ "ready_to_be_picked_up": "[%key:component::seventeentrack::entity::sensor::ready_to_be_picked_up::name%]", "undelivered": "[%key:component::seventeentrack::entity::sensor::undelivered::name%]", "delivered": "[%key:component::seventeentrack::entity::sensor::delivered::name%]", - "returned": "[%key:component::seventeentrack::entity::sensor::returned::name%]" + "alert": "[%key:component::seventeentrack::entity::sensor::alert::name%]" } } } From bdeb24cb6136c4ff522760617a1f37ee633fddd0 Mon Sep 17 00:00:00 2001 From: peteS-UK <64092177+peteS-UK@users.noreply.github.com> Date: Sun, 16 Feb 2025 21:02:29 +0000 Subject: [PATCH 14/52] Add OptionsFlow to Squeezebox to allow setting Browse Limit and Volume Step (#129578) * Initial * prettier strings * Updates * remove error strings * prettier again * Update strings.json vscode prettier fails check * update test to remove invalid value * Remove config_entry __init__ * remove param * Review updates * ruff fixes * Review changes * Shorten options flow ui string * Review changes * Remove errant mock attib --------- Co-authored-by: Andrew Sayre <6730289+andrewsayre@users.noreply.github.com> --- .../components/squeezebox/__init__.py | 5 +- .../components/squeezebox/browse_media.py | 17 +++-- .../components/squeezebox/config_flow.py | 74 ++++++++++++++++++- homeassistant/components/squeezebox/const.py | 4 + .../components/squeezebox/media_player.py | 56 +++++++++----- .../components/squeezebox/strings.json | 15 ++++ tests/components/squeezebox/conftest.py | 6 ++ .../snapshots/test_media_player.ambr | 4 +- .../components/squeezebox/test_config_flow.py | 48 +++++++++++- .../squeezebox/test_media_player.py | 12 ++- 10 files changed, 206 insertions(+), 35 deletions(-) diff --git a/homeassistant/components/squeezebox/__init__.py b/homeassistant/components/squeezebox/__init__.py index 789f6ddb3a8..fd641d3389d 100644 --- a/homeassistant/components/squeezebox/__init__.py +++ b/homeassistant/components/squeezebox/__init__.py @@ -129,10 +129,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: SqueezeboxConfigEntry) - server_coordinator = LMSStatusDataUpdateCoordinator(hass, entry, lms) - entry.runtime_data = SqueezeboxData( - coordinator=server_coordinator, - server=lms, - ) + entry.runtime_data = SqueezeboxData(coordinator=server_coordinator, server=lms) # set up player discovery known_servers = hass.data.setdefault(DOMAIN, {}).setdefault(KNOWN_SERVERS, {}) diff --git a/homeassistant/components/squeezebox/browse_media.py b/homeassistant/components/squeezebox/browse_media.py index 331bf383c70..c0458067a23 100644 --- a/homeassistant/components/squeezebox/browse_media.py +++ b/homeassistant/components/squeezebox/browse_media.py @@ -81,11 +81,12 @@ CONTENT_TYPE_TO_CHILD_TYPE = { "New Music": MediaType.ALBUM, } -BROWSE_LIMIT = 1000 - async def build_item_response( - entity: MediaPlayerEntity, player: Player, payload: dict[str, str | None] + entity: MediaPlayerEntity, + player: Player, + payload: dict[str, str | None], + browse_limit: int, ) -> BrowseMedia: """Create response payload for search described by payload.""" @@ -107,7 +108,7 @@ async def build_item_response( result = await player.async_browse( MEDIA_TYPE_TO_SQUEEZEBOX[search_type], - limit=BROWSE_LIMIT, + limit=browse_limit, browse_id=browse_id, ) @@ -237,7 +238,11 @@ def media_source_content_filter(item: BrowseMedia) -> bool: return item.media_content_type.startswith("audio/") -async def generate_playlist(player: Player, payload: dict[str, str]) -> list | None: +async def generate_playlist( + player: Player, + payload: dict[str, str], + browse_limit: int, +) -> list | None: """Generate playlist from browsing payload.""" media_type = payload["search_type"] media_id = payload["search_id"] @@ -247,7 +252,7 @@ async def generate_playlist(player: Player, payload: dict[str, str]) -> list | N browse_id = (SQUEEZEBOX_ID_BY_TYPE[media_type], media_id) result = await player.async_browse( - "titles", limit=BROWSE_LIMIT, browse_id=browse_id + "titles", limit=browse_limit, browse_id=browse_id ) if result and "items" in result: items: list = result["items"] diff --git a/homeassistant/components/squeezebox/config_flow.py b/homeassistant/components/squeezebox/config_flow.py index 97eb848c21c..2853ad14217 100644 --- a/homeassistant/components/squeezebox/config_flow.py +++ b/homeassistant/components/squeezebox/config_flow.py @@ -11,15 +11,34 @@ from pysqueezebox import Server, async_discover import voluptuous as vol from homeassistant.components.media_player import DOMAIN as MP_DOMAIN -from homeassistant.config_entries import ConfigFlow, ConfigFlowResult +from homeassistant.config_entries import ( + ConfigEntry, + ConfigFlow, + ConfigFlowResult, + OptionsFlow, +) from homeassistant.const import CONF_HOST, CONF_PASSWORD, CONF_PORT, CONF_USERNAME +from homeassistant.core import callback from homeassistant.data_entry_flow import AbortFlow from homeassistant.helpers import entity_registry as er from homeassistant.helpers.aiohttp_client import async_get_clientsession from homeassistant.helpers.device_registry import format_mac +from homeassistant.helpers.selector import ( + NumberSelector, + NumberSelectorConfig, + NumberSelectorMode, +) from homeassistant.helpers.service_info.dhcp import DhcpServiceInfo -from .const import CONF_HTTPS, DEFAULT_PORT, DOMAIN +from .const import ( + CONF_BROWSE_LIMIT, + CONF_HTTPS, + CONF_VOLUME_STEP, + DEFAULT_BROWSE_LIMIT, + DEFAULT_PORT, + DEFAULT_VOLUME_STEP, + DOMAIN, +) _LOGGER = logging.getLogger(__name__) @@ -77,6 +96,12 @@ class SqueezeboxConfigFlow(ConfigFlow, domain=DOMAIN): self.data_schema = _base_schema() self.discovery_info: dict[str, Any] | None = None + @staticmethod + @callback + def async_get_options_flow(config_entry: ConfigEntry) -> OptionsFlowHandler: + """Get the options flow for this handler.""" + return OptionsFlowHandler() + async def _discover(self, uuid: str | None = None) -> None: """Discover an unconfigured LMS server.""" self.discovery_info = None @@ -222,3 +247,48 @@ class SqueezeboxConfigFlow(ConfigFlow, domain=DOMAIN): # if the player is unknown, then we likely need to configure its server return await self.async_step_user() + + +OPTIONS_SCHEMA = vol.Schema( + { + vol.Required(CONF_BROWSE_LIMIT): vol.All( + NumberSelector( + NumberSelectorConfig(min=1, max=65534, mode=NumberSelectorMode.BOX) + ), + vol.Coerce(int), + ), + vol.Required(CONF_VOLUME_STEP): vol.All( + NumberSelector( + NumberSelectorConfig(min=1, max=20, mode=NumberSelectorMode.SLIDER) + ), + vol.Coerce(int), + ), + } +) + + +class OptionsFlowHandler(OptionsFlow): + """Options Flow Handler.""" + + async def async_step_init( + self, user_input: dict[str, Any] | None = None + ) -> ConfigFlowResult: + """Options Flow Steps.""" + + if user_input is not None: + return self.async_create_entry(title="", data=user_input) + + return self.async_show_form( + step_id="init", + data_schema=self.add_suggested_values_to_schema( + OPTIONS_SCHEMA, + { + CONF_BROWSE_LIMIT: self.config_entry.options.get( + CONF_BROWSE_LIMIT, DEFAULT_BROWSE_LIMIT + ), + CONF_VOLUME_STEP: self.config_entry.options.get( + CONF_VOLUME_STEP, DEFAULT_VOLUME_STEP + ), + }, + ), + ) diff --git a/homeassistant/components/squeezebox/const.py b/homeassistant/components/squeezebox/const.py index 8bc33214170..f24c452282f 100644 --- a/homeassistant/components/squeezebox/const.py +++ b/homeassistant/components/squeezebox/const.py @@ -32,3 +32,7 @@ SIGNAL_PLAYER_DISCOVERED = "squeezebox_player_discovered" SIGNAL_PLAYER_REDISCOVERED = "squeezebox_player_rediscovered" DISCOVERY_INTERVAL = 60 PLAYER_UPDATE_INTERVAL = 5 +CONF_BROWSE_LIMIT = "browse_limit" +CONF_VOLUME_STEP = "volume_step" +DEFAULT_BROWSE_LIMIT = 1000 +DEFAULT_VOLUME_STEP = 5 diff --git a/homeassistant/components/squeezebox/media_player.py b/homeassistant/components/squeezebox/media_player.py index 1b810019373..a98ee13275c 100644 --- a/homeassistant/components/squeezebox/media_player.py +++ b/homeassistant/components/squeezebox/media_player.py @@ -52,6 +52,10 @@ from .browse_media import ( media_source_content_filter, ) from .const import ( + CONF_BROWSE_LIMIT, + CONF_VOLUME_STEP, + DEFAULT_BROWSE_LIMIT, + DEFAULT_VOLUME_STEP, DISCOVERY_TASK, DOMAIN, KNOWN_PLAYERS, @@ -166,6 +170,7 @@ class SqueezeBoxMediaPlayerEntity( | MediaPlayerEntityFeature.PAUSE | MediaPlayerEntityFeature.VOLUME_SET | MediaPlayerEntityFeature.VOLUME_MUTE + | MediaPlayerEntityFeature.VOLUME_STEP | MediaPlayerEntityFeature.PREVIOUS_TRACK | MediaPlayerEntityFeature.NEXT_TRACK | MediaPlayerEntityFeature.SEEK @@ -184,10 +189,7 @@ class SqueezeBoxMediaPlayerEntity( _attr_name = None _last_update: datetime | None = None - def __init__( - self, - coordinator: SqueezeBoxPlayerUpdateCoordinator, - ) -> None: + def __init__(self, coordinator: SqueezeBoxPlayerUpdateCoordinator) -> None: """Initialize the SqueezeBox device.""" super().__init__(coordinator) player = coordinator.player @@ -223,6 +225,23 @@ class SqueezeBoxMediaPlayerEntity( self._last_update = utcnow() self.async_write_ha_state() + @property + def volume_step(self) -> float: + """Return the step to be used for volume up down.""" + return float( + self.coordinator.config_entry.options.get( + CONF_VOLUME_STEP, DEFAULT_VOLUME_STEP + ) + / 100 + ) + + @property + def browse_limit(self) -> int: + """Return the step to be used for volume up down.""" + return self.coordinator.config_entry.options.get( + CONF_BROWSE_LIMIT, DEFAULT_BROWSE_LIMIT + ) + @property def available(self) -> bool: """Return True if entity is available.""" @@ -366,16 +385,6 @@ class SqueezeBoxMediaPlayerEntity( await self._player.async_set_power(False) await self.coordinator.async_refresh() - async def async_volume_up(self) -> None: - """Volume up media player.""" - await self._player.async_set_volume("+5") - await self.coordinator.async_refresh() - - async def async_volume_down(self) -> None: - """Volume down media player.""" - await self._player.async_set_volume("-5") - await self.coordinator.async_refresh() - async def async_set_volume_level(self, volume: float) -> None: """Set volume level, range 0..1.""" volume_percent = str(int(volume * 100)) @@ -466,7 +475,11 @@ class SqueezeBoxMediaPlayerEntity( "search_id": media_id, "search_type": MediaType.PLAYLIST, } - playlist = await generate_playlist(self._player, payload) + playlist = await generate_playlist( + self._player, + payload, + self.browse_limit, + ) except BrowseError: # a list of urls content = json.loads(media_id) @@ -477,7 +490,11 @@ class SqueezeBoxMediaPlayerEntity( "search_id": media_id, "search_type": media_type, } - playlist = await generate_playlist(self._player, payload) + playlist = await generate_playlist( + self._player, + payload, + self.browse_limit, + ) _LOGGER.debug("Generated playlist: %s", playlist) @@ -587,7 +604,12 @@ class SqueezeBoxMediaPlayerEntity( "search_id": media_content_id, } - return await build_item_response(self, self._player, payload) + return await build_item_response( + self, + self._player, + payload, + self.browse_limit, + ) async def async_get_browse_image( self, diff --git a/homeassistant/components/squeezebox/strings.json b/homeassistant/components/squeezebox/strings.json index bce71ddb5f2..ed569989b56 100644 --- a/homeassistant/components/squeezebox/strings.json +++ b/homeassistant/components/squeezebox/strings.json @@ -103,5 +103,20 @@ "unit_of_measurement": "[%key:component::squeezebox::entity::sensor::player_count::unit_of_measurement%]" } } + }, + "options": { + "step": { + "init": { + "title": "LMS Configuration", + "data": { + "browse_limit": "Browse limit", + "volume_step": "Volume step" + }, + "data_description": { + "browse_limit": "Maximum number of items when browsing or in a playlist.", + "volume_step": "Amount to adjust the volume when turning volume up or down." + } + } + } } } diff --git a/tests/components/squeezebox/conftest.py b/tests/components/squeezebox/conftest.py index 7b007114420..c960844ee2f 100644 --- a/tests/components/squeezebox/conftest.py +++ b/tests/components/squeezebox/conftest.py @@ -33,6 +33,9 @@ from homeassistant.helpers.device_registry import format_mac # from homeassistant.setup import async_setup_component from tests.common import MockConfigEntry +CONF_VOLUME_STEP = "volume_step" +TEST_VOLUME_STEP = 10 + TEST_HOST = "1.2.3.4" TEST_PORT = "9000" TEST_USE_HTTPS = False @@ -109,6 +112,9 @@ def config_entry(hass: HomeAssistant) -> MockConfigEntry: CONF_PORT: TEST_PORT, const.CONF_HTTPS: TEST_USE_HTTPS, }, + options={ + CONF_VOLUME_STEP: TEST_VOLUME_STEP, + }, ) config_entry.add_to_hass(hass) return config_entry diff --git a/tests/components/squeezebox/snapshots/test_media_player.ambr b/tests/components/squeezebox/snapshots/test_media_player.ambr index fd663c5eb63..47c2fea22c5 100644 --- a/tests/components/squeezebox/snapshots/test_media_player.ambr +++ b/tests/components/squeezebox/snapshots/test_media_player.ambr @@ -65,7 +65,7 @@ 'original_name': None, 'platform': 'squeezebox', 'previous_unique_id': None, - 'supported_features': , + 'supported_features': , 'translation_key': None, 'unique_id': 'aa:bb:cc:dd:ee:ff', 'unit_of_measurement': None, @@ -88,7 +88,7 @@ }), 'repeat': , 'shuffle': False, - 'supported_features': , + 'supported_features': , 'volume_level': 0.01, }), 'context': , diff --git a/tests/components/squeezebox/test_config_flow.py b/tests/components/squeezebox/test_config_flow.py index c5efe66152f..cae3672061b 100644 --- a/tests/components/squeezebox/test_config_flow.py +++ b/tests/components/squeezebox/test_config_flow.py @@ -6,7 +6,12 @@ from unittest.mock import patch from pysqueezebox import Server from homeassistant import config_entries -from homeassistant.components.squeezebox.const import CONF_HTTPS, DOMAIN +from homeassistant.components.squeezebox.const import ( + CONF_BROWSE_LIMIT, + CONF_HTTPS, + CONF_VOLUME_STEP, + DOMAIN, +) from homeassistant.const import CONF_HOST, CONF_PASSWORD, CONF_PORT, CONF_USERNAME from homeassistant.core import HomeAssistant from homeassistant.data_entry_flow import FlowResultType @@ -19,6 +24,8 @@ HOST2 = "2.2.2.2" PORT = 9000 UUID = "test-uuid" UNKNOWN_ERROR = "1234" +BROWSE_LIMIT = 10 +VOLUME_STEP = 1 async def mock_discover(_discovery_callback): @@ -87,6 +94,45 @@ async def test_user_form(hass: HomeAssistant) -> None: assert len(mock_setup_entry.mock_calls) == 1 +async def test_options_form(hass: HomeAssistant) -> None: + """Test we can configure options.""" + entry = MockConfigEntry( + data={ + CONF_HOST: HOST, + CONF_PORT: PORT, + CONF_USERNAME: "", + CONF_PASSWORD: "", + CONF_HTTPS: False, + }, + unique_id=UUID, + domain=DOMAIN, + options={CONF_BROWSE_LIMIT: 1000, CONF_VOLUME_STEP: 5}, + ) + + entry.add_to_hass(hass) + await hass.config_entries.async_setup(entry.entry_id) + await hass.async_block_till_done() + + result = await hass.config_entries.options.async_init(entry.entry_id) + + assert result["type"] is FlowResultType.FORM + assert result["step_id"] == "init" + + # simulate manual input of options + result = await hass.config_entries.options.async_configure( + result["flow_id"], + user_input={CONF_BROWSE_LIMIT: BROWSE_LIMIT, CONF_VOLUME_STEP: VOLUME_STEP}, + ) + + # put some meaningful asserts here + assert result["type"] is FlowResultType.CREATE_ENTRY + + assert result["data"] == { + CONF_BROWSE_LIMIT: BROWSE_LIMIT, + CONF_VOLUME_STEP: VOLUME_STEP, + } + + async def test_user_form_timeout(hass: HomeAssistant) -> None: """Test we handle server search timeout.""" with ( diff --git a/tests/components/squeezebox/test_media_player.py b/tests/components/squeezebox/test_media_player.py index 080a2161b4d..694f5c9a8a2 100644 --- a/tests/components/squeezebox/test_media_player.py +++ b/tests/components/squeezebox/test_media_player.py @@ -68,7 +68,7 @@ from homeassistant.helpers.device_registry import DeviceRegistry from homeassistant.helpers.entity_registry import EntityRegistry from homeassistant.util.dt import utcnow -from .conftest import FAKE_VALID_ITEM_ID, TEST_MAC +from .conftest import FAKE_VALID_ITEM_ID, TEST_MAC, TEST_VOLUME_STEP from tests.common import MockConfigEntry, async_fire_time_changed, snapshot_platform @@ -183,26 +183,32 @@ async def test_squeezebox_volume_up( hass: HomeAssistant, configured_player: MagicMock ) -> None: """Test volume up service call.""" + configured_player.volume = 50 await hass.services.async_call( MEDIA_PLAYER_DOMAIN, SERVICE_VOLUME_UP, {ATTR_ENTITY_ID: "media_player.test_player"}, blocking=True, ) - configured_player.async_set_volume.assert_called_once_with("+5") + configured_player.async_set_volume.assert_called_once_with( + str(configured_player.volume + TEST_VOLUME_STEP) + ) async def test_squeezebox_volume_down( hass: HomeAssistant, configured_player: MagicMock ) -> None: """Test volume down service call.""" + configured_player.volume = 50 await hass.services.async_call( MEDIA_PLAYER_DOMAIN, SERVICE_VOLUME_DOWN, {ATTR_ENTITY_ID: "media_player.test_player"}, blocking=True, ) - configured_player.async_set_volume.assert_called_once_with("-5") + configured_player.async_set_volume.assert_called_once_with( + str(configured_player.volume - TEST_VOLUME_STEP) + ) async def test_squeezebox_volume_set( From 93f1597e6d87437a61093f8743afecb773608ac8 Mon Sep 17 00:00:00 2001 From: Markus Lanthaler Date: Sun, 16 Feb 2025 22:03:57 +0100 Subject: [PATCH 15/52] Add latest Nighthawk WiFi 7 routers to V2 models (#138675) --- homeassistant/components/netgear/const.py | 1 + 1 file changed, 1 insertion(+) diff --git a/homeassistant/components/netgear/const.py b/homeassistant/components/netgear/const.py index f7a683326d3..c8ecd8e7e1d 100644 --- a/homeassistant/components/netgear/const.py +++ b/homeassistant/components/netgear/const.py @@ -62,6 +62,7 @@ MODELS_V2 = [ "RBR", "RBS", "RBW", + "RS", "LBK", "LBR", "CBK", From 56b51227bb6c915f92e5b655d9b2e4e95a41f7ff Mon Sep 17 00:00:00 2001 From: fwestenberg <47930023+fwestenberg@users.noreply.github.com> Date: Mon, 17 Feb 2025 02:19:03 +0100 Subject: [PATCH 16/52] Bump stookwijzer==1.5.4 (#138678) --- homeassistant/components/stookwijzer/manifest.json | 2 +- requirements_all.txt | 2 +- requirements_test_all.txt | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/stookwijzer/manifest.json b/homeassistant/components/stookwijzer/manifest.json index 0c97d1b20ed..8243b903e8d 100644 --- a/homeassistant/components/stookwijzer/manifest.json +++ b/homeassistant/components/stookwijzer/manifest.json @@ -6,5 +6,5 @@ "documentation": "https://www.home-assistant.io/integrations/stookwijzer", "integration_type": "service", "iot_class": "cloud_polling", - "requirements": ["stookwijzer==1.5.2"] + "requirements": ["stookwijzer==1.5.4"] } diff --git a/requirements_all.txt b/requirements_all.txt index abbda498827..9d340460b1d 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -2796,7 +2796,7 @@ statsd==3.2.1 steamodd==4.21 # homeassistant.components.stookwijzer -stookwijzer==1.5.2 +stookwijzer==1.5.4 # homeassistant.components.streamlabswater streamlabswater==1.0.1 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index f6223d56c2f..40b9fa85762 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -2257,7 +2257,7 @@ statsd==3.2.1 steamodd==4.21 # homeassistant.components.stookwijzer -stookwijzer==1.5.2 +stookwijzer==1.5.4 # homeassistant.components.streamlabswater streamlabswater==1.0.1 From 6b90e7b2c2be3ed29222a0828a11c20114b39ac1 Mon Sep 17 00:00:00 2001 From: cdnninja Date: Sun, 16 Feb 2025 20:33:48 -0700 Subject: [PATCH 17/52] Bump pyvesync for vesync (#138681) * bump pyvesync * fix tests * Test fix --- homeassistant/components/vesync/manifest.json | 2 +- requirements_all.txt | 2 +- requirements_test_all.txt | 2 +- tests/components/vesync/snapshots/test_diagnostics.ambr | 1 + 4 files changed, 4 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/vesync/manifest.json b/homeassistant/components/vesync/manifest.json index b3697844f19..9e2fbcc1782 100644 --- a/homeassistant/components/vesync/manifest.json +++ b/homeassistant/components/vesync/manifest.json @@ -12,5 +12,5 @@ "documentation": "https://www.home-assistant.io/integrations/vesync", "iot_class": "cloud_polling", "loggers": ["pyvesync"], - "requirements": ["pyvesync==2.1.17"] + "requirements": ["pyvesync==2.1.18"] } diff --git a/requirements_all.txt b/requirements_all.txt index 9d340460b1d..3adfa7abb88 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -2522,7 +2522,7 @@ pyvera==0.3.15 pyversasense==0.0.6 # homeassistant.components.vesync -pyvesync==2.1.17 +pyvesync==2.1.18 # homeassistant.components.vizio pyvizio==0.1.61 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index 40b9fa85762..6ff5c8bc7d7 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -2040,7 +2040,7 @@ pyuptimerobot==22.2.0 pyvera==0.3.15 # homeassistant.components.vesync -pyvesync==2.1.17 +pyvesync==2.1.18 # homeassistant.components.vizio pyvizio==0.1.61 diff --git a/tests/components/vesync/snapshots/test_diagnostics.ambr b/tests/components/vesync/snapshots/test_diagnostics.ambr index 1c409dbab00..407e18d65b6 100644 --- a/tests/components/vesync/snapshots/test_diagnostics.ambr +++ b/tests/components/vesync/snapshots/test_diagnostics.ambr @@ -171,6 +171,7 @@ 'models': list([ 'LV-PUR131S', 'LV-RH131S', + 'LV-RH131S-WM', ]), 'modes': list([ 'manual', From c357b3ae656c2d8f7f5555077b57090131b4292b Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Sun, 16 Feb 2025 23:06:28 -0500 Subject: [PATCH 18/52] Move some setups during onboarding to background (#138558) * Move some setups during onboarding to background * Update homeassistant/components/onboarding/views.py Co-authored-by: Martin Hjelmare --------- Co-authored-by: Martin Hjelmare --- homeassistant/components/onboarding/views.py | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/homeassistant/components/onboarding/views.py b/homeassistant/components/onboarding/views.py index cb0dc4fdfa7..ea955987d80 100644 --- a/homeassistant/components/onboarding/views.py +++ b/homeassistant/components/onboarding/views.py @@ -33,7 +33,6 @@ from homeassistant.helpers.hassio import is_hassio from homeassistant.helpers.system_info import async_get_system_info from homeassistant.helpers.translation import async_get_translations from homeassistant.setup import async_setup_component -from homeassistant.util.async_ import create_eager_task if TYPE_CHECKING: from . import OnboardingData, OnboardingStorage, OnboardingStoreData @@ -235,22 +234,21 @@ class CoreConfigOnboardingView(_BaseOnboardingView): ): onboard_integrations.append("rpi_power") - coros: list[Coroutine[Any, Any, Any]] = [ - hass.config_entries.flow.async_init( - domain, context={"source": "onboarding"} + for domain in onboard_integrations: + # Create tasks so onboarding isn't affected + # by errors in these integrations. + hass.async_create_task( + hass.config_entries.flow.async_init( + domain, context={"source": "onboarding"} + ), + f"onboarding_setup_{domain}", ) - for domain in onboard_integrations - ] if "analytics" not in hass.config.components: # If by some chance that analytics has not finished # setting up, wait for it here so its ready for the # next step. - coros.append(async_setup_component(hass, "analytics", {})) - - # Set up integrations after onboarding and ensure - # analytics is ready for the next step. - await asyncio.gather(*(create_eager_task(coro) for coro in coros)) + await async_setup_component(hass, "analytics", {}) return self.json({}) From 89956adf2eea8d3dd6630506f6e0d9fcab436a39 Mon Sep 17 00:00:00 2001 From: Andrew Sayre <6730289+andrewsayre@users.noreply.github.com> Date: Mon, 17 Feb 2025 01:47:11 -0600 Subject: [PATCH 19/52] Allow removal of stale HEOS devices (#138677) Allow device removal --- homeassistant/components/heos/__init__.py | 11 +++++++ .../components/heos/quality_scale.yaml | 2 +- tests/components/heos/test_init.py | 29 +++++++++++++++++++ 3 files changed, 41 insertions(+), 1 deletion(-) diff --git a/homeassistant/components/heos/__init__.py b/homeassistant/components/heos/__init__.py index 7bbd3765602..4df1a2fa0e1 100644 --- a/homeassistant/components/heos/__init__.py +++ b/homeassistant/components/heos/__init__.py @@ -69,3 +69,14 @@ async def async_setup_entry(hass: HomeAssistant, entry: HeosConfigEntry) -> bool async def async_unload_entry(hass: HomeAssistant, entry: HeosConfigEntry) -> bool: """Unload a config entry.""" return await hass.config_entries.async_unload_platforms(entry, PLATFORMS) + + +async def async_remove_config_entry_device( + hass: HomeAssistant, entry: HeosConfigEntry, device: dr.DeviceEntry +) -> bool: + """Remove config entry from device if no longer present.""" + return not any( + (domain, key) + for domain, key in device.identifiers + if domain == DOMAIN and int(key) in entry.runtime_data.heos.players + ) diff --git a/homeassistant/components/heos/quality_scale.yaml b/homeassistant/components/heos/quality_scale.yaml index 67022ec492c..a1220366fa3 100644 --- a/homeassistant/components/heos/quality_scale.yaml +++ b/homeassistant/components/heos/quality_scale.yaml @@ -58,7 +58,7 @@ rules: icon-translations: done reconfiguration-flow: done repair-issues: todo - stale-devices: todo + stale-devices: done # Platinum async-dependency: done inject-websession: diff --git a/tests/components/heos/test_init.py b/tests/components/heos/test_init.py index 81acb7b3b8b..60bc2a72e51 100644 --- a/tests/components/heos/test_init.py +++ b/tests/components/heos/test_init.py @@ -11,10 +11,12 @@ from homeassistant.config_entries import SOURCE_REAUTH, ConfigEntryState from homeassistant.const import CONF_HOST, CONF_PASSWORD, CONF_USERNAME from homeassistant.core import HomeAssistant from homeassistant.helpers import device_registry as dr +from homeassistant.setup import async_setup_component from . import MockHeos from tests.common import MockConfigEntry +from tests.typing import WebSocketGenerator async def test_async_setup_entry_loads_platforms( @@ -226,3 +228,30 @@ async def test_device_id_migration_both_present( await hass.async_block_till_done(wait_background_tasks=True) assert device_registry.async_get_device({(DOMAIN, 1)}) is None # type: ignore[arg-type] assert device_registry.async_get_device({(DOMAIN, "1")}) is not None + + +@pytest.mark.parametrize( + ("player_id", "expected_result"), + [("1", False), ("5", True)], + ids=("Present device", "Stale device"), +) +async def test_remove_config_entry_device( + hass: HomeAssistant, + config_entry: MockConfigEntry, + device_registry: dr.DeviceRegistry, + hass_ws_client: WebSocketGenerator, + player_id: str, + expected_result: bool, +) -> None: + """Test manually removing an stale device.""" + assert await async_setup_component(hass, "config", {}) + config_entry.add_to_hass(hass) + assert await hass.config_entries.async_setup(config_entry.entry_id) + + device_entry = device_registry.async_get_or_create( + config_entry_id=config_entry.entry_id, identifiers={(DOMAIN, player_id)} + ) + + ws_client = await hass_ws_client(hass) + response = await ws_client.remove_device(device_entry.id, config_entry.entry_id) + assert response["success"] == expected_result From f2126a357a826e3107084b67aa6e50f246759315 Mon Sep 17 00:00:00 2001 From: Jonas Fors Lellky Date: Mon, 17 Feb 2025 08:58:21 +0100 Subject: [PATCH 20/52] Comply with parallel updates quality rule (#138672) --- homeassistant/components/flexit_bacnet/binary_sensor.py | 4 ++++ homeassistant/components/flexit_bacnet/climate.py | 3 +++ homeassistant/components/flexit_bacnet/number.py | 3 +++ homeassistant/components/flexit_bacnet/quality_scale.yaml | 2 +- homeassistant/components/flexit_bacnet/sensor.py | 4 ++++ homeassistant/components/flexit_bacnet/switch.py | 3 +++ 6 files changed, 18 insertions(+), 1 deletion(-) diff --git a/homeassistant/components/flexit_bacnet/binary_sensor.py b/homeassistant/components/flexit_bacnet/binary_sensor.py index faee803e915..50c49f45e3e 100644 --- a/homeassistant/components/flexit_bacnet/binary_sensor.py +++ b/homeassistant/components/flexit_bacnet/binary_sensor.py @@ -47,6 +47,10 @@ async def async_setup_entry( ) +# Coordinator is used to centralize the data updates +PARALLEL_UPDATES = 0 + + class FlexitBinarySensor(FlexitEntity, BinarySensorEntity): """Representation of a Flexit binary Sensor.""" diff --git a/homeassistant/components/flexit_bacnet/climate.py b/homeassistant/components/flexit_bacnet/climate.py index abfa59d0a6d..b9ae16739b9 100644 --- a/homeassistant/components/flexit_bacnet/climate.py +++ b/homeassistant/components/flexit_bacnet/climate.py @@ -43,6 +43,9 @@ async def async_setup_entry( async_add_entities([FlexitClimateEntity(config_entry.runtime_data)]) +PARALLEL_UPDATES = 1 + + class FlexitClimateEntity(FlexitEntity, ClimateEntity): """Flexit air handling unit.""" diff --git a/homeassistant/components/flexit_bacnet/number.py b/homeassistant/components/flexit_bacnet/number.py index dfcfc193692..061860e7d0d 100644 --- a/homeassistant/components/flexit_bacnet/number.py +++ b/homeassistant/components/flexit_bacnet/number.py @@ -205,6 +205,9 @@ async def async_setup_entry( ) +PARALLEL_UPDATES = 1 + + class FlexitNumber(FlexitEntity, NumberEntity): """Representation of a Flexit Number.""" diff --git a/homeassistant/components/flexit_bacnet/quality_scale.yaml b/homeassistant/components/flexit_bacnet/quality_scale.yaml index 9b7e4deb4c0..548580f96d3 100644 --- a/homeassistant/components/flexit_bacnet/quality_scale.yaml +++ b/homeassistant/components/flexit_bacnet/quality_scale.yaml @@ -47,7 +47,7 @@ rules: status: done comment: | Done implicitly with coordinator. - parallel-updates: todo + parallel-updates: done reauthentication-flow: todo test-coverage: todo # Gold diff --git a/homeassistant/components/flexit_bacnet/sensor.py b/homeassistant/components/flexit_bacnet/sensor.py index 23d8f20da36..0506b13892b 100644 --- a/homeassistant/components/flexit_bacnet/sensor.py +++ b/homeassistant/components/flexit_bacnet/sensor.py @@ -161,6 +161,10 @@ async def async_setup_entry( ) +# Coordinator is used to centralize the data updates +PARALLEL_UPDATES = 0 + + class FlexitSensor(FlexitEntity, SensorEntity): """Representation of a Flexit (bacnet) Sensor.""" diff --git a/homeassistant/components/flexit_bacnet/switch.py b/homeassistant/components/flexit_bacnet/switch.py index 283d0e1ec3b..ac69bb86023 100644 --- a/homeassistant/components/flexit_bacnet/switch.py +++ b/homeassistant/components/flexit_bacnet/switch.py @@ -68,6 +68,9 @@ async def async_setup_entry( ) +PARALLEL_UPDATES = 1 + + class FlexitSwitch(FlexitEntity, SwitchEntity): """Representation of a Flexit Switch.""" From ed3ca766964a735d5d39ff6accf9743e7069c3d9 Mon Sep 17 00:00:00 2001 From: Norbert Rittel Date: Mon, 17 Feb 2025 09:03:28 +0100 Subject: [PATCH 21/52] Update foscam action descriptions to match HA style (#138664) Update foscam action description to match HA style --- homeassistant/components/foscam/strings.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/foscam/strings.json b/homeassistant/components/foscam/strings.json index 2784e541809..03351e3238f 100644 --- a/homeassistant/components/foscam/strings.json +++ b/homeassistant/components/foscam/strings.json @@ -35,7 +35,7 @@ "services": { "ptz": { "name": "PTZ", - "description": "Pan/Tilt action for Foscam camera.", + "description": "Moves a Foscam camera to a specified direction.", "fields": { "movement": { "name": "Movement", @@ -49,7 +49,7 @@ }, "ptz_preset": { "name": "PTZ preset", - "description": "PTZ Preset action for Foscam camera.", + "description": "Moves a Foscam camera to a predefined position.", "fields": { "preset_name": { "name": "Preset name", From 66d16336ea23d2f9967d547dd9544e1fc2784478 Mon Sep 17 00:00:00 2001 From: Dan Raper Date: Mon, 17 Feb 2025 08:07:18 +0000 Subject: [PATCH 22/52] Add preconditioning number entity to Ohme (#138346) * Add preconditioning number entity * Updated test snapshots for ohme * Update test snapshots --- homeassistant/components/ohme/icons.json | 3 + homeassistant/components/ohme/number.py | 14 ++++- homeassistant/components/ohme/strings.json | 3 + tests/components/ohme/conftest.py | 1 + .../ohme/snapshots/test_number.ambr | 57 +++++++++++++++++++ 5 files changed, 77 insertions(+), 1 deletion(-) diff --git a/homeassistant/components/ohme/icons.json b/homeassistant/components/ohme/icons.json index 7a27156b2fe..ade48b4f80f 100644 --- a/homeassistant/components/ohme/icons.json +++ b/homeassistant/components/ohme/icons.json @@ -6,6 +6,9 @@ } }, "number": { + "preconditioning_duration": { + "default": "mdi:fan-clock" + }, "target_percentage": { "default": "mdi:battery-heart" } diff --git a/homeassistant/components/ohme/number.py b/homeassistant/components/ohme/number.py index 8c5be2b48be..0c71bab009f 100644 --- a/homeassistant/components/ohme/number.py +++ b/homeassistant/components/ohme/number.py @@ -6,7 +6,7 @@ from dataclasses import dataclass from ohme import ApiException, OhmeApiClient from homeassistant.components.number import NumberEntity, NumberEntityDescription -from homeassistant.const import PERCENTAGE +from homeassistant.const import PERCENTAGE, UnitOfTime from homeassistant.core import HomeAssistant from homeassistant.exceptions import HomeAssistantError from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback @@ -37,6 +37,18 @@ NUMBER_DESCRIPTION = [ native_step=1, native_unit_of_measurement=PERCENTAGE, ), + OhmeNumberDescription( + key="preconditioning_duration", + translation_key="preconditioning_duration", + value_fn=lambda client: client.preconditioning, + set_fn=lambda client, value: client.async_set_target( + pre_condition_length=value + ), + native_min_value=0, + native_max_value=60, + native_step=5, + native_unit_of_measurement=UnitOfTime.MINUTES, + ), ] diff --git a/homeassistant/components/ohme/strings.json b/homeassistant/components/ohme/strings.json index b337c013727..46ccfca71fd 100644 --- a/homeassistant/components/ohme/strings.json +++ b/homeassistant/components/ohme/strings.json @@ -51,6 +51,9 @@ } }, "number": { + "preconditioning_duration": { + "name": "Preconditioning duration" + }, "target_percentage": { "name": "Target percentage" } diff --git a/tests/components/ohme/conftest.py b/tests/components/ohme/conftest.py index 3d3db730d08..01cc668ae32 100644 --- a/tests/components/ohme/conftest.py +++ b/tests/components/ohme/conftest.py @@ -57,6 +57,7 @@ def mock_client(): client.target_soc = 50 client.target_time = (8, 0) client.battery = 80 + client.preconditioning = 15 client.serial = "chargerid" client.ct_connected = True client.energy = 1000 diff --git a/tests/components/ohme/snapshots/test_number.ambr b/tests/components/ohme/snapshots/test_number.ambr index dbcf6134252..69e18d0b2a7 100644 --- a/tests/components/ohme/snapshots/test_number.ambr +++ b/tests/components/ohme/snapshots/test_number.ambr @@ -1,4 +1,61 @@ # serializer version: 1 +# name: test_numbers[number.ohme_home_pro_preconditioning_duration-entry] + EntityRegistryEntrySnapshot({ + 'aliases': set({ + }), + 'area_id': None, + 'capabilities': dict({ + 'max': 60, + 'min': 0, + 'mode': , + 'step': 5, + }), + 'config_entry_id': , + 'config_subentry_id': , + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'number', + 'entity_category': None, + 'entity_id': 'number.ohme_home_pro_preconditioning_duration', + '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': 'Preconditioning duration', + 'platform': 'ohme', + 'previous_unique_id': None, + 'supported_features': 0, + 'translation_key': 'preconditioning_duration', + 'unique_id': 'chargerid_preconditioning_duration', + 'unit_of_measurement': , + }) +# --- +# name: test_numbers[number.ohme_home_pro_preconditioning_duration-state] + StateSnapshot({ + 'attributes': ReadOnlyDict({ + 'friendly_name': 'Ohme Home Pro Preconditioning duration', + 'max': 60, + 'min': 0, + 'mode': , + 'step': 5, + 'unit_of_measurement': , + }), + 'context': , + 'entity_id': 'number.ohme_home_pro_preconditioning_duration', + 'last_changed': , + 'last_reported': , + 'last_updated': , + 'state': '15', + }) +# --- # name: test_numbers[number.ohme_home_pro_target_percentage-entry] EntityRegistryEntrySnapshot({ 'aliases': set({ From e77193fa2e5250e33b3ac1b941be3f00d02d36fe Mon Sep 17 00:00:00 2001 From: Norbert Rittel Date: Mon, 17 Feb 2025 09:08:40 +0100 Subject: [PATCH 23/52] Improve 17track action descriptions by using those from the online docs (#138698) * Improve 17Track action descriptions using those from the online docs Also change them to third-person singular to match the descriptive style that Home Assistant prefers. * Add missing period on 2nd description --- homeassistant/components/seventeentrack/strings.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/seventeentrack/strings.json b/homeassistant/components/seventeentrack/strings.json index 70fea2e2735..c95a553ae7b 100644 --- a/homeassistant/components/seventeentrack/strings.json +++ b/homeassistant/components/seventeentrack/strings.json @@ -68,7 +68,7 @@ "services": { "get_packages": { "name": "Get packages", - "description": "Get packages from 17Track", + "description": "Queries the 17track API for the latest package data.", "fields": { "package_state": { "name": "Package states", @@ -82,7 +82,7 @@ }, "archive_package": { "name": "Archive package", - "description": "Archive a package", + "description": "Archives a package using the 17track API.", "fields": { "package_tracking_number": { "name": "Package tracking number", From cd13eff8ae89575e1786bc3a97ea4d828fda8312 Mon Sep 17 00:00:00 2001 From: Alberto Geniola Date: Mon, 17 Feb 2025 10:01:27 +0100 Subject: [PATCH 24/52] Elmax - fix issue 136877 (#138419) * Fix IPv6 zero-conf discovery not handling hostname correctly. * Aligned tests. * Remove redundant !s notation. * Add IPv6 discovery tests * Parametrize input_uri to avoid duplicated code * Update tests/components/elmax/conftest.py --------- Co-authored-by: Josef Zweck --- homeassistant/components/elmax/config_flow.py | 6 +- tests/components/elmax/__init__.py | 1 + tests/components/elmax/conftest.py | 14 +++-- tests/components/elmax/test_config_flow.py | 63 +++++++++++++++++-- 4 files changed, 73 insertions(+), 11 deletions(-) diff --git a/homeassistant/components/elmax/config_flow.py b/homeassistant/components/elmax/config_flow.py index b8697552626..98e49cc8056 100644 --- a/homeassistant/components/elmax/config_flow.py +++ b/homeassistant/components/elmax/config_flow.py @@ -498,7 +498,11 @@ class ElmaxConfigFlow(ConfigFlow, domain=DOMAIN): self, discovery_info: ZeroconfServiceInfo ) -> ConfigFlowResult: """Handle device found via zeroconf.""" - host = discovery_info.host + host = ( + f"[{discovery_info.ip_address}]" + if discovery_info.ip_address.version == 6 + else str(discovery_info.ip_address) + ) https_port = ( int(discovery_info.port) if discovery_info.port is not None diff --git a/tests/components/elmax/__init__.py b/tests/components/elmax/__init__.py index e1a6728f1f5..391c3ccbfb2 100644 --- a/tests/components/elmax/__init__.py +++ b/tests/components/elmax/__init__.py @@ -30,6 +30,7 @@ MOCK_PANEL_PIN = "000000" MOCK_WRONG_PANEL_PIN = "000000" MOCK_PASSWORD = "password" MOCK_DIRECT_HOST = "1.1.1.1" +MOCK_DIRECT_HOST_V6 = "fd00::be2:54:34:2" MOCK_DIRECT_HOST_CHANGED = "2.2.2.2" MOCK_DIRECT_PORT = 443 MOCK_DIRECT_SSL = True diff --git a/tests/components/elmax/conftest.py b/tests/components/elmax/conftest.py index f8cf33ffe1a..02f01036996 100644 --- a/tests/components/elmax/conftest.py +++ b/tests/components/elmax/conftest.py @@ -18,6 +18,7 @@ import respx from . import ( MOCK_DIRECT_HOST, + MOCK_DIRECT_HOST_V6, MOCK_DIRECT_PORT, MOCK_DIRECT_SSL, MOCK_PANEL_ID, @@ -29,6 +30,7 @@ from tests.common import load_fixture MOCK_DIRECT_BASE_URI = ( f"{'https' if MOCK_DIRECT_SSL else 'http'}://{MOCK_DIRECT_HOST}:{MOCK_DIRECT_PORT}" ) +MOCK_DIRECT_BASE_URI_V6 = f"{'https' if MOCK_DIRECT_SSL else 'http'}://[{MOCK_DIRECT_HOST_V6}]:{MOCK_DIRECT_PORT}" @pytest.fixture(autouse=True) @@ -58,12 +60,16 @@ def httpx_mock_cloud_fixture() -> Generator[respx.MockRouter]: yield respx_mock +@pytest.fixture +def base_uri() -> str: + """Configure the base-uri for the respx mock fixtures.""" + return MOCK_DIRECT_BASE_URI + + @pytest.fixture(autouse=True) -def httpx_mock_direct_fixture() -> Generator[respx.MockRouter]: +def httpx_mock_direct_fixture(base_uri: str) -> Generator[respx.MockRouter]: """Configure httpx fixture for direct Panel-API communication.""" - with respx.mock( - base_url=MOCK_DIRECT_BASE_URI, assert_all_called=False - ) as respx_mock: + with respx.mock(base_url=base_uri, assert_all_called=False) as respx_mock: # Mock Login POST. login_route = respx_mock.post(f"/api/v2/{ENDPOINT_LOGIN}", name="login") diff --git a/tests/components/elmax/test_config_flow.py b/tests/components/elmax/test_config_flow.py index be89ee4d5d6..379cfa98bbc 100644 --- a/tests/components/elmax/test_config_flow.py +++ b/tests/components/elmax/test_config_flow.py @@ -1,8 +1,10 @@ """Tests for the Elmax config flow.""" +from ipaddress import IPv4Address, IPv6Address from unittest.mock import patch from elmax_api.exceptions import ElmaxBadLoginError, ElmaxBadPinError, ElmaxNetworkError +import pytest from homeassistant import config_entries from homeassistant.components.elmax.const import ( @@ -28,6 +30,7 @@ from . import ( MOCK_DIRECT_CERT, MOCK_DIRECT_HOST, MOCK_DIRECT_HOST_CHANGED, + MOCK_DIRECT_HOST_V6, MOCK_DIRECT_PORT, MOCK_DIRECT_SSL, MOCK_PANEL_ID, @@ -37,12 +40,27 @@ from . import ( MOCK_USERNAME, MOCK_WRONG_PANEL_PIN, ) +from .conftest import MOCK_DIRECT_BASE_URI_V6 from tests.common import MockConfigEntry MOCK_ZEROCONF_DISCOVERY_INFO = ZeroconfServiceInfo( - ip_address=MOCK_DIRECT_HOST, - ip_addresses=[MOCK_DIRECT_HOST], + ip_address=IPv4Address(address=MOCK_DIRECT_HOST), + ip_addresses=[IPv4Address(address=MOCK_DIRECT_HOST)], + hostname="VideoBox.local", + name="VideoBox", + port=443, + properties={ + "idl": MOCK_PANEL_ID, + "idr": MOCK_PANEL_ID, + "v1": "PHANTOM64PRO_GSM 11.9.844", + "v2": "4.9.13", + }, + type="_elmax-ssl._tcp", +) +MOCK_ZEROCONF_DISCOVERY_INFO_V6 = ZeroconfServiceInfo( + ip_address=IPv6Address(address=MOCK_DIRECT_HOST_V6), + ip_addresses=[IPv6Address(address=MOCK_DIRECT_HOST_V6)], hostname="VideoBox.local", name="VideoBox", port=443, @@ -55,8 +73,8 @@ MOCK_ZEROCONF_DISCOVERY_INFO = ZeroconfServiceInfo( type="_elmax-ssl._tcp", ) MOCK_ZEROCONF_DISCOVERY_CHANGED_INFO = ZeroconfServiceInfo( - ip_address=MOCK_DIRECT_HOST_CHANGED, - ip_addresses=[MOCK_DIRECT_HOST_CHANGED], + ip_address=IPv4Address(address=MOCK_DIRECT_HOST_CHANGED), + ip_addresses=[IPv4Address(address=MOCK_DIRECT_HOST_CHANGED)], hostname="VideoBox.local", name="VideoBox", port=443, @@ -69,8 +87,8 @@ MOCK_ZEROCONF_DISCOVERY_CHANGED_INFO = ZeroconfServiceInfo( type="_elmax-ssl._tcp", ) MOCK_ZEROCONF_DISCOVERY_INFO_NOT_SUPPORTED = ZeroconfServiceInfo( - ip_address=MOCK_DIRECT_HOST, - ip_addresses=[MOCK_DIRECT_HOST], + ip_address=IPv4Address(MOCK_DIRECT_HOST), + ip_addresses=[IPv4Address(MOCK_DIRECT_HOST)], hostname="VideoBox.local", name="VideoBox", port=443, @@ -194,6 +212,18 @@ async def test_zeroconf_discovery(hass: HomeAssistant) -> None: assert result["errors"] is None +async def test_zeroconf_discovery_ipv6(hass: HomeAssistant) -> None: + """Test discovery of Elmax local api panel.""" + result = await hass.config_entries.flow.async_init( + DOMAIN, + context={"source": config_entries.SOURCE_ZEROCONF}, + data=MOCK_ZEROCONF_DISCOVERY_INFO_V6, + ) + assert result["type"] is FlowResultType.FORM + assert result["step_id"] == "zeroconf_setup" + assert result["errors"] is None + + async def test_zeroconf_setup_show_form(hass: HomeAssistant) -> None: """Test discovery shows a form when activated.""" result = await hass.config_entries.flow.async_init( @@ -230,6 +260,27 @@ async def test_zeroconf_setup(hass: HomeAssistant) -> None: assert result["type"] is FlowResultType.CREATE_ENTRY +@pytest.mark.parametrize("base_uri", [MOCK_DIRECT_BASE_URI_V6]) +async def test_zeroconf_ipv6_setup(hass: HomeAssistant) -> None: + """Test the successful creation of config entry via discovery flow.""" + result = await hass.config_entries.flow.async_init( + DOMAIN, + context={"source": config_entries.SOURCE_ZEROCONF}, + data=MOCK_ZEROCONF_DISCOVERY_INFO_V6, + ) + + result = await hass.config_entries.flow.async_configure( + result["flow_id"], + { + CONF_ELMAX_PANEL_PIN: MOCK_PANEL_PIN, + CONF_ELMAX_MODE_DIRECT_SSL: MOCK_DIRECT_SSL, + }, + ) + + await hass.async_block_till_done() + assert result["type"] is FlowResultType.CREATE_ENTRY + + async def test_zeroconf_already_configured(hass: HomeAssistant) -> None: """Ensure local discovery aborts when same panel is already added to ha.""" MockConfigEntry( From 1fe644d0567019b6aa1c62b063a22c0506071f37 Mon Sep 17 00:00:00 2001 From: Norbert Rittel Date: Mon, 17 Feb 2025 11:05:39 +0100 Subject: [PATCH 25/52] Fix casing in Sensibo action descriptions (#138701) - treat "Pure Boost" as a feature name - fix sentence-casing - capitalize first word --- homeassistant/components/sensibo/strings.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/homeassistant/components/sensibo/strings.json b/homeassistant/components/sensibo/strings.json index 6c5210d12bf..6aba2be52fc 100644 --- a/homeassistant/components/sensibo/strings.json +++ b/homeassistant/components/sensibo/strings.json @@ -429,16 +429,16 @@ } }, "enable_pure_boost": { - "name": "Enable pure boost", + "name": "Enable Pure Boost", "description": "Enables and configures Pure Boost settings.", "fields": { "ac_integration": { "name": "AC integration", - "description": "Integrate with Air Conditioner." + "description": "Integrate with air conditioner." }, "geo_integration": { "name": "Geo integration", - "description": "Integrate with Presence." + "description": "Integrate with presence." }, "indoor_integration": { "name": "Indoor air quality", @@ -468,7 +468,7 @@ }, "fan_mode": { "name": "Fan mode", - "description": "set fan mode." + "description": "Set fan mode." }, "swing_mode": { "name": "Swing mode", From 168e45b0f9b357b80096b991e1e470e0943b028b Mon Sep 17 00:00:00 2001 From: Matrix Date: Mon, 17 Feb 2025 19:24:56 +0800 Subject: [PATCH 26/52] Bump yolink api 0.4.8 (#138703) --- homeassistant/components/yolink/manifest.json | 2 +- requirements_all.txt | 2 +- requirements_test_all.txt | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/yolink/manifest.json b/homeassistant/components/yolink/manifest.json index 78b553d7978..52ae8281f59 100644 --- a/homeassistant/components/yolink/manifest.json +++ b/homeassistant/components/yolink/manifest.json @@ -6,5 +6,5 @@ "dependencies": ["auth", "application_credentials"], "documentation": "https://www.home-assistant.io/integrations/yolink", "iot_class": "cloud_push", - "requirements": ["yolink-api==0.4.7"] + "requirements": ["yolink-api==0.4.8"] } diff --git a/requirements_all.txt b/requirements_all.txt index 3adfa7abb88..9153674fdcc 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -3110,7 +3110,7 @@ yeelight==0.7.16 yeelightsunflower==0.0.10 # homeassistant.components.yolink -yolink-api==0.4.7 +yolink-api==0.4.8 # homeassistant.components.youless youless-api==2.2.0 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index 6ff5c8bc7d7..164562a485b 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -2505,7 +2505,7 @@ yalexs==8.10.0 yeelight==0.7.16 # homeassistant.components.yolink -yolink-api==0.4.7 +yolink-api==0.4.8 # homeassistant.components.youless youless-api==2.2.0 From b4fac38d8a658fef1700440996cf11d780cca01d Mon Sep 17 00:00:00 2001 From: Robert Resch Date: Mon, 17 Feb 2025 12:42:02 +0100 Subject: [PATCH 27/52] Bump uv to 0.6.0 (#138707) --- Dockerfile | 2 +- homeassistant/package_constraints.txt | 2 +- pyproject.toml | 2 +- requirements.txt | 2 +- script/hassfest/docker/Dockerfile | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Dockerfile b/Dockerfile index 19b2c97b181..42a90107c4d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -13,7 +13,7 @@ ENV \ ARG QEMU_CPU # Install uv -RUN pip3 install uv==0.5.27 +RUN pip3 install uv==0.6.0 WORKDIR /usr/src diff --git a/homeassistant/package_constraints.txt b/homeassistant/package_constraints.txt index 7aa76de2620..2b9e5c307a6 100644 --- a/homeassistant/package_constraints.txt +++ b/homeassistant/package_constraints.txt @@ -67,7 +67,7 @@ standard-telnetlib==3.13.0 typing-extensions>=4.12.2,<5.0 ulid-transform==1.2.0 urllib3>=1.26.5,<2 -uv==0.5.27 +uv==0.6.0 voluptuous-openapi==0.0.6 voluptuous-serialize==2.6.0 voluptuous==0.15.2 diff --git a/pyproject.toml b/pyproject.toml index 66b25b75f92..44fef7dea9a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -76,7 +76,7 @@ dependencies = [ # Temporary setting an upper bound, to prevent compat issues with urllib3>=2 # https://github.com/home-assistant/core/issues/97248 "urllib3>=1.26.5,<2", - "uv==0.5.27", + "uv==0.6.0", "voluptuous==0.15.2", "voluptuous-serialize==2.6.0", "voluptuous-openapi==0.0.6", diff --git a/requirements.txt b/requirements.txt index 2cbd3780eae..c06beefab37 100644 --- a/requirements.txt +++ b/requirements.txt @@ -45,7 +45,7 @@ standard-telnetlib==3.13.0 typing-extensions>=4.12.2,<5.0 ulid-transform==1.2.0 urllib3>=1.26.5,<2 -uv==0.5.27 +uv==0.6.0 voluptuous==0.15.2 voluptuous-serialize==2.6.0 voluptuous-openapi==0.0.6 diff --git a/script/hassfest/docker/Dockerfile b/script/hassfest/docker/Dockerfile index 5598c839257..9d652ec1641 100644 --- a/script/hassfest/docker/Dockerfile +++ b/script/hassfest/docker/Dockerfile @@ -14,7 +14,7 @@ WORKDIR "/github/workspace" COPY . /usr/src/homeassistant # Uv is only needed during build -RUN --mount=from=ghcr.io/astral-sh/uv:0.5.27,source=/uv,target=/bin/uv \ +RUN --mount=from=ghcr.io/astral-sh/uv:0.6.0,source=/uv,target=/bin/uv \ # Uv creates a lock file in /tmp --mount=type=tmpfs,target=/tmp \ # Required for PyTurboJPEG From a7f63e3847b38785eb6640b433faae6ac60a559e Mon Sep 17 00:00:00 2001 From: ashionky <35916938+ashionky@users.noreply.github.com> Date: Mon, 17 Feb 2025 20:02:52 +0800 Subject: [PATCH 28/52] Optimize Refoss state_class of Sensor (#138266) TOTAL_INCREASING --- homeassistant/components/refoss/sensor.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/refoss/sensor.py b/homeassistant/components/refoss/sensor.py index 82637aae538..92090a192e8 100644 --- a/homeassistant/components/refoss/sensor.py +++ b/homeassistant/components/refoss/sensor.py @@ -94,7 +94,7 @@ SENSORS: dict[str, tuple[RefossSensorEntityDescription, ...]] = { key="energy", translation_key="this_month_energy", device_class=SensorDeviceClass.ENERGY, - state_class=SensorStateClass.TOTAL, + state_class=SensorStateClass.TOTAL_INCREASING, native_unit_of_measurement=UnitOfEnergy.WATT_HOUR, suggested_display_precision=2, subkey="mConsume", @@ -104,7 +104,7 @@ SENSORS: dict[str, tuple[RefossSensorEntityDescription, ...]] = { key="energy_returned", translation_key="this_month_energy_returned", device_class=SensorDeviceClass.ENERGY, - state_class=SensorStateClass.TOTAL, + state_class=SensorStateClass.TOTAL_INCREASING, native_unit_of_measurement=UnitOfEnergy.WATT_HOUR, suggested_display_precision=2, subkey="mConsume", From df6cb0b824972fa990616c3e6cd774b470bb1cd2 Mon Sep 17 00:00:00 2001 From: Michael <35783820+mib1185@users.noreply.github.com> Date: Mon, 17 Feb 2025 13:03:31 +0100 Subject: [PATCH 29/52] Add repair-issue that backup location setup is missing in Synology DSM (#138233) * add missing backup location setup repair-issue * add tests * tweak translation strings * add test for other fixable issues * remove senseless abort reason no_file_station --- .../components/synology_dsm/common.py | 17 + .../components/synology_dsm/const.py | 2 + .../components/synology_dsm/repairs.py | 125 +++++++ .../components/synology_dsm/strings.json | 31 ++ tests/components/synology_dsm/test_repairs.py | 321 ++++++++++++++++++ 5 files changed, 496 insertions(+) create mode 100644 homeassistant/components/synology_dsm/repairs.py create mode 100644 tests/components/synology_dsm/test_repairs.py diff --git a/homeassistant/components/synology_dsm/common.py b/homeassistant/components/synology_dsm/common.py index dfc372e6bde..d61944c146d 100644 --- a/homeassistant/components/synology_dsm/common.py +++ b/homeassistant/components/synology_dsm/common.py @@ -35,13 +35,17 @@ from homeassistant.const import ( ) from homeassistant.core import HomeAssistant, callback from homeassistant.exceptions import ConfigEntryAuthFailed +from homeassistant.helpers import issue_registry as ir from homeassistant.helpers.aiohttp_client import async_get_clientsession from .const import ( + CONF_BACKUP_PATH, CONF_DEVICE_TOKEN, DEFAULT_TIMEOUT, + DOMAIN, EXCEPTION_DETAILS, EXCEPTION_UNKNOWN, + ISSUE_MISSING_BACKUP_SETUP, SYNOLOGY_CONNECTION_EXCEPTIONS, ) @@ -174,6 +178,19 @@ class SynoApi: " permissions or no writable shared folders available" ) + if shares and not self._entry.options.get(CONF_BACKUP_PATH): + ir.async_create_issue( + self._hass, + DOMAIN, + f"{ISSUE_MISSING_BACKUP_SETUP}_{self._entry.unique_id}", + data={"entry_id": self._entry.entry_id}, + is_fixable=True, + is_persistent=False, + severity=ir.IssueSeverity.WARNING, + translation_key=ISSUE_MISSING_BACKUP_SETUP, + translation_placeholders={"title": self._entry.title}, + ) + LOGGER.debug( "State of File Station during setup of '%s': %s", self._entry.unique_id, diff --git a/homeassistant/components/synology_dsm/const.py b/homeassistant/components/synology_dsm/const.py index 8fb436e8fa6..758fad53970 100644 --- a/homeassistant/components/synology_dsm/const.py +++ b/homeassistant/components/synology_dsm/const.py @@ -35,6 +35,8 @@ PLATFORMS = [ EXCEPTION_DETAILS = "details" EXCEPTION_UNKNOWN = "unknown" +ISSUE_MISSING_BACKUP_SETUP = "missing_backup_setup" + # Configuration CONF_SERIAL = "serial" CONF_VOLUMES = "volumes" diff --git a/homeassistant/components/synology_dsm/repairs.py b/homeassistant/components/synology_dsm/repairs.py new file mode 100644 index 00000000000..725e77a2593 --- /dev/null +++ b/homeassistant/components/synology_dsm/repairs.py @@ -0,0 +1,125 @@ +"""Repair flows for the Synology DSM integration.""" + +from __future__ import annotations + +from contextlib import suppress +import logging +from typing import cast + +from synology_dsm.api.file_station.models import SynoFileSharedFolder +import voluptuous as vol + +from homeassistant import data_entry_flow +from homeassistant.components.repairs import ConfirmRepairFlow, RepairsFlow +from homeassistant.config_entries import ConfigEntry +from homeassistant.core import HomeAssistant +from homeassistant.helpers import issue_registry as ir +from homeassistant.helpers.selector import ( + SelectOptionDict, + SelectSelector, + SelectSelectorConfig, + SelectSelectorMode, +) + +from .const import ( + CONF_BACKUP_PATH, + CONF_BACKUP_SHARE, + DOMAIN, + ISSUE_MISSING_BACKUP_SETUP, + SYNOLOGY_CONNECTION_EXCEPTIONS, +) +from .models import SynologyDSMData + +LOGGER = logging.getLogger(__name__) + + +class MissingBackupSetupRepairFlow(RepairsFlow): + """Handler for an issue fixing flow.""" + + def __init__(self, entry: ConfigEntry, issue_id: str) -> None: + """Create flow.""" + self.entry = entry + self.issue_id = issue_id + super().__init__() + + async def async_step_init( + self, user_input: dict[str, str] | None = None + ) -> data_entry_flow.FlowResult: + """Handle the first step of a fix flow.""" + + return self.async_show_menu( + menu_options=["confirm", "ignore"], + description_placeholders={ + "docs_url": "https://www.home-assistant.io/integrations/synology_dsm/#backup-location" + }, + ) + + async def async_step_confirm( + self, user_input: dict[str, str] | None = None + ) -> data_entry_flow.FlowResult: + """Handle the confirm step of a fix flow.""" + + syno_data: SynologyDSMData = self.hass.data[DOMAIN][self.entry.unique_id] + + if user_input is not None: + self.hass.config_entries.async_update_entry( + self.entry, options={**dict(self.entry.options), **user_input} + ) + return self.async_create_entry(data={}) + + shares: list[SynoFileSharedFolder] | None = None + if syno_data.api.file_station: + with suppress(*SYNOLOGY_CONNECTION_EXCEPTIONS): + shares = await syno_data.api.file_station.get_shared_folders( + only_writable=True + ) + + if not shares: + return self.async_abort(reason="no_shares") + + return self.async_show_form( + data_schema=vol.Schema( + { + vol.Required( + CONF_BACKUP_SHARE, + default=self.entry.options[CONF_BACKUP_SHARE], + ): SelectSelector( + SelectSelectorConfig( + options=[ + SelectOptionDict(value=s.path, label=s.name) + for s in shares + ], + mode=SelectSelectorMode.DROPDOWN, + ), + ), + vol.Required( + CONF_BACKUP_PATH, + default=self.entry.options[CONF_BACKUP_PATH], + ): str, + } + ), + ) + + async def async_step_ignore( + self, _: dict[str, str] | None = None + ) -> data_entry_flow.FlowResult: + """Handle the confirm step of a fix flow.""" + ir.async_ignore_issue(self.hass, DOMAIN, self.issue_id, True) + return self.async_abort(reason="ignored") + + +async def async_create_fix_flow( + hass: HomeAssistant, + issue_id: str, + data: dict[str, str | int | float | None] | None, +) -> RepairsFlow: + """Create flow.""" + entry = None + if data and (entry_id := data.get("entry_id")): + entry_id = cast(str, entry_id) + entry = hass.config_entries.async_get_entry(entry_id) + + if entry and issue_id.startswith(ISSUE_MISSING_BACKUP_SETUP): + return MissingBackupSetupRepairFlow(entry, issue_id) + + return ConfirmRepairFlow() diff --git a/homeassistant/components/synology_dsm/strings.json b/homeassistant/components/synology_dsm/strings.json index c14f8da1037..f51184ef1cb 100644 --- a/homeassistant/components/synology_dsm/strings.json +++ b/homeassistant/components/synology_dsm/strings.json @@ -185,6 +185,37 @@ } } }, + "issues": { + "missing_backup_setup": { + "title": "Backup location not configured for {title}", + "fix_flow": { + "step": { + "init": { + "description": "The backup location for {title} is not configured. Do you want to set it up now? Details can be found in the integration documentation under [Backup Location]({docs_url})", + "menu_options": { + "confirm": "Set up the backup location now", + "ignore": "Don't set it up now" + } + }, + "confirm": { + "title": "[%key:component::synology_dsm::config::step::backup_share::title%]", + "data": { + "backup_share": "[%key:component::synology_dsm::config::step::backup_share::data::backup_share%]", + "backup_path": "[%key:component::synology_dsm::config::step::backup_share::data::backup_path%]" + }, + "data_description": { + "backup_share": "[%key:component::synology_dsm::config::step::backup_share::data_description::backup_share%]", + "backup_path": "[%key:component::synology_dsm::config::step::backup_share::data_description::backup_path%]" + } + } + }, + "abort": { + "no_shares": "There are no shared folders available for the user.\nPlease check the documentation.", + "ignored": "The backup location has not been configured.\nYou can still set it up later via the integration options." + } + } + } + }, "services": { "reboot": { "name": "Reboot", diff --git a/tests/components/synology_dsm/test_repairs.py b/tests/components/synology_dsm/test_repairs.py new file mode 100644 index 00000000000..b2e7352f214 --- /dev/null +++ b/tests/components/synology_dsm/test_repairs.py @@ -0,0 +1,321 @@ +"""Test repairs for synology dsm.""" + +from __future__ import annotations + +from unittest.mock import AsyncMock, MagicMock, Mock, patch + +import pytest +from synology_dsm.api.file_station.models import SynoFileSharedFolder + +from homeassistant.components.repairs import DOMAIN as REPAIRS_DOMAIN +from homeassistant.components.synology_dsm.const import ( + CONF_BACKUP_PATH, + CONF_BACKUP_SHARE, + DOMAIN, +) +from homeassistant.const import ( + CONF_HOST, + CONF_MAC, + CONF_PASSWORD, + CONF_PORT, + CONF_SSL, + CONF_USERNAME, +) +from homeassistant.core import HomeAssistant +from homeassistant.helpers import issue_registry as ir +from homeassistant.setup import async_setup_component + +from .consts import HOST, MACS, PASSWORD, PORT, SERIAL, USE_SSL, USERNAME + +from tests.common import ANY, MockConfigEntry +from tests.components.repairs import process_repair_fix_flow, start_repair_fix_flow +from tests.typing import ClientSessionGenerator, WebSocketGenerator + + +@pytest.fixture +def mock_dsm_with_filestation(): + """Mock a successful service with filestation support.""" + with patch("homeassistant.components.synology_dsm.common.SynologyDSM") as dsm: + dsm.login = AsyncMock(return_value=True) + dsm.update = AsyncMock(return_value=True) + + dsm.surveillance_station.update = AsyncMock(return_value=True) + dsm.upgrade.update = AsyncMock(return_value=True) + dsm.utilisation = Mock(cpu_user_load=1, update=AsyncMock(return_value=True)) + dsm.network = Mock(update=AsyncMock(return_value=True), macs=MACS) + dsm.storage = Mock( + disks_ids=["sda", "sdb", "sdc"], + volumes_ids=["volume_1"], + update=AsyncMock(return_value=True), + ) + dsm.information = Mock(serial=SERIAL) + dsm.file = AsyncMock( + get_shared_folders=AsyncMock( + return_value=[ + SynoFileSharedFolder( + additional=None, + is_dir=True, + name="HA Backup", + path="/ha_backup", + ) + ] + ), + ) + dsm.logout = AsyncMock(return_value=True) + yield dsm + + +@pytest.fixture +async def setup_dsm_with_filestation( + hass: HomeAssistant, + mock_dsm_with_filestation: MagicMock, +): + """Mock setup of synology dsm config entry.""" + with ( + patch( + "homeassistant.components.synology_dsm.common.SynologyDSM", + return_value=mock_dsm_with_filestation, + ), + patch("homeassistant.components.synology_dsm.PLATFORMS", return_value=[]), + ): + entry = MockConfigEntry( + domain=DOMAIN, + data={ + CONF_HOST: HOST, + CONF_PORT: PORT, + CONF_SSL: USE_SSL, + CONF_USERNAME: USERNAME, + CONF_PASSWORD: PASSWORD, + CONF_MAC: MACS[0], + }, + options={ + CONF_BACKUP_PATH: None, + CONF_BACKUP_SHARE: None, + }, + unique_id="my_serial", + ) + entry.add_to_hass(hass) + assert await hass.config_entries.async_setup(entry.entry_id) + assert await async_setup_component(hass, REPAIRS_DOMAIN, {}) + await hass.async_block_till_done() + + yield mock_dsm_with_filestation + + +async def test_create_issue( + hass: HomeAssistant, + setup_dsm_with_filestation: MagicMock, + hass_ws_client: WebSocketGenerator, +) -> None: + """Test the issue is created.""" + ws_client = await hass_ws_client(hass) + await ws_client.send_json({"id": 1, "type": "repairs/list_issues"}) + msg = await ws_client.receive_json() + + assert msg["success"] + assert len(msg["result"]["issues"]) == 1 + issue = msg["result"]["issues"][0] + assert issue["breaks_in_ha_version"] is None + assert issue["domain"] == DOMAIN + assert issue["issue_id"] == "missing_backup_setup_my_serial" + assert issue["translation_key"] == "missing_backup_setup" + + +async def test_missing_backup_ignore( + hass: HomeAssistant, + setup_dsm_with_filestation: MagicMock, + hass_client: ClientSessionGenerator, + hass_ws_client: WebSocketGenerator, +) -> None: + """Test missing backup location setup issue is ignored by the user.""" + ws_client = await hass_ws_client(hass) + client = await hass_client() + + # get repair issues + await ws_client.send_json({"id": 1, "type": "repairs/list_issues"}) + msg = await ws_client.receive_json() + assert msg["success"] + assert len(msg["result"]["issues"]) == 1 + issue = msg["result"]["issues"][0] + assert not issue["ignored"] + + # start repair flow + data = await start_repair_fix_flow(client, DOMAIN, "missing_backup_setup_my_serial") + + flow_id = data["flow_id"] + assert data["description_placeholders"] == { + "docs_url": "https://www.home-assistant.io/integrations/synology_dsm/#backup-location" + } + assert data["step_id"] == "init" + assert data["menu_options"] == ["confirm", "ignore"] + + # seelct to ignore the flow + data = await process_repair_fix_flow( + client, flow_id, json={"next_step_id": "ignore"} + ) + assert data["type"] == "abort" + assert data["reason"] == "ignored" + + # check issue is ignored + await ws_client.send_json({"id": 2, "type": "repairs/list_issues"}) + msg = await ws_client.receive_json() + assert msg["success"] + assert len(msg["result"]["issues"]) == 1 + issue = msg["result"]["issues"][0] + assert issue["ignored"] + + +async def test_missing_backup_success( + hass: HomeAssistant, + setup_dsm_with_filestation: MagicMock, + hass_client: ClientSessionGenerator, + hass_ws_client: WebSocketGenerator, +) -> None: + """Test the missing backup location setup repair flow is fully processed by the user.""" + ws_client = await hass_ws_client(hass) + client = await hass_client() + entries = hass.config_entries.async_entries(DOMAIN) + assert len(entries) == 1 + entry = entries[0] + assert entry.options == {"backup_path": None, "backup_share": None} + + # get repair issues + await ws_client.send_json({"id": 1, "type": "repairs/list_issues"}) + msg = await ws_client.receive_json() + assert msg["success"] + assert len(msg["result"]["issues"]) == 1 + issue = msg["result"]["issues"][0] + assert not issue["ignored"] + + # start repair flow + data = await start_repair_fix_flow(client, DOMAIN, "missing_backup_setup_my_serial") + + flow_id = data["flow_id"] + assert data["description_placeholders"] == { + "docs_url": "https://www.home-assistant.io/integrations/synology_dsm/#backup-location" + } + assert data["step_id"] == "init" + assert data["menu_options"] == ["confirm", "ignore"] + + # seelct to confirm the flow + data = await process_repair_fix_flow( + client, flow_id, json={"next_step_id": "confirm"} + ) + assert data["step_id"] == "confirm" + assert data["type"] == "form" + + # fill out the form and submit + data = await process_repair_fix_flow( + client, + flow_id, + json={"backup_share": "/ha_backup", "backup_path": "backup_ha_dev"}, + ) + assert data["type"] == "create_entry" + assert entry.options == { + "backup_path": "backup_ha_dev", + "backup_share": "/ha_backup", + } + + +async def test_missing_backup_no_shares( + hass: HomeAssistant, + setup_dsm_with_filestation: MagicMock, + hass_client: ClientSessionGenerator, + hass_ws_client: WebSocketGenerator, +) -> None: + """Test the missing backup location setup repair flow errors out.""" + ws_client = await hass_ws_client(hass) + client = await hass_client() + + # get repair issues + await ws_client.send_json({"id": 1, "type": "repairs/list_issues"}) + msg = await ws_client.receive_json() + assert msg["success"] + assert len(msg["result"]["issues"]) == 1 + + # start repair flow + data = await start_repair_fix_flow(client, DOMAIN, "missing_backup_setup_my_serial") + + flow_id = data["flow_id"] + assert data["description_placeholders"] == { + "docs_url": "https://www.home-assistant.io/integrations/synology_dsm/#backup-location" + } + assert data["step_id"] == "init" + assert data["menu_options"] == ["confirm", "ignore"] + + # inject error + setup_dsm_with_filestation.file.get_shared_folders.return_value = [] + + # select to confirm the flow + data = await process_repair_fix_flow( + client, flow_id, json={"next_step_id": "confirm"} + ) + assert data["type"] == "abort" + assert data["reason"] == "no_shares" + + +@pytest.mark.parametrize( + "ignore_translations", + ["component.synology_dsm.issues.other_issue.title"], +) +async def test_other_fixable_issues( + hass: HomeAssistant, + setup_dsm_with_filestation: MagicMock, + hass_client: ClientSessionGenerator, + hass_ws_client: WebSocketGenerator, +) -> None: + """Test fixing another issue.""" + ws_client = await hass_ws_client(hass) + client = await hass_client() + + await ws_client.send_json({"id": 1, "type": "repairs/list_issues"}) + msg = await ws_client.receive_json() + + assert msg["success"] + + issue = { + "breaks_in_ha_version": None, + "domain": DOMAIN, + "issue_id": "other_issue", + "is_fixable": True, + "severity": "error", + "translation_key": "other_issue", + } + ir.async_create_issue( + hass, + issue["domain"], + issue["issue_id"], + is_fixable=issue["is_fixable"], + severity=issue["severity"], + translation_key=issue["translation_key"], + ) + + await ws_client.send_json({"id": 2, "type": "repairs/list_issues"}) + msg = await ws_client.receive_json() + + assert msg["success"] + results = msg["result"]["issues"] + assert { + "breaks_in_ha_version": None, + "created": ANY, + "dismissed_version": None, + "domain": "synology_dsm", + "ignored": False, + "is_fixable": True, + "issue_domain": None, + "issue_id": "other_issue", + "learn_more_url": None, + "severity": "error", + "translation_key": "other_issue", + "translation_placeholders": None, + } in results + + data = await start_repair_fix_flow(client, DOMAIN, "other_issue") + + flow_id = data["flow_id"] + assert data["step_id"] == "confirm" + + data = await process_repair_fix_flow(client, flow_id) + + assert data["type"] == "create_entry" + await hass.async_block_till_done() From 4a385ed26c2cc4adaf50a33352340c6acda73726 Mon Sep 17 00:00:00 2001 From: Norbert Rittel Date: Mon, 17 Feb 2025 13:38:42 +0100 Subject: [PATCH 30/52] Use correct camel-case for OpenThread, reword error message (#138651) * Use correct camel-case for OpenThread, reword error message * Treat "Border Agent ID" as a name by capitalizing it --- homeassistant/components/otbr/strings.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/otbr/strings.json b/homeassistant/components/otbr/strings.json index e1afa5b8909..3a9661c454d 100644 --- a/homeassistant/components/otbr/strings.json +++ b/homeassistant/components/otbr/strings.json @@ -5,7 +5,7 @@ "data": { "url": "[%key:common::config_flow::data::url%]" }, - "description": "Provide URL for the Open Thread Border Router's REST API" + "description": "Provide URL for the OpenThread Border Router's REST API" } }, "error": { @@ -20,8 +20,8 @@ }, "issues": { "get_get_border_agent_id_unsupported": { - "title": "The OTBR does not support border agent ID", - "description": "Your OTBR does not support border agent ID.\n\nTo fix this issue, update the OTBR to the latest version and restart Home Assistant.\nTo update the OTBR, update the Open Thread Border Router or Silicon Labs Multiprotocol add-on if you use the OTBR from the add-on, otherwise update your self managed OTBR." + "title": "The OTBR does not support Border Agent ID", + "description": "Your OTBR does not support Border Agent ID.\n\nTo fix this issue, update the OTBR to the latest version and restart Home Assistant.\nIf you are using an OTBR integrated in Home Assistant, update either the OpenThread Border Router add-on or the Silicon Labs Multiprotocol add-on. Otherwise update your self-managed OTBR." }, "insecure_thread_network": { "title": "Insecure Thread network settings detected", From d8d054e7dd62ce0f0e83c48cf7c466b266edb989 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Mon, 17 Feb 2025 14:45:00 +0100 Subject: [PATCH 31/52] Improve type hints in base entities (#138708) --- homeassistant/components/broadlink/entity.py | 6 +++--- homeassistant/components/enocean/entity.py | 2 +- homeassistant/components/flo/entity.py | 4 ++-- homeassistant/components/hlk_sw16/entity.py | 4 ++-- homeassistant/components/homematic/entity.py | 4 ++-- homeassistant/components/ihc/entity.py | 2 +- homeassistant/components/insteon/entity.py | 4 ++-- homeassistant/components/lupusec/entity.py | 2 +- homeassistant/components/lutron_caseta/entity.py | 2 +- homeassistant/components/onvif/entity.py | 2 +- homeassistant/components/pilight/entity.py | 4 ++-- homeassistant/components/plaato/entity.py | 4 ++-- homeassistant/components/point/entity.py | 4 ++-- homeassistant/components/qwikswitch/entity.py | 2 +- homeassistant/components/raincloud/entity.py | 2 +- homeassistant/components/rflink/entity.py | 8 ++++---- homeassistant/components/roomba/entity.py | 2 +- homeassistant/components/soma/entity.py | 2 +- homeassistant/components/starline/entity.py | 8 ++++---- homeassistant/components/tellduslive/entity.py | 6 +++--- homeassistant/components/tellstick/entity.py | 4 ++-- homeassistant/components/upb/entity.py | 4 ++-- homeassistant/components/velux/entity.py | 2 +- homeassistant/components/vera/entity.py | 4 ++-- homeassistant/components/volvooncall/entity.py | 2 +- homeassistant/components/wiffi/entity.py | 2 +- homeassistant/components/wirelesstag/entity.py | 4 ++-- homeassistant/components/xiaomi_aqara/entity.py | 4 ++-- homeassistant/components/xiaomi_miio/entity.py | 2 +- homeassistant/components/xs1/entity.py | 2 +- homeassistant/components/yamaha_musiccast/entity.py | 4 ++-- 31 files changed, 54 insertions(+), 54 deletions(-) diff --git a/homeassistant/components/broadlink/entity.py b/homeassistant/components/broadlink/entity.py index 6c956d8c80a..a97374680f9 100644 --- a/homeassistant/components/broadlink/entity.py +++ b/homeassistant/components/broadlink/entity.py @@ -17,13 +17,13 @@ class BroadlinkEntity(Entity): self._device = device self._coordinator = device.update_manager.coordinator - async def async_added_to_hass(self): + async def async_added_to_hass(self) -> None: """Call when the entity is added to hass.""" self.async_on_remove(self._coordinator.async_add_listener(self._recv_data)) if self._coordinator.data: self._update_state(self._coordinator.data) - async def async_update(self): + async def async_update(self) -> None: """Update the state of the entity.""" await self._coordinator.async_request_refresh() @@ -49,7 +49,7 @@ class BroadlinkEntity(Entity): """ @property - def available(self): + def available(self) -> bool: """Return True if the entity is available.""" return self._device.available diff --git a/homeassistant/components/enocean/entity.py b/homeassistant/components/enocean/entity.py index 5c12fc12a68..b2d73e65443 100644 --- a/homeassistant/components/enocean/entity.py +++ b/homeassistant/components/enocean/entity.py @@ -16,7 +16,7 @@ class EnOceanEntity(Entity): """Initialize the device.""" self.dev_id = dev_id - async def async_added_to_hass(self): + async def async_added_to_hass(self) -> None: """Register callbacks.""" self.async_on_remove( async_dispatcher_connect( diff --git a/homeassistant/components/flo/entity.py b/homeassistant/components/flo/entity.py index b0cf8d04313..072afbae4f2 100644 --- a/homeassistant/components/flo/entity.py +++ b/homeassistant/components/flo/entity.py @@ -45,10 +45,10 @@ class FloEntity(Entity): """Return True if device is available.""" return self._device.available - async def async_update(self): + async def async_update(self) -> None: """Update Flo entity.""" await self._device.async_request_refresh() - async def async_added_to_hass(self): + async def async_added_to_hass(self) -> None: """When entity is added to hass.""" self.async_on_remove(self._device.async_add_listener(self.async_write_ha_state)) diff --git a/homeassistant/components/hlk_sw16/entity.py b/homeassistant/components/hlk_sw16/entity.py index fdef5f6764b..91510760968 100644 --- a/homeassistant/components/hlk_sw16/entity.py +++ b/homeassistant/components/hlk_sw16/entity.py @@ -35,7 +35,7 @@ class SW16Entity(Entity): self.async_write_ha_state() @property - def available(self): + def available(self) -> bool: """Return True if entity is available.""" return bool(self._client.is_connected) @@ -44,7 +44,7 @@ class SW16Entity(Entity): """Update availability state.""" self.async_write_ha_state() - async def async_added_to_hass(self): + async def async_added_to_hass(self) -> None: """Register update callback.""" self._client.register_status_callback( self.handle_event_callback, self._device_port diff --git a/homeassistant/components/homematic/entity.py b/homeassistant/components/homematic/entity.py index 5a5b2a3b8c8..44e95e98f38 100644 --- a/homeassistant/components/homematic/entity.py +++ b/homeassistant/components/homematic/entity.py @@ -62,7 +62,7 @@ class HMDevice(Entity): if self._state: self._state = self._state.upper() - async def async_added_to_hass(self): + async def async_added_to_hass(self) -> None: """Load data init callbacks.""" self._subscribe_homematic_events() @@ -77,7 +77,7 @@ class HMDevice(Entity): return self._name @property - def available(self): + def available(self) -> bool: """Return true if device is available.""" return self._available diff --git a/homeassistant/components/ihc/entity.py b/homeassistant/components/ihc/entity.py index f90b2ee943c..8847ffc9f49 100644 --- a/homeassistant/components/ihc/entity.py +++ b/homeassistant/components/ihc/entity.py @@ -54,7 +54,7 @@ class IHCEntity(Entity): self.ihc_note = "" self.ihc_position = "" - async def async_added_to_hass(self): + async def async_added_to_hass(self) -> None: """Add callback for IHC changes.""" _LOGGER.debug("Adding IHC entity notify event: %s", self.ihc_id) self.ihc_controller.add_notify_event(self.ihc_id, self.on_ihc_change, True) diff --git a/homeassistant/components/insteon/entity.py b/homeassistant/components/insteon/entity.py index 79e5c18a934..b7886723fdf 100644 --- a/homeassistant/components/insteon/entity.py +++ b/homeassistant/components/insteon/entity.py @@ -109,7 +109,7 @@ class InsteonEntity(Entity): ) self.async_write_ha_state() - async def async_added_to_hass(self): + async def async_added_to_hass(self) -> None: """Register INSTEON update events.""" _LOGGER.debug( "Tracking updates for device %s group %d name %s", @@ -137,7 +137,7 @@ class InsteonEntity(Entity): ) ) - async def async_will_remove_from_hass(self): + async def async_will_remove_from_hass(self) -> None: """Unsubscribe to INSTEON update events.""" _LOGGER.debug( "Remove tracking updates for device %s group %d name %s", diff --git a/homeassistant/components/lupusec/entity.py b/homeassistant/components/lupusec/entity.py index dc0dac89dc8..8cfb559b84f 100644 --- a/homeassistant/components/lupusec/entity.py +++ b/homeassistant/components/lupusec/entity.py @@ -18,7 +18,7 @@ class LupusecDevice(Entity): self._device = device self._attr_unique_id = device.device_id - def update(self): + def update(self) -> None: """Update automation state.""" self._device.refresh() diff --git a/homeassistant/components/lutron_caseta/entity.py b/homeassistant/components/lutron_caseta/entity.py index f954be74f1d..5ab211ed87b 100644 --- a/homeassistant/components/lutron_caseta/entity.py +++ b/homeassistant/components/lutron_caseta/entity.py @@ -63,7 +63,7 @@ class LutronCasetaEntity(Entity): info[ATTR_SUGGESTED_AREA] = area self._attr_device_info = info - async def async_added_to_hass(self): + async def async_added_to_hass(self) -> None: """Register callbacks.""" self._smartbridge.add_subscriber(self.device_id, self.async_write_ha_state) diff --git a/homeassistant/components/onvif/entity.py b/homeassistant/components/onvif/entity.py index c9900106256..783df743e86 100644 --- a/homeassistant/components/onvif/entity.py +++ b/homeassistant/components/onvif/entity.py @@ -17,7 +17,7 @@ class ONVIFBaseEntity(Entity): self.device: ONVIFDevice = device @property - def available(self): + def available(self) -> bool: """Return True if device is available.""" return self.device.available diff --git a/homeassistant/components/pilight/entity.py b/homeassistant/components/pilight/entity.py index fbb924d7f8f..fbfa5cfb5e1 100644 --- a/homeassistant/components/pilight/entity.py +++ b/homeassistant/components/pilight/entity.py @@ -86,7 +86,7 @@ class PilightBaseDevice(RestoreEntity): self._brightness = 255 - async def async_added_to_hass(self): + async def async_added_to_hass(self) -> None: """Call when entity about to be added to hass.""" await super().async_added_to_hass() if state := await self.async_get_last_state(): @@ -99,7 +99,7 @@ class PilightBaseDevice(RestoreEntity): return self._name @property - def assumed_state(self): + def assumed_state(self) -> bool: """Return True if unable to access real state of the entity.""" return True diff --git a/homeassistant/components/plaato/entity.py b/homeassistant/components/plaato/entity.py index 7ab8367bd1d..9cc63a38a64 100644 --- a/homeassistant/components/plaato/entity.py +++ b/homeassistant/components/plaato/entity.py @@ -73,13 +73,13 @@ class PlaatoEntity(entity.Entity): return None @property - def available(self): + def available(self) -> bool: """Return if sensor is available.""" if self._coordinator is not None: return self._coordinator.last_update_success return True - async def async_added_to_hass(self): + async def async_added_to_hass(self) -> None: """When entity is added to hass.""" if self._coordinator is not None: self.async_on_remove( diff --git a/homeassistant/components/point/entity.py b/homeassistant/components/point/entity.py index 4784dd43180..5c52e81e6f7 100644 --- a/homeassistant/components/point/entity.py +++ b/homeassistant/components/point/entity.py @@ -52,7 +52,7 @@ class MinutPointEntity(Entity): ) await self._update_callback() - async def async_will_remove_from_hass(self): + async def async_will_remove_from_hass(self) -> None: """Disconnect dispatcher listener when removed.""" if self._async_unsub_dispatcher_connect: self._async_unsub_dispatcher_connect() @@ -61,7 +61,7 @@ class MinutPointEntity(Entity): """Update the value of the sensor.""" @property - def available(self): + def available(self) -> bool: """Return true if device is not offline.""" return self._client.is_available(self.device_id) diff --git a/homeassistant/components/qwikswitch/entity.py b/homeassistant/components/qwikswitch/entity.py index 3a2ec5a9206..ff7a1d2e98a 100644 --- a/homeassistant/components/qwikswitch/entity.py +++ b/homeassistant/components/qwikswitch/entity.py @@ -35,7 +35,7 @@ class QSEntity(Entity): """Receive update packet from QSUSB. Match dispather_send signature.""" self.async_write_ha_state() - async def async_added_to_hass(self): + async def async_added_to_hass(self) -> None: """Listen for updates from QSUSb via dispatcher.""" self.async_on_remove( async_dispatcher_connect(self.hass, self.qsid, self.update_packet) diff --git a/homeassistant/components/raincloud/entity.py b/homeassistant/components/raincloud/entity.py index 337324d96eb..b45684ac72b 100644 --- a/homeassistant/components/raincloud/entity.py +++ b/homeassistant/components/raincloud/entity.py @@ -45,7 +45,7 @@ class RainCloudEntity(Entity): """Return the name of the sensor.""" return self._name - async def async_added_to_hass(self): + async def async_added_to_hass(self) -> None: """Register callbacks.""" self.async_on_remove( async_dispatcher_connect( diff --git a/homeassistant/components/rflink/entity.py b/homeassistant/components/rflink/entity.py index 26153acf7ba..0caec4ea2c3 100644 --- a/homeassistant/components/rflink/entity.py +++ b/homeassistant/components/rflink/entity.py @@ -105,12 +105,12 @@ class RflinkDevice(Entity): return self._state @property - def assumed_state(self): + def assumed_state(self) -> bool: """Assume device state until first device event sets state.""" return self._state is None @property - def available(self): + def available(self) -> bool: """Return True if entity is available.""" return self._available @@ -120,7 +120,7 @@ class RflinkDevice(Entity): self._available = availability self.async_write_ha_state() - async def async_added_to_hass(self): + async def async_added_to_hass(self) -> None: """Register update callback.""" await super().async_added_to_hass() # Remove temporary bogus entity_id if added @@ -300,7 +300,7 @@ class RflinkCommand(RflinkDevice): class SwitchableRflinkDevice(RflinkCommand, RestoreEntity): """Rflink entity which can switch on/off (eg: light, switch).""" - async def async_added_to_hass(self): + async def async_added_to_hass(self) -> None: """Restore RFLink device state (ON/OFF).""" await super().async_added_to_hass() if (old_state := await self.async_get_last_state()) is not None: diff --git a/homeassistant/components/roomba/entity.py b/homeassistant/components/roomba/entity.py index ae5577da4e4..14c7ac3af3e 100644 --- a/homeassistant/components/roomba/entity.py +++ b/homeassistant/components/roomba/entity.py @@ -80,7 +80,7 @@ class IRobotEntity(Entity): return None return dt_util.utc_from_timestamp(ts) - async def async_added_to_hass(self): + async def async_added_to_hass(self) -> None: """Register callback function.""" self.vacuum.register_on_message_callback(self.on_message) diff --git a/homeassistant/components/soma/entity.py b/homeassistant/components/soma/entity.py index f9824d107b1..4b2fcee5405 100644 --- a/homeassistant/components/soma/entity.py +++ b/homeassistant/components/soma/entity.py @@ -71,7 +71,7 @@ class SomaEntity(Entity): self.api_is_available = True @property - def available(self): + def available(self) -> bool: """Return true if the last API commands returned successfully.""" return self.is_available diff --git a/homeassistant/components/starline/entity.py b/homeassistant/components/starline/entity.py index 74807996dfb..f8846c2a97f 100644 --- a/homeassistant/components/starline/entity.py +++ b/homeassistant/components/starline/entity.py @@ -27,20 +27,20 @@ class StarlineEntity(Entity): self._unsubscribe_api: Callable | None = None @property - def available(self): + def available(self) -> bool: """Return True if entity is available.""" return self._account.api.available - def update(self): + def update(self) -> None: """Read new state data.""" self.schedule_update_ha_state() - async def async_added_to_hass(self): + async def async_added_to_hass(self) -> None: """Call when entity about to be added to Home Assistant.""" await super().async_added_to_hass() self._unsubscribe_api = self._account.api.add_update_listener(self.update) - async def async_will_remove_from_hass(self): + async def async_will_remove_from_hass(self) -> None: """Call when entity is being removed from Home Assistant.""" await super().async_will_remove_from_hass() if self._unsubscribe_api is not None: diff --git a/homeassistant/components/tellduslive/entity.py b/homeassistant/components/tellduslive/entity.py index a71fcb685c0..5366e4c27df 100644 --- a/homeassistant/components/tellduslive/entity.py +++ b/homeassistant/components/tellduslive/entity.py @@ -33,7 +33,7 @@ class TelldusLiveEntity(Entity): self._id = device_id self._client = client - async def async_added_to_hass(self): + async def async_added_to_hass(self) -> None: """Call when entity is added to hass.""" _LOGGER.debug("Created device %s", self) self.async_on_remove( @@ -58,12 +58,12 @@ class TelldusLiveEntity(Entity): return self.device.state @property - def assumed_state(self): + def assumed_state(self) -> bool: """Return true if unable to access real state of entity.""" return True @property - def available(self): + def available(self) -> bool: """Return true if device is not offline.""" return self._client.is_available(self.device_id) diff --git a/homeassistant/components/tellstick/entity.py b/homeassistant/components/tellstick/entity.py index 746c7f4dd4d..5be3d1f48f4 100644 --- a/homeassistant/components/tellstick/entity.py +++ b/homeassistant/components/tellstick/entity.py @@ -40,7 +40,7 @@ class TellstickDevice(Entity): self._attr_name = tellcore_device.name self._attr_unique_id = tellcore_device.id - async def async_added_to_hass(self): + async def async_added_to_hass(self) -> None: """Register callbacks.""" self.async_on_remove( async_dispatcher_connect( @@ -146,6 +146,6 @@ class TellstickDevice(Entity): except TelldusError as err: _LOGGER.error(err) - def update(self): + def update(self) -> None: """Poll the current state of the device.""" self._update_from_tellcore() diff --git a/homeassistant/components/upb/entity.py b/homeassistant/components/upb/entity.py index 13037adf680..8a9afa453b1 100644 --- a/homeassistant/components/upb/entity.py +++ b/homeassistant/components/upb/entity.py @@ -30,7 +30,7 @@ class UpbEntity(Entity): return self._element.as_dict() @property - def available(self): + def available(self) -> bool: """Is the entity available to be updated.""" return self._upb.is_connected() @@ -43,7 +43,7 @@ class UpbEntity(Entity): self._element_changed(element, changeset) self.async_write_ha_state() - async def async_added_to_hass(self): + async def async_added_to_hass(self) -> None: """Register callback for UPB changes and update entity state.""" self._element.add_callback(self._element_callback) self._element_callback(self._element, {}) diff --git a/homeassistant/components/velux/entity.py b/homeassistant/components/velux/entity.py index 674ba5dde45..1231a98e0a8 100644 --- a/homeassistant/components/velux/entity.py +++ b/homeassistant/components/velux/entity.py @@ -31,6 +31,6 @@ class VeluxEntity(Entity): self.node.register_device_updated_cb(after_update_callback) - async def async_added_to_hass(self): + async def async_added_to_hass(self) -> None: """Store register state change callback.""" self.async_register_callbacks() diff --git a/homeassistant/components/vera/entity.py b/homeassistant/components/vera/entity.py index 84e21e54983..b3013c288c1 100644 --- a/homeassistant/components/vera/entity.py +++ b/homeassistant/components/vera/entity.py @@ -52,7 +52,7 @@ class VeraEntity[_DeviceTypeT: veraApi.VeraDevice](Entity): """Update the state.""" self.schedule_update_ha_state(True) - def update(self): + def update(self) -> None: """Force a refresh from the device if the device is unavailable.""" refresh_needed = self.vera_device.should_poll or not self.available _LOGGER.debug("%s: update called (refresh=%s)", self._name, refresh_needed) @@ -90,7 +90,7 @@ class VeraEntity[_DeviceTypeT: veraApi.VeraDevice](Entity): return attr @property - def available(self): + def available(self) -> bool: """If device communications have failed return false.""" return not self.vera_device.comm_failure diff --git a/homeassistant/components/volvooncall/entity.py b/homeassistant/components/volvooncall/entity.py index 6ebc4bdc754..5a1194e8b1a 100644 --- a/homeassistant/components/volvooncall/entity.py +++ b/homeassistant/components/volvooncall/entity.py @@ -57,7 +57,7 @@ class VolvoEntity(CoordinatorEntity[VolvoUpdateCoordinator]): return f"{self._vehicle_name} {self._entity_name}" @property - def assumed_state(self): + def assumed_state(self) -> bool: """Return true if unable to access real state of entity.""" return True diff --git a/homeassistant/components/wiffi/entity.py b/homeassistant/components/wiffi/entity.py index fd774c930c8..84bbc9b3df1 100644 --- a/homeassistant/components/wiffi/entity.py +++ b/homeassistant/components/wiffi/entity.py @@ -41,7 +41,7 @@ class WiffiEntity(Entity): self._value = None self._timeout = options.get(CONF_TIMEOUT, DEFAULT_TIMEOUT) - async def async_added_to_hass(self): + async def async_added_to_hass(self) -> None: """Entity has been added to hass.""" self.async_on_remove( async_dispatcher_connect( diff --git a/homeassistant/components/wirelesstag/entity.py b/homeassistant/components/wirelesstag/entity.py index 31f8ee99d0d..73b13cdc397 100644 --- a/homeassistant/components/wirelesstag/entity.py +++ b/homeassistant/components/wirelesstag/entity.py @@ -60,11 +60,11 @@ class WirelessTagBaseSensor(Entity): return f"{value:.1f}" @property - def available(self): + def available(self) -> bool: """Return True if entity is available.""" return self._tag.is_alive - def update(self): + def update(self) -> None: """Update state.""" if not self.should_poll: return diff --git a/homeassistant/components/xiaomi_aqara/entity.py b/homeassistant/components/xiaomi_aqara/entity.py index db47015c0cf..59107984ddf 100644 --- a/homeassistant/components/xiaomi_aqara/entity.py +++ b/homeassistant/components/xiaomi_aqara/entity.py @@ -57,7 +57,7 @@ class XiaomiDevice(Entity): self._is_gateway = False self._device_id = self._sid - async def async_added_to_hass(self): + async def async_added_to_hass(self) -> None: """Start unavailability tracking.""" self._xiaomi_hub.callbacks[self._sid].append(self.push_data) self._async_track_unavailable() @@ -100,7 +100,7 @@ class XiaomiDevice(Entity): return device_info @property - def available(self): + def available(self) -> bool: """Return True if entity is available.""" return self._is_available diff --git a/homeassistant/components/xiaomi_miio/entity.py b/homeassistant/components/xiaomi_miio/entity.py index 0343a7526d7..ba1148985ba 100644 --- a/homeassistant/components/xiaomi_miio/entity.py +++ b/homeassistant/components/xiaomi_miio/entity.py @@ -185,7 +185,7 @@ class XiaomiGatewayDevice(CoordinatorEntity, Entity): ) @property - def available(self): + def available(self) -> bool: """Return if entity is available.""" if self.coordinator.data is None: return False diff --git a/homeassistant/components/xs1/entity.py b/homeassistant/components/xs1/entity.py index 7239a6fd446..c1ec43ec33c 100644 --- a/homeassistant/components/xs1/entity.py +++ b/homeassistant/components/xs1/entity.py @@ -17,7 +17,7 @@ class XS1DeviceEntity(Entity): """Initialize the XS1 device.""" self.device = device - async def async_update(self): + async def async_update(self) -> None: """Retrieve latest device state.""" async with UPDATE_LOCK: await self.hass.async_add_executor_job(self.device.update) diff --git a/homeassistant/components/yamaha_musiccast/entity.py b/homeassistant/components/yamaha_musiccast/entity.py index 4f1add825e4..8023b13c10a 100644 --- a/homeassistant/components/yamaha_musiccast/entity.py +++ b/homeassistant/components/yamaha_musiccast/entity.py @@ -78,13 +78,13 @@ class MusicCastDeviceEntity(MusicCastEntity): return device_info - async def async_added_to_hass(self): + async def async_added_to_hass(self) -> None: """Run when this Entity has been added to HA.""" await super().async_added_to_hass() # All entities should register callbacks to update HA when their state changes self.coordinator.musiccast.register_callback(self.async_write_ha_state) - async def async_will_remove_from_hass(self): + async def async_will_remove_from_hass(self) -> None: """Entity being removed from hass.""" await super().async_will_remove_from_hass() self.coordinator.musiccast.remove_callback(self.async_write_ha_state) From 7e388f69b0f3b009aef587c1ed70e7a60cef87b6 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Mon, 17 Feb 2025 14:45:32 +0100 Subject: [PATCH 32/52] Add common entity module to pylint plugin (#138706) * Add common entity module to pylint plugin * Fix pylint errors --- homeassistant/components/isy994/entity.py | 4 ++-- homeassistant/components/switchbot/entity.py | 2 +- pylint/plugins/hass_enforce_type_hints.py | 10 ++++++++++ 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/isy994/entity.py b/homeassistant/components/isy994/entity.py index 893b33644fe..1da727fdee8 100644 --- a/homeassistant/components/isy994/entity.py +++ b/homeassistant/components/isy994/entity.py @@ -106,7 +106,7 @@ class ISYNodeEntity(ISYEntity): return getattr(self._node, TAG_ENABLED, True) @property - def extra_state_attributes(self) -> dict: + def extra_state_attributes(self) -> dict[str, Any]: """Get the state attributes for the device. The 'aux_properties' in the pyisy Node class are combined with the @@ -189,7 +189,7 @@ class ISYProgramEntity(ISYEntity): self._actions = actions @property - def extra_state_attributes(self) -> dict: + def extra_state_attributes(self) -> dict[str, Any]: """Get the state attributes for the device.""" attr = {} if self._actions: diff --git a/homeassistant/components/switchbot/entity.py b/homeassistant/components/switchbot/entity.py index bde69429bc3..282d23bfd1a 100644 --- a/homeassistant/components/switchbot/entity.py +++ b/homeassistant/components/switchbot/entity.py @@ -61,7 +61,7 @@ class SwitchbotEntity( return self.coordinator.device.parsed_data @property - def extra_state_attributes(self) -> Mapping[Any, Any]: + def extra_state_attributes(self) -> Mapping[str, Any]: """Return the state attributes.""" return {"last_run_success": self._last_run_success} diff --git a/pylint/plugins/hass_enforce_type_hints.py b/pylint/plugins/hass_enforce_type_hints.py index e2b6de6e6a3..a4590207294 100644 --- a/pylint/plugins/hass_enforce_type_hints.py +++ b/pylint/plugins/hass_enforce_type_hints.py @@ -1410,6 +1410,16 @@ _INHERITANCE_MATCH: dict[str, list[ClassTypeHintMatch]] = { ], ), ], + "entity": [ + ClassTypeHintMatch( + base_class="Entity", + matches=_ENTITY_MATCH, + ), + ClassTypeHintMatch( + base_class="RestoreEntity", + matches=_RESTORE_ENTITY_MATCH, + ), + ], "fan": [ ClassTypeHintMatch( base_class="Entity", From 51aea58c7ac441a3d4c84935ca4a2be4d9d5e23c Mon Sep 17 00:00:00 2001 From: Marc Mueller <30130371+cdce8p@users.noreply.github.com> Date: Mon, 17 Feb 2025 14:46:33 +0100 Subject: [PATCH 33/52] Update mypy-dev to 1.16.0a3 (#138655) --- requirements_test.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements_test.txt b/requirements_test.txt index 2731114043b..0a7a3bb18e5 100644 --- a/requirements_test.txt +++ b/requirements_test.txt @@ -12,7 +12,7 @@ coverage==7.6.10 freezegun==1.5.1 license-expression==30.4.1 mock-open==1.4.0 -mypy-dev==1.16.0a2 +mypy-dev==1.16.0a3 pre-commit==4.0.0 pydantic==2.10.6 pylint==3.3.4 From 4cdc3de94a491fdf7fb98667666e3656b66806e5 Mon Sep 17 00:00:00 2001 From: Erik Montnemery Date: Mon, 17 Feb 2025 15:38:28 +0100 Subject: [PATCH 34/52] Correct backup filename on delete or download of cloud backup (#138704) * Correct backup filename on delete or download of cloud backup * Improve tests * Address review comments --- homeassistant/components/cloud/backup.py | 43 +++++++++++------ tests/components/cloud/test_backup.py | 61 +++++++++++++++++++++--- 2 files changed, 83 insertions(+), 21 deletions(-) diff --git a/homeassistant/components/cloud/backup.py b/homeassistant/components/cloud/backup.py index 61edeccdd9c..b31fe16fbe9 100644 --- a/homeassistant/components/cloud/backup.py +++ b/homeassistant/components/cloud/backup.py @@ -11,7 +11,11 @@ from typing import Any from aiohttp import ClientError from hass_nabucasa import Cloud, CloudError from hass_nabucasa.api import CloudApiNonRetryableError -from hass_nabucasa.cloud_api import async_files_delete_file, async_files_list +from hass_nabucasa.cloud_api import ( + FilesHandlerListEntry, + async_files_delete_file, + async_files_list, +) from hass_nabucasa.files import FilesError, StorageType, calculate_b64md5 from homeassistant.components.backup import AgentBackup, BackupAgent, BackupAgentError @@ -76,11 +80,6 @@ class CloudBackupAgent(BackupAgent): self._cloud = cloud self._hass = hass - @callback - def _get_backup_filename(self) -> str: - """Return the backup filename.""" - return f"{self._cloud.client.prefs.instance_id}.tar" - async def async_download_backup( self, backup_id: str, @@ -91,13 +90,13 @@ class CloudBackupAgent(BackupAgent): :param backup_id: The ID of the backup that was returned in async_list_backups. :return: An async iterator that yields bytes. """ - if not await self.async_get_backup(backup_id): + if not (backup := await self._async_get_backup(backup_id)): raise BackupAgentError("Backup not found") try: content = await self._cloud.files.download( storage_type=StorageType.BACKUP, - filename=self._get_backup_filename(), + filename=backup["Key"], ) except CloudError as err: raise BackupAgentError(f"Failed to download backup: {err}") from err @@ -124,7 +123,7 @@ class CloudBackupAgent(BackupAgent): base64md5hash = await calculate_b64md5(open_stream, size) except FilesError as err: raise BackupAgentError(err) from err - filename = self._get_backup_filename() + filename = f"{self._cloud.client.prefs.instance_id}.tar" metadata = backup.as_dict() tries = 1 @@ -172,29 +171,34 @@ class CloudBackupAgent(BackupAgent): :param backup_id: The ID of the backup that was returned in async_list_backups. """ - if not await self.async_get_backup(backup_id): + if not (backup := await self._async_get_backup(backup_id)): return try: await async_files_delete_file( self._cloud, storage_type=StorageType.BACKUP, - filename=self._get_backup_filename(), + filename=backup["Key"], ) except (ClientError, CloudError) as err: raise BackupAgentError("Failed to delete backup") from err async def async_list_backups(self, **kwargs: Any) -> list[AgentBackup]: + """List backups.""" + backups = await self._async_list_backups() + return [AgentBackup.from_dict(backup["Metadata"]) for backup in backups] + + async def _async_list_backups(self) -> list[FilesHandlerListEntry]: """List backups.""" try: backups = await async_files_list( self._cloud, storage_type=StorageType.BACKUP ) - _LOGGER.debug("Cloud backups: %s", backups) except (ClientError, CloudError) as err: raise BackupAgentError("Failed to list backups") from err - return [AgentBackup.from_dict(backup["Metadata"]) for backup in backups] + _LOGGER.debug("Cloud backups: %s", backups) + return backups async def async_get_backup( self, @@ -202,10 +206,19 @@ class CloudBackupAgent(BackupAgent): **kwargs: Any, ) -> AgentBackup | None: """Return a backup.""" - backups = await self.async_list_backups() + if not (backup := await self._async_get_backup(backup_id)): + return None + return AgentBackup.from_dict(backup["Metadata"]) + + async def _async_get_backup( + self, + backup_id: str, + ) -> FilesHandlerListEntry | None: + """Return a backup.""" + backups = await self._async_list_backups() for backup in backups: - if backup.backup_id == backup_id: + if backup["Metadata"]["backup_id"] == backup_id: return backup return None diff --git a/tests/components/cloud/test_backup.py b/tests/components/cloud/test_backup.py index c6bb0bdad54..18793cc00bb 100644 --- a/tests/components/cloud/test_backup.py +++ b/tests/components/cloud/test_backup.py @@ -3,12 +3,12 @@ from collections.abc import AsyncGenerator, Generator from io import StringIO from typing import Any -from unittest.mock import Mock, PropertyMock, patch +from unittest.mock import ANY, Mock, PropertyMock, patch from aiohttp import ClientError from hass_nabucasa import CloudError from hass_nabucasa.api import CloudApiNonRetryableError -from hass_nabucasa.files import FilesError +from hass_nabucasa.files import FilesError, StorageType import pytest from homeassistant.components.backup import ( @@ -90,7 +90,26 @@ def mock_list_files() -> Generator[MagicMock]: "size": 34519040, "storage-type": "backup", }, - } + }, + { + "Key": "462e16810d6841228828d9dd2f9e341f.tar", + "LastModified": "2024-11-22T10:49:01.182Z", + "Size": 34519040, + "Metadata": { + "addons": [], + "backup_id": "23e64aed", + "date": "2024-11-22T11:48:48.727189+01:00", + "database_included": True, + "extra_metadata": {}, + "folders": [], + "homeassistant_included": True, + "homeassistant_version": "2024.12.0.dev0", + "name": "Core 2024.12.0.dev0", + "protected": False, + "size": 34519040, + "storage-type": "backup", + }, + }, ] yield list_files @@ -148,7 +167,21 @@ async def test_agents_list_backups( "name": "Core 2024.12.0.dev0", "failed_agent_ids": [], "with_automatic_settings": None, - } + }, + { + "addons": [], + "agents": {"cloud.cloud": {"protected": False, "size": 34519040}}, + "backup_id": "23e64aed", + "date": "2024-11-22T11:48:48.727189+01:00", + "database_included": True, + "extra_metadata": {}, + "folders": [], + "homeassistant_included": True, + "homeassistant_version": "2024.12.0.dev0", + "name": "Core 2024.12.0.dev0", + "failed_agent_ids": [], + "with_automatic_settings": None, + }, ] @@ -242,6 +275,10 @@ async def test_agents_download( resp = await client.get(f"/api/backup/download/{backup_id}?agent_id=cloud.cloud") assert resp.status == 200 assert await resp.content.read() == b"backup data" + cloud.files.download.assert_called_once_with( + filename="462e16810d6841228828d9dd2f9e341e.tar", + storage_type=StorageType.BACKUP, + ) @pytest.mark.usefixtures("cloud_logged_in", "mock_list_files") @@ -317,7 +354,14 @@ async def test_agents_upload( data={"file": StringIO(backup_data)}, ) - assert len(cloud.files.upload.mock_calls) == 1 + cloud.files.upload.assert_called_once_with( + storage_type=StorageType.BACKUP, + open_stream=ANY, + filename=f"{cloud.client.prefs.instance_id}.tar", + base64md5hash=ANY, + metadata=ANY, + size=ANY, + ) metadata = cloud.files.upload.mock_calls[-1].kwargs["metadata"] assert metadata["backup_id"] == backup_id @@ -552,6 +596,7 @@ async def test_agents_upload_wrong_size( async def test_agents_delete( hass: HomeAssistant, hass_ws_client: WebSocketGenerator, + cloud: Mock, mock_delete_file: Mock, ) -> None: """Test agent delete backup.""" @@ -568,7 +613,11 @@ async def test_agents_delete( assert response["success"] assert response["result"] == {"agent_errors": {}} - mock_delete_file.assert_called_once() + mock_delete_file.assert_called_once_with( + cloud, + filename="462e16810d6841228828d9dd2f9e341e.tar", + storage_type=StorageType.BACKUP, + ) @pytest.mark.parametrize("side_effect", [ClientError, CloudError]) From 9422c4de65aafc693440af1f4b8f41fbd7d17744 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ab=C3=ADlio=20Costa?= Date: Mon, 17 Feb 2025 15:01:03 +0000 Subject: [PATCH 35/52] Fix snapshots timezone in Cloud tests (#138393) * Fix snapshots timezone in Cloud tests * Add explanation comment --- tests/components/cloud/test_http_api.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/components/cloud/test_http_api.py b/tests/components/cloud/test_http_api.py index c8852b911e9..ef4b93a8aab 100644 --- a/tests/components/cloud/test_http_api.py +++ b/tests/components/cloud/test_http_api.py @@ -1943,7 +1943,10 @@ async def test_download_support_package( ) now = dt_util.utcnow() - freezer.move_to(datetime.datetime.fromisoformat("2025-02-10T12:00:00.0+00:00")) + # The logging is done with local time according to the system timezone. Set the + # fake time to 12:00 local time + tz = now.astimezone().tzinfo + freezer.move_to(datetime.datetime(2025, 2, 10, 12, 0, 0, tzinfo=tz)) logging.getLogger("hass_nabucasa.iot").info( "This message will be dropped since this test patches MAX_RECORDS" ) From 82f2e72327c7baa5cf6b700baeef93015d096def Mon Sep 17 00:00:00 2001 From: Jonas Fors Lellky Date: Mon, 17 Feb 2025 16:18:46 +0100 Subject: [PATCH 36/52] Add translations for exceptions (#138669) * Add translations for exceptions * Review comment * Add translation for exception in the coordinator * Use same translation string for switch exceptions --- .../components/flexit_bacnet/climate.py | 17 +++++++++++++-- .../components/flexit_bacnet/coordinator.py | 6 +++++- .../components/flexit_bacnet/number.py | 9 +++++++- .../flexit_bacnet/quality_scale.yaml | 2 +- .../components/flexit_bacnet/strings.json | 17 +++++++++++++++ .../components/flexit_bacnet/switch.py | 21 +++++++++++++++---- 6 files changed, 63 insertions(+), 9 deletions(-) diff --git a/homeassistant/components/flexit_bacnet/climate.py b/homeassistant/components/flexit_bacnet/climate.py index b9ae16739b9..7dc855e3106 100644 --- a/homeassistant/components/flexit_bacnet/climate.py +++ b/homeassistant/components/flexit_bacnet/climate.py @@ -25,6 +25,7 @@ from homeassistant.exceptions import HomeAssistantError from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback from .const import ( + DOMAIN, MAX_TEMP, MIN_TEMP, PRESET_TO_VENTILATION_MODE_MAP, @@ -133,7 +134,13 @@ class FlexitClimateEntity(FlexitEntity, ClimateEntity): try: await self.device.set_ventilation_mode(ventilation_mode) except (asyncio.exceptions.TimeoutError, ConnectionError, DecodingError) as exc: - raise HomeAssistantError from exc + raise HomeAssistantError( + translation_domain=DOMAIN, + translation_key="set_preset_mode", + translation_placeholders={ + "preset": str(ventilation_mode), + }, + ) from exc finally: await self.coordinator.async_refresh() @@ -153,6 +160,12 @@ class FlexitClimateEntity(FlexitEntity, ClimateEntity): else: await self.device.set_ventilation_mode(VENTILATION_MODE_HOME) except (asyncio.exceptions.TimeoutError, ConnectionError, DecodingError) as exc: - raise HomeAssistantError from exc + raise HomeAssistantError( + translation_domain=DOMAIN, + translation_key="set_hvac_mode", + translation_placeholders={ + "mode": str(hvac_mode), + }, + ) from exc finally: await self.coordinator.async_refresh() diff --git a/homeassistant/components/flexit_bacnet/coordinator.py b/homeassistant/components/flexit_bacnet/coordinator.py index da9415f2b87..9148ec87883 100644 --- a/homeassistant/components/flexit_bacnet/coordinator.py +++ b/homeassistant/components/flexit_bacnet/coordinator.py @@ -49,7 +49,11 @@ class FlexitCoordinator(DataUpdateCoordinator[FlexitBACnet]): await self.device.update() except (asyncio.exceptions.TimeoutError, ConnectionError, DecodingError) as exc: raise ConfigEntryNotReady( - f"Timeout while connecting to {self.config_entry.data[CONF_IP_ADDRESS]}" + translation_domain=DOMAIN, + translation_key="not_ready", + translation_placeholders={ + "ip": str(self.config_entry.data[CONF_IP_ADDRESS]), + }, ) from exc return self.device diff --git a/homeassistant/components/flexit_bacnet/number.py b/homeassistant/components/flexit_bacnet/number.py index 061860e7d0d..b8c329bd1d4 100644 --- a/homeassistant/components/flexit_bacnet/number.py +++ b/homeassistant/components/flexit_bacnet/number.py @@ -18,6 +18,7 @@ from homeassistant.core import HomeAssistant from homeassistant.exceptions import HomeAssistantError from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback +from .const import DOMAIN from .coordinator import FlexitConfigEntry, FlexitCoordinator from .entity import FlexitEntity @@ -249,6 +250,12 @@ class FlexitNumber(FlexitEntity, NumberEntity): try: await set_native_value_fn(int(value)) except (asyncio.exceptions.TimeoutError, ConnectionError, DecodingError) as exc: - raise HomeAssistantError from exc + raise HomeAssistantError( + translation_domain=DOMAIN, + translation_key="set_value_error", + translation_placeholders={ + "value": str(value), + }, + ) from exc finally: await self.coordinator.async_refresh() diff --git a/homeassistant/components/flexit_bacnet/quality_scale.yaml b/homeassistant/components/flexit_bacnet/quality_scale.yaml index 548580f96d3..f59435bad0d 100644 --- a/homeassistant/components/flexit_bacnet/quality_scale.yaml +++ b/homeassistant/components/flexit_bacnet/quality_scale.yaml @@ -62,7 +62,7 @@ rules: comment: | Device type integration. diagnostics: todo - exception-translations: todo + exception-translations: done icon-translations: done reconfiguration-flow: todo dynamic-devices: diff --git a/homeassistant/components/flexit_bacnet/strings.json b/homeassistant/components/flexit_bacnet/strings.json index 488d93fbd61..e9acbd46a37 100644 --- a/homeassistant/components/flexit_bacnet/strings.json +++ b/homeassistant/components/flexit_bacnet/strings.json @@ -119,5 +119,22 @@ "name": "Cooker hood mode" } } + }, + "exceptions": { + "set_value_error": { + "message": "Failed setting the value {value}." + }, + "switch_turn": { + "message": "Failed to turn the switch {state}." + }, + "set_preset_mode": { + "message": "Failed to set preset mode {preset}." + }, + "set_hvac_mode": { + "message": "Failed to set HVAC mode {mode}." + }, + "not_ready": { + "message": "Timeout while connecting to {ip}." + } } } diff --git a/homeassistant/components/flexit_bacnet/switch.py b/homeassistant/components/flexit_bacnet/switch.py index ac69bb86023..bdeff006181 100644 --- a/homeassistant/components/flexit_bacnet/switch.py +++ b/homeassistant/components/flexit_bacnet/switch.py @@ -17,6 +17,7 @@ from homeassistant.core import HomeAssistant from homeassistant.exceptions import HomeAssistantError from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback +from .const import DOMAIN from .coordinator import FlexitConfigEntry, FlexitCoordinator from .entity import FlexitEntity @@ -97,19 +98,31 @@ class FlexitSwitch(FlexitEntity, SwitchEntity): return self.entity_description.is_on_fn(self.coordinator.data) async def async_turn_on(self, **kwargs: Any) -> None: - """Turn electric heater on.""" + """Turn switch on.""" try: await self.entity_description.turn_on_fn(self.coordinator.data) except (asyncio.exceptions.TimeoutError, ConnectionError, DecodingError) as exc: - raise HomeAssistantError from exc + raise HomeAssistantError( + translation_domain=DOMAIN, + translation_key="switch_turn", + translation_placeholders={ + "state": "on", + }, + ) from exc finally: await self.coordinator.async_refresh() async def async_turn_off(self, **kwargs: Any) -> None: - """Turn electric heater off.""" + """Turn switch off.""" try: await self.entity_description.turn_off_fn(self.coordinator.data) except (asyncio.exceptions.TimeoutError, ConnectionError, DecodingError) as exc: - raise HomeAssistantError from exc + raise HomeAssistantError( + translation_domain=DOMAIN, + translation_key="switch_turn", + translation_placeholders={ + "state": "off", + }, + ) from exc finally: await self.coordinator.async_refresh() From 34a33e0465e6d34d9f831857bd32135bb0af15a5 Mon Sep 17 00:00:00 2001 From: Andrew Sayre <6730289+andrewsayre@users.noreply.github.com> Date: Mon, 17 Feb 2025 09:28:55 -0600 Subject: [PATCH 37/52] Create HEOS devices after integration setup (#138721) * Create entities for new players * Fix docstring typo --- homeassistant/components/heos/coordinator.py | 30 ++++++-- homeassistant/components/heos/media_player.py | 17 +++-- .../components/heos/quality_scale.yaml | 2 +- tests/components/heos/conftest.py | 62 ++++++++------- tests/components/heos/test_init.py | 75 ++++++++++++++++++- 5 files changed, 147 insertions(+), 39 deletions(-) diff --git a/homeassistant/components/heos/coordinator.py b/homeassistant/components/heos/coordinator.py index 94aa4ad0ab5..0303d150794 100644 --- a/homeassistant/components/heos/coordinator.py +++ b/homeassistant/components/heos/coordinator.py @@ -16,6 +16,7 @@ from pyheos import ( HeosError, HeosNowPlayingMedia, HeosOptions, + HeosPlayer, MediaItem, MediaType, PlayerUpdateResult, @@ -58,6 +59,7 @@ class HeosCoordinator(DataUpdateCoordinator[None]): credentials=credentials, ) ) + self._platform_callbacks: list[Callable[[Sequence[HeosPlayer]], None]] = [] self._update_sources_pending: bool = False self._source_list: list[str] = [] self._favorites: dict[int, MediaItem] = {} @@ -124,6 +126,27 @@ class HeosCoordinator(DataUpdateCoordinator[None]): self.async_update_listeners() return remove_listener + def async_add_platform_callback( + self, add_entities_callback: Callable[[Sequence[HeosPlayer]], None] + ) -> None: + """Add a callback to add entities for a platform.""" + self._platform_callbacks.append(add_entities_callback) + + def _async_handle_player_update_result( + self, update_result: PlayerUpdateResult + ) -> None: + """Handle a player update result.""" + if update_result.added_player_ids and self._platform_callbacks: + new_players = [ + self.heos.players[player_id] + for player_id in update_result.added_player_ids + ] + for add_entities_callback in self._platform_callbacks: + add_entities_callback(new_players) + + if update_result.updated_player_ids: + self._async_update_player_ids(update_result.updated_player_ids) + async def _async_on_auth_failure(self) -> None: """Handle when the user credentials are no longer valid.""" assert self.config_entry is not None @@ -147,8 +170,7 @@ class HeosCoordinator(DataUpdateCoordinator[None]): """Handle a controller event, such as players or groups changed.""" if event == const.EVENT_PLAYERS_CHANGED: assert data is not None - if data.updated_player_ids: - self._async_update_player_ids(data.updated_player_ids) + self._async_handle_player_update_result(data) elif ( event in (const.EVENT_SOURCES_CHANGED, const.EVENT_USER_CHANGED) and not self._update_sources_pending @@ -242,9 +264,7 @@ class HeosCoordinator(DataUpdateCoordinator[None]): except HeosError as error: _LOGGER.error("Unable to refresh players: %s", error) return - # After reconnecting, player_id may have changed - if player_updates.updated_player_ids: - self._async_update_player_ids(player_updates.updated_player_ids) + self._async_handle_player_update_result(player_updates) @callback def async_get_source_list(self) -> list[str]: diff --git a/homeassistant/components/heos/media_player.py b/homeassistant/components/heos/media_player.py index 4dbaead67a7..b9aa05810e5 100644 --- a/homeassistant/components/heos/media_player.py +++ b/homeassistant/components/heos/media_player.py @@ -2,7 +2,7 @@ from __future__ import annotations -from collections.abc import Awaitable, Callable, Coroutine +from collections.abc import Awaitable, Callable, Coroutine, Sequence from datetime import datetime from functools import reduce, wraps from operator import ior @@ -93,11 +93,16 @@ async def async_setup_entry( async_add_entities: AddConfigEntryEntitiesCallback, ) -> None: """Add media players for a config entry.""" - devices = [ - HeosMediaPlayer(entry.runtime_data, player) - for player in entry.runtime_data.heos.players.values() - ] - async_add_entities(devices) + + def add_entities_callback(players: Sequence[HeosPlayer]) -> None: + """Add entities for each player.""" + async_add_entities( + [HeosMediaPlayer(entry.runtime_data, player) for player in players] + ) + + coordinator = entry.runtime_data + coordinator.async_add_platform_callback(add_entities_callback) + add_entities_callback(list(coordinator.heos.players.values())) type _FuncType[**_P] = Callable[_P, Awaitable[Any]] diff --git a/homeassistant/components/heos/quality_scale.yaml b/homeassistant/components/heos/quality_scale.yaml index a1220366fa3..a08e2dca544 100644 --- a/homeassistant/components/heos/quality_scale.yaml +++ b/homeassistant/components/heos/quality_scale.yaml @@ -49,7 +49,7 @@ rules: docs-supported-functions: done docs-troubleshooting: done docs-use-cases: done - dynamic-devices: todo + dynamic-devices: done entity-category: done entity-device-class: done entity-disabled-by-default: done diff --git a/tests/components/heos/conftest.py b/tests/components/heos/conftest.py index 39937a8355f..7bed05a0289 100644 --- a/tests/components/heos/conftest.py +++ b/tests/components/heos/conftest.py @@ -2,7 +2,7 @@ from __future__ import annotations -from collections.abc import Iterator +from collections.abc import Callable, Iterator from unittest.mock import Mock, patch from pyheos import ( @@ -130,16 +130,17 @@ def system_info_fixture() -> HeosSystem: ) -@pytest.fixture(name="players") -def players_fixture() -> dict[int, HeosPlayer]: - """Create two mock HeosPlayers.""" - players = {} - for i in (1, 2): - player = HeosPlayer( - player_id=i, +@pytest.fixture(name="player_factory") +def player_factory_fixture() -> Callable[[int, str, str], HeosPlayer]: + """Return a method that creates players.""" + + def factory(player_id: int, name: str, model: str) -> HeosPlayer: + """Create a player.""" + return HeosPlayer( + player_id=player_id, group_id=999, - name="Test Player" if i == 1 else f"Test Player {i}", - model="HEOS Drive HS2" if i == 1 else "Speaker", + name=name, + model=model, serial="123456", version="1.0.0", supported_version=True, @@ -147,26 +148,37 @@ def players_fixture() -> dict[int, HeosPlayer]: is_muted=False, available=True, state=PlayState.STOP, - ip_address=f"127.0.0.{i}", + ip_address=f"127.0.0.{player_id}", network=NetworkType.WIRED, shuffle=False, repeat=RepeatType.OFF, volume=25, + now_playing_media=HeosNowPlayingMedia( + type=MediaType.STATION, + song="Song", + station="Station Name", + album="Album", + artist="Artist", + image_url="http://", + album_id="1", + media_id="1", + queue_id=1, + source_id=10, + ), ) - player.now_playing_media = HeosNowPlayingMedia( - type=MediaType.STATION, - song="Song", - station="Station Name", - album="Album", - artist="Artist", - image_url="http://", - album_id="1", - media_id="1", - queue_id=1, - source_id=10, - ) - players[player.player_id] = player - return players + + return factory + + +@pytest.fixture(name="players") +def players_fixture( + player_factory: Callable[[int, str, str], HeosPlayer], +) -> dict[int, HeosPlayer]: + """Create two mock HeosPlayers.""" + return { + 1: player_factory(1, "Test Player", "HEOS Drive HS2"), + 2: player_factory(2, "Test Player 2", "Speaker"), + } @pytest.fixture(name="group") diff --git a/tests/components/heos/test_init.py b/tests/components/heos/test_init.py index 60bc2a72e51..87cc8dd7dde 100644 --- a/tests/components/heos/test_init.py +++ b/tests/components/heos/test_init.py @@ -1,16 +1,26 @@ """Tests for the init module.""" +from collections.abc import Callable from typing import cast from unittest.mock import Mock -from pyheos import HeosError, HeosOptions, SignalHeosEvent, SignalType +from pyheos import ( + HeosError, + HeosOptions, + HeosPlayer, + PlayerUpdateResult, + SignalHeosEvent, + SignalType, + const, +) import pytest from homeassistant.components.heos.const import DOMAIN +from homeassistant.components.media_player import DOMAIN as MEDIA_PLAYER_DOMAIN from homeassistant.config_entries import SOURCE_REAUTH, ConfigEntryState from homeassistant.const import CONF_HOST, CONF_PASSWORD, CONF_USERNAME from homeassistant.core import HomeAssistant -from homeassistant.helpers import device_registry as dr +from homeassistant.helpers import device_registry as dr, entity_registry as er from homeassistant.setup import async_setup_component from . import MockHeos @@ -255,3 +265,64 @@ async def test_remove_config_entry_device( ws_client = await hass_ws_client(hass) response = await ws_client.remove_device(device_entry.id, config_entry.entry_id) assert response["success"] == expected_result + + +async def test_reconnected_new_entities_created( + hass: HomeAssistant, + entity_registry: er.EntityRegistry, + config_entry: MockConfigEntry, + controller: MockHeos, + player_factory: Callable[[int, str, str], HeosPlayer], +) -> None: + """Test new entities are created for new players after reconnecting.""" + config_entry.add_to_hass(hass) + assert await hass.config_entries.async_setup(config_entry.entry_id) + + # Assert initial entity doesn't exist + assert not entity_registry.async_get_entity_id(MEDIA_PLAYER_DOMAIN, DOMAIN, "3") + + # Create player + players = controller.players.copy() + players[3] = player_factory(3, "Test Player 3", "HEOS Link") + controller.mock_set_players(players) + controller.load_players.return_value = PlayerUpdateResult([3], [], {}) + + # Simulate reconnection + await controller.dispatcher.wait_send( + SignalType.HEOS_EVENT, SignalHeosEvent.CONNECTED + ) + await hass.async_block_till_done() + + # Assert new entity created + assert entity_registry.async_get_entity_id(MEDIA_PLAYER_DOMAIN, DOMAIN, "3") + + +async def test_players_changed_new_entities_created( + hass: HomeAssistant, + entity_registry: er.EntityRegistry, + config_entry: MockConfigEntry, + controller: MockHeos, + player_factory: Callable[[int, str, str], HeosPlayer], +) -> None: + """Test new entities are created for new players on change event.""" + config_entry.add_to_hass(hass) + assert await hass.config_entries.async_setup(config_entry.entry_id) + + # Assert initial entity doesn't exist + assert not entity_registry.async_get_entity_id(MEDIA_PLAYER_DOMAIN, DOMAIN, "3") + + # Create player + players = controller.players.copy() + players[3] = player_factory(3, "Test Player 3", "HEOS Link") + controller.mock_set_players(players) + + # Simulate players changed event + await controller.dispatcher.wait_send( + SignalType.CONTROLLER_EVENT, + const.EVENT_PLAYERS_CHANGED, + PlayerUpdateResult([3], [], {}), + ) + await hass.async_block_till_done() + + # Assert new entity created + assert entity_registry.async_get_entity_id(MEDIA_PLAYER_DOMAIN, DOMAIN, "3") From 67fcbc4c286a12a8040e77967a96b57f1386fbb5 Mon Sep 17 00:00:00 2001 From: Daniel O'Connor Date: Tue, 18 Feb 2025 01:59:28 +1030 Subject: [PATCH 38/52] Add LV-RH131S-WM Air Purifier (#138626) * Add LV-RH131S-WM Air Purifier Fix 138486 * Update homeassistant/components/vesync/const.py --- homeassistant/components/vesync/const.py | 1 + 1 file changed, 1 insertion(+) diff --git a/homeassistant/components/vesync/const.py b/homeassistant/components/vesync/const.py index 897c8d2b745..2e51b96451c 100644 --- a/homeassistant/components/vesync/const.py +++ b/homeassistant/components/vesync/const.py @@ -63,6 +63,7 @@ SKU_TO_BASE_DEVICE = { # Air Purifiers "LV-PUR131S": "LV-PUR131S", "LV-RH131S": "LV-PUR131S", # Alt ID Model LV-PUR131S + "LV-RH131S-WM": "LV-PUR131S", # Alt ID Model LV-PUR131S "Core200S": "Core200S", "LAP-C201S-AUSR": "Core200S", # Alt ID Model Core200S "LAP-C202S-WUSR": "Core200S", # Alt ID Model Core200S From 25296e1b8f98c8ef201f2af5d755d8a9bd010e5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ab=C3=ADlio=20Costa?= Date: Mon, 17 Feb 2025 16:12:55 +0000 Subject: [PATCH 39/52] Move ZHA debug logs handling out of event loop (#138568) --- homeassistant/components/zha/helpers.py | 31 +++++++++++++++++++------ 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/homeassistant/components/zha/helpers.py b/homeassistant/components/zha/helpers.py index c31627d3dc3..700e2833705 100644 --- a/homeassistant/components/zha/helpers.py +++ b/homeassistant/components/zha/helpers.py @@ -11,6 +11,7 @@ import enum import functools import itertools import logging +import queue import re import time from types import MappingProxyType @@ -111,9 +112,10 @@ from homeassistant.helpers import ( device_registry as dr, entity_registry as er, ) -from homeassistant.helpers.dispatcher import async_dispatcher_send +from homeassistant.helpers.dispatcher import async_dispatcher_send, dispatcher_send from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.typing import ConfigType +from homeassistant.util.logging import HomeAssistantQueueHandler from .const import ( ATTR_ACTIVE_COORDINATOR, @@ -505,7 +507,14 @@ class ZHAGatewayProxy(EventBase): DEBUG_LEVEL_CURRENT: async_capture_log_levels(), } self.debug_enabled: bool = False - self._log_relay_handler: LogRelayHandler = LogRelayHandler(hass, self) + + log_relay_handler: LogRelayHandler = LogRelayHandler(hass, self) + log_simple_queue: queue.SimpleQueue[logging.Handler] = queue.SimpleQueue() + self._log_queue_handler = HomeAssistantQueueHandler(log_simple_queue) + self._log_queue_handler.listener = logging.handlers.QueueListener( + log_simple_queue, log_relay_handler + ) + self._unsubs: list[Callable[[], None]] = [] self._unsubs.append(self.gateway.on_all_events(self._handle_event_protocol)) self._reload_task: asyncio.Task | None = None @@ -736,10 +745,13 @@ class ZHAGatewayProxy(EventBase): self._log_levels[DEBUG_LEVEL_CURRENT] = async_capture_log_levels() if filterer: - self._log_relay_handler.addFilter(filterer) + self._log_queue_handler.addFilter(filterer) + + if self._log_queue_handler.listener: + self._log_queue_handler.listener.start() for logger_name in DEBUG_RELAY_LOGGERS: - logging.getLogger(logger_name).addHandler(self._log_relay_handler) + logging.getLogger(logger_name).addHandler(self._log_queue_handler) self.debug_enabled = True @@ -749,9 +761,14 @@ class ZHAGatewayProxy(EventBase): async_set_logger_levels(self._log_levels[DEBUG_LEVEL_ORIGINAL]) self._log_levels[DEBUG_LEVEL_CURRENT] = async_capture_log_levels() for logger_name in DEBUG_RELAY_LOGGERS: - logging.getLogger(logger_name).removeHandler(self._log_relay_handler) + logging.getLogger(logger_name).removeHandler(self._log_queue_handler) + + if self._log_queue_handler.listener: + self._log_queue_handler.listener.stop() + if filterer: - self._log_relay_handler.removeFilter(filterer) + self._log_queue_handler.removeFilter(filterer) + self.debug_enabled = False async def shutdown(self) -> None: @@ -978,7 +995,7 @@ class LogRelayHandler(logging.Handler): entry = LogEntry( record, self.paths_re, figure_out_source=record.levelno >= logging.WARNING ) - async_dispatcher_send( + dispatcher_send( self.hass, ZHA_GW_MSG, {ATTR_TYPE: ZHA_GW_MSG_LOG_OUTPUT, ZHA_GW_MSG_LOG_ENTRY: entry.to_dict()}, From 04b826daa12bb367d978330d1a0f3f5bc338f40e Mon Sep 17 00:00:00 2001 From: LG-ThinQ-Integration Date: Tue, 18 Feb 2025 01:30:41 +0900 Subject: [PATCH 40/52] Add sensors for washer and system boiler in LG ThinQ (#137514) Co-authored-by: yunseon.park --- homeassistant/components/lg_thinq/icons.json | 6 +++++ homeassistant/components/lg_thinq/sensor.py | 27 +++++++++++++++++++ .../components/lg_thinq/strings.json | 15 +++++++++++ 3 files changed, 48 insertions(+) diff --git a/homeassistant/components/lg_thinq/icons.json b/homeassistant/components/lg_thinq/icons.json index 42ae5746f24..db33106da79 100644 --- a/homeassistant/components/lg_thinq/icons.json +++ b/homeassistant/components/lg_thinq/icons.json @@ -407,6 +407,12 @@ }, "power_level_for_location": { "default": "mdi:radiator" + }, + "cycle_count": { + "default": "mdi:counter" + }, + "cycle_count_for_location": { + "default": "mdi:counter" } } } diff --git a/homeassistant/components/lg_thinq/sensor.py b/homeassistant/components/lg_thinq/sensor.py index bb190cccde9..95198d931a1 100644 --- a/homeassistant/components/lg_thinq/sensor.py +++ b/homeassistant/components/lg_thinq/sensor.py @@ -248,6 +248,24 @@ TEMPERATURE_SENSOR_DESC: dict[ThinQProperty, SensorEntityDescription] = { state_class=SensorStateClass.MEASUREMENT, translation_key=ThinQProperty.CURRENT_TEMPERATURE, ), + ThinQPropertyEx.ROOM_AIR_CURRENT_TEMPERATURE: SensorEntityDescription( + key=ThinQPropertyEx.ROOM_AIR_CURRENT_TEMPERATURE, + device_class=SensorDeviceClass.TEMPERATURE, + state_class=SensorStateClass.MEASUREMENT, + translation_key=ThinQPropertyEx.ROOM_AIR_CURRENT_TEMPERATURE, + ), + ThinQPropertyEx.ROOM_IN_WATER_CURRENT_TEMPERATURE: SensorEntityDescription( + key=ThinQPropertyEx.ROOM_IN_WATER_CURRENT_TEMPERATURE, + device_class=SensorDeviceClass.TEMPERATURE, + state_class=SensorStateClass.MEASUREMENT, + translation_key=ThinQPropertyEx.ROOM_IN_WATER_CURRENT_TEMPERATURE, + ), + ThinQPropertyEx.ROOM_OUT_WATER_CURRENT_TEMPERATURE: SensorEntityDescription( + key=ThinQPropertyEx.ROOM_OUT_WATER_CURRENT_TEMPERATURE, + device_class=SensorDeviceClass.TEMPERATURE, + state_class=SensorStateClass.MEASUREMENT, + translation_key=ThinQPropertyEx.ROOM_OUT_WATER_CURRENT_TEMPERATURE, + ), } WATER_FILTER_INFO_SENSOR_DESC: dict[ThinQProperty, SensorEntityDescription] = { ThinQProperty.USED_TIME: SensorEntityDescription( @@ -341,6 +359,10 @@ TIMER_SENSOR_DESC: dict[ThinQProperty, SensorEntityDescription] = { } WASHER_SENSORS: tuple[SensorEntityDescription, ...] = ( + SensorEntityDescription( + key=ThinQProperty.CYCLE_COUNT, + translation_key=ThinQProperty.CYCLE_COUNT, + ), RUN_STATE_SENSOR_DESC[ThinQProperty.CURRENT_STATE], TIMER_SENSOR_DESC[TimerProperty.TOTAL], TIMER_SENSOR_DESC[TimerProperty.RELATIVE_TO_START_WM], @@ -470,6 +492,11 @@ DEVICE_TYPE_SENSOR_MAP: dict[DeviceType, tuple[SensorEntityDescription, ...]] = RUN_STATE_SENSOR_DESC[ThinQProperty.CURRENT_STATE], ), DeviceType.STYLER: WASHER_SENSORS, + DeviceType.SYSTEM_BOILER: ( + TEMPERATURE_SENSOR_DESC[ThinQPropertyEx.ROOM_AIR_CURRENT_TEMPERATURE], + TEMPERATURE_SENSOR_DESC[ThinQPropertyEx.ROOM_IN_WATER_CURRENT_TEMPERATURE], + TEMPERATURE_SENSOR_DESC[ThinQPropertyEx.ROOM_OUT_WATER_CURRENT_TEMPERATURE], + ), DeviceType.WASHCOMBO_MAIN: WASHER_SENSORS, DeviceType.WASHCOMBO_MINI: WASHER_SENSORS, DeviceType.WASHER: WASHER_SENSORS, diff --git a/homeassistant/components/lg_thinq/strings.json b/homeassistant/components/lg_thinq/strings.json index dee2d21e05a..359ac40e1f1 100644 --- a/homeassistant/components/lg_thinq/strings.json +++ b/homeassistant/components/lg_thinq/strings.json @@ -305,6 +305,15 @@ "current_temperature": { "name": "Current temperature" }, + "room_air_current_temperature": { + "name": "Indoor temperature" + }, + "room_in_water_current_temperature": { + "name": "Inlet temperature" + }, + "room_out_water_current_temperature": { + "name": "Outlet temperature" + }, "temperature": { "name": "Temperature" }, @@ -848,6 +857,12 @@ }, "power_level_for_location": { "name": "{location} power level" + }, + "cycle_count": { + "name": "Cycles" + }, + "cycle_count_for_location": { + "name": "{location} cycles" } }, "select": { From ff16e587e8aeb1afc9ebe15a738001657eaabe71 Mon Sep 17 00:00:00 2001 From: Joost Lekkerkerker Date: Mon, 17 Feb 2025 17:45:26 +0100 Subject: [PATCH 41/52] Bump airgradient to 0.9.2 (#138725) * Bump airgradient to 0.9.2 * Bump airgradient to 0.9.2 --- homeassistant/components/airgradient/manifest.json | 2 +- requirements_all.txt | 2 +- requirements_test_all.txt | 2 +- .../airgradient/snapshots/test_diagnostics.ambr | 6 +++--- .../components/airgradient/snapshots/test_sensor.ambr | 10 +++++----- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/homeassistant/components/airgradient/manifest.json b/homeassistant/components/airgradient/manifest.json index 13764142697..afaf2698ced 100644 --- a/homeassistant/components/airgradient/manifest.json +++ b/homeassistant/components/airgradient/manifest.json @@ -6,6 +6,6 @@ "documentation": "https://www.home-assistant.io/integrations/airgradient", "integration_type": "device", "iot_class": "local_polling", - "requirements": ["airgradient==0.9.1"], + "requirements": ["airgradient==0.9.2"], "zeroconf": ["_airgradient._tcp.local."] } diff --git a/requirements_all.txt b/requirements_all.txt index 9153674fdcc..9efa46334a6 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -431,7 +431,7 @@ aiowithings==3.1.5 aioymaps==1.2.5 # homeassistant.components.airgradient -airgradient==0.9.1 +airgradient==0.9.2 # homeassistant.components.airly airly==1.1.0 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index 164562a485b..0ced3ce92ab 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -413,7 +413,7 @@ aiowithings==3.1.5 aioymaps==1.2.5 # homeassistant.components.airgradient -airgradient==0.9.1 +airgradient==0.9.2 # homeassistant.components.airly airly==1.1.0 diff --git a/tests/components/airgradient/snapshots/test_diagnostics.ambr b/tests/components/airgradient/snapshots/test_diagnostics.ambr index a96dfb95382..624a6f76f8d 100644 --- a/tests/components/airgradient/snapshots/test_diagnostics.ambr +++ b/tests/components/airgradient/snapshots/test_diagnostics.ambr @@ -25,13 +25,13 @@ 'nitrogen_index': 1, 'pm003_count': 270, 'pm01': 22, - 'pm02': 34, + 'pm02': 34.0, 'pm10': 41, 'raw_ambient_temperature': 27.96, - 'raw_nitrogen': 16931, + 'raw_nitrogen': 16931.0, 'raw_pm02': 34, 'raw_relative_humidity': 48.0, - 'raw_total_volatile_organic_component': 31792, + 'raw_total_volatile_organic_component': 31792.0, 'rco2': 778, 'relative_humidity': 47.0, 'serial_number': '84fce612f5b8', diff --git a/tests/components/airgradient/snapshots/test_sensor.ambr b/tests/components/airgradient/snapshots/test_sensor.ambr index 38a6774b6db..374d9a60e4e 100644 --- a/tests/components/airgradient/snapshots/test_sensor.ambr +++ b/tests/components/airgradient/snapshots/test_sensor.ambr @@ -724,7 +724,7 @@ 'last_changed': , 'last_reported': , 'last_updated': , - 'state': '34', + 'state': '34.0', }) # --- # name: test_all_entities[indoor][sensor.airgradient_raw_nox-entry] @@ -775,7 +775,7 @@ 'last_changed': , 'last_reported': , 'last_updated': , - 'state': '16931', + 'state': '16931.0', }) # --- # name: test_all_entities[indoor][sensor.airgradient_raw_pm2_5-entry] @@ -878,7 +878,7 @@ 'last_changed': , 'last_reported': , 'last_updated': , - 'state': '31792', + 'state': '31792.0', }) # --- # name: test_all_entities[indoor][sensor.airgradient_signal_strength-entry] @@ -1280,7 +1280,7 @@ 'last_changed': , 'last_reported': , 'last_updated': , - 'state': '16359', + 'state': '16359.0', }) # --- # name: test_all_entities[outdoor][sensor.airgradient_raw_voc-entry] @@ -1331,7 +1331,7 @@ 'last_changed': , 'last_reported': , 'last_updated': , - 'state': '30802', + 'state': '30802.0', }) # --- # name: test_all_entities[outdoor][sensor.airgradient_signal_strength-entry] From e0795e6d07fd9a29d58d3a7233fe34a742429528 Mon Sep 17 00:00:00 2001 From: Erik Montnemery Date: Mon, 17 Feb 2025 18:16:57 +0100 Subject: [PATCH 42/52] Improve config entry state transitions when unloading and removing entries (#138522) * Improve config entry state transitions when unloading and removing entries * Update integrations which check for a single loaded entry * Update tests checking state after unload fails * Update homeassistant/config_entries.py Co-authored-by: Martin Hjelmare --------- Co-authored-by: Martin Hjelmare --- homeassistant/components/adguard/__init__.py | 9 ++------ .../google_assistant_sdk/__init__.py | 9 ++------ .../components/google_mail/__init__.py | 9 ++------ .../components/google_sheets/__init__.py | 9 ++------ homeassistant/components/guardian/__init__.py | 9 ++------ homeassistant/components/lookin/__init__.py | 9 ++------ .../components/motion_blinds/__init__.py | 9 ++------ .../components/netgear_lte/__init__.py | 8 +------ .../components/rainmachine/__init__.py | 9 ++------ .../components/simplisafe/__init__.py | 9 ++------ .../components/tplink_omada/__init__.py | 9 ++------ .../components/xiaomi_aqara/__init__.py | 9 ++------ homeassistant/config_entries.py | 23 +++++++++++++------ tests/components/matter/test_init.py | 2 +- tests/components/unifi/test_hub.py | 2 +- tests/components/zwave_js/test_init.py | 2 +- tests/test_config_entries.py | 8 +++---- 17 files changed, 46 insertions(+), 98 deletions(-) diff --git a/homeassistant/components/adguard/__init__.py b/homeassistant/components/adguard/__init__.py index f8ddeba6767..bbc763d7ec3 100644 --- a/homeassistant/components/adguard/__init__.py +++ b/homeassistant/components/adguard/__init__.py @@ -7,7 +7,7 @@ from dataclasses import dataclass from adguardhome import AdGuardHome, AdGuardHomeConnectionError import voluptuous as vol -from homeassistant.config_entries import ConfigEntry, ConfigEntryState +from homeassistant.config_entries import ConfigEntry from homeassistant.const import ( CONF_HOST, CONF_NAME, @@ -123,12 +123,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: AdGuardConfigEntry) -> b async def async_unload_entry(hass: HomeAssistant, entry: AdGuardConfigEntry) -> bool: """Unload AdGuard Home config entry.""" unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS) - loaded_entries = [ - entry - for entry in hass.config_entries.async_entries(DOMAIN) - if entry.state == ConfigEntryState.LOADED - ] - if len(loaded_entries) == 1: + if not hass.config_entries.async_loaded_entries(DOMAIN): # This is the last loaded instance of AdGuard, deregister any services hass.services.async_remove(DOMAIN, SERVICE_ADD_URL) hass.services.async_remove(DOMAIN, SERVICE_REMOVE_URL) diff --git a/homeassistant/components/google_assistant_sdk/__init__.py b/homeassistant/components/google_assistant_sdk/__init__.py index 4ea496f2824..a08d7554516 100644 --- a/homeassistant/components/google_assistant_sdk/__init__.py +++ b/homeassistant/components/google_assistant_sdk/__init__.py @@ -10,7 +10,7 @@ from google.oauth2.credentials import Credentials import voluptuous as vol from homeassistant.components import conversation -from homeassistant.config_entries import ConfigEntry, ConfigEntryState +from homeassistant.config_entries import ConfigEntry from homeassistant.const import CONF_ACCESS_TOKEN, CONF_NAME, Platform from homeassistant.core import ( HomeAssistant, @@ -99,12 +99,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: """Unload a config entry.""" hass.data[DOMAIN].pop(entry.entry_id) - loaded_entries = [ - entry - for entry in hass.config_entries.async_entries(DOMAIN) - if entry.state == ConfigEntryState.LOADED - ] - if len(loaded_entries) == 1: + if not hass.config_entries.async_loaded_entries(DOMAIN): for service_name in hass.services.async_services_for_domain(DOMAIN): hass.services.async_remove(DOMAIN, service_name) diff --git a/homeassistant/components/google_mail/__init__.py b/homeassistant/components/google_mail/__init__.py index 7fae5f18da5..8ef978568dc 100644 --- a/homeassistant/components/google_mail/__init__.py +++ b/homeassistant/components/google_mail/__init__.py @@ -2,7 +2,7 @@ from __future__ import annotations -from homeassistant.config_entries import ConfigEntry, ConfigEntryState +from homeassistant.config_entries import ConfigEntry from homeassistant.const import CONF_NAME, Platform from homeassistant.core import HomeAssistant from homeassistant.helpers import config_validation as cv, discovery @@ -59,12 +59,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: GoogleMailConfigEntry) - async def async_unload_entry(hass: HomeAssistant, entry: GoogleMailConfigEntry) -> bool: """Unload a config entry.""" - loaded_entries = [ - entry - for entry in hass.config_entries.async_entries(DOMAIN) - if entry.state == ConfigEntryState.LOADED - ] - if len(loaded_entries) == 1: + if not hass.config_entries.async_loaded_entries(DOMAIN): for service_name in hass.services.async_services_for_domain(DOMAIN): hass.services.async_remove(DOMAIN, service_name) diff --git a/homeassistant/components/google_sheets/__init__.py b/homeassistant/components/google_sheets/__init__.py index faf1ff1ee0b..afafce816a9 100644 --- a/homeassistant/components/google_sheets/__init__.py +++ b/homeassistant/components/google_sheets/__init__.py @@ -12,7 +12,7 @@ from gspread.exceptions import APIError from gspread.utils import ValueInputOption import voluptuous as vol -from homeassistant.config_entries import ConfigEntry, ConfigEntryState +from homeassistant.config_entries import ConfigEntry from homeassistant.const import CONF_ACCESS_TOKEN, CONF_TOKEN from homeassistant.core import HomeAssistant, ServiceCall from homeassistant.exceptions import ( @@ -81,12 +81,7 @@ async def async_unload_entry( hass: HomeAssistant, entry: GoogleSheetsConfigEntry ) -> bool: """Unload a config entry.""" - loaded_entries = [ - entry - for entry in hass.config_entries.async_entries(DOMAIN) - if entry.state == ConfigEntryState.LOADED - ] - if len(loaded_entries) == 1: + if not hass.config_entries.async_loaded_entries(DOMAIN): for service_name in hass.services.async_services_for_domain(DOMAIN): hass.services.async_remove(DOMAIN, service_name) diff --git a/homeassistant/components/guardian/__init__.py b/homeassistant/components/guardian/__init__.py index c1cbb4c0e5a..075c388c4e4 100644 --- a/homeassistant/components/guardian/__init__.py +++ b/homeassistant/components/guardian/__init__.py @@ -11,7 +11,7 @@ from aioguardian import Client from aioguardian.errors import GuardianError import voluptuous as vol -from homeassistant.config_entries import ConfigEntry, ConfigEntryState +from homeassistant.config_entries import ConfigEntry from homeassistant.const import ( ATTR_DEVICE_ID, CONF_DEVICE_ID, @@ -247,12 +247,7 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: if unload_ok: hass.data[DOMAIN].pop(entry.entry_id) - loaded_entries = [ - entry - for entry in hass.config_entries.async_entries(DOMAIN) - if entry.state == ConfigEntryState.LOADED - ] - if len(loaded_entries) == 1: + if not hass.config_entries.async_loaded_entries(DOMAIN): # If this is the last loaded instance of Guardian, deregister any services # defined during integration setup: for service_name in SERVICES: diff --git a/homeassistant/components/lookin/__init__.py b/homeassistant/components/lookin/__init__.py index 2fbabc12747..247282309e4 100644 --- a/homeassistant/components/lookin/__init__.py +++ b/homeassistant/components/lookin/__init__.py @@ -19,7 +19,7 @@ from aiolookin import ( ) from aiolookin.models import UDPCommandType, UDPEvent -from homeassistant.config_entries import ConfigEntry, ConfigEntryState +from homeassistant.config_entries import ConfigEntry from homeassistant.const import CONF_HOST, Platform from homeassistant.core import HomeAssistant, callback from homeassistant.exceptions import ConfigEntryNotReady @@ -192,12 +192,7 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: if unload_ok := await hass.config_entries.async_unload_platforms(entry, PLATFORMS): hass.data[DOMAIN].pop(entry.entry_id) - loaded_entries = [ - entry - for entry in hass.config_entries.async_entries(DOMAIN) - if entry.state == ConfigEntryState.LOADED - ] - if len(loaded_entries) == 1: + if not hass.config_entries.async_loaded_entries(DOMAIN): manager: LookinUDPManager = hass.data[DOMAIN][UDP_MANAGER] await manager.async_stop() return unload_ok diff --git a/homeassistant/components/motion_blinds/__init__.py b/homeassistant/components/motion_blinds/__init__.py index fa1664353e1..df06ffb75fc 100644 --- a/homeassistant/components/motion_blinds/__init__.py +++ b/homeassistant/components/motion_blinds/__init__.py @@ -6,7 +6,7 @@ from typing import TYPE_CHECKING from motionblinds import AsyncMotionMulticast -from homeassistant.config_entries import ConfigEntry, ConfigEntryState +from homeassistant.config_entries import ConfigEntry from homeassistant.const import CONF_API_KEY, CONF_HOST, EVENT_HOMEASSISTANT_STOP from homeassistant.core import HomeAssistant from homeassistant.exceptions import ConfigEntryNotReady @@ -124,12 +124,7 @@ async def async_unload_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> multicast.Unregister_motion_gateway(config_entry.data[CONF_HOST]) hass.data[DOMAIN].pop(config_entry.entry_id) - loaded_entries = [ - entry - for entry in hass.config_entries.async_entries(DOMAIN) - if entry.state == ConfigEntryState.LOADED - ] - if len(loaded_entries) == 1: + if not hass.config_entries.async_loaded_entries(DOMAIN): # No motion gateways left, stop Motion multicast unsub_stop = hass.data[DOMAIN].pop(KEY_UNSUB_STOP) unsub_stop() diff --git a/homeassistant/components/netgear_lte/__init__.py b/homeassistant/components/netgear_lte/__init__.py index a756d85c866..47a39a39be0 100644 --- a/homeassistant/components/netgear_lte/__init__.py +++ b/homeassistant/components/netgear_lte/__init__.py @@ -6,7 +6,6 @@ from aiohttp.cookiejar import CookieJar import eternalegypt from eternalegypt.eternalegypt import SMS -from homeassistant.config_entries import ConfigEntryState from homeassistant.const import CONF_HOST, CONF_NAME, CONF_PASSWORD, Platform from homeassistant.core import HomeAssistant from homeassistant.exceptions import ConfigEntryNotReady @@ -117,12 +116,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: NetgearLTEConfigEntry) - async def async_unload_entry(hass: HomeAssistant, entry: NetgearLTEConfigEntry) -> bool: """Unload a config entry.""" unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS) - loaded_entries = [ - entry - for entry in hass.config_entries.async_entries(DOMAIN) - if entry.state == ConfigEntryState.LOADED - ] - if len(loaded_entries) == 1: + if not hass.config_entries.async_loaded_entries(DOMAIN): hass.data.pop(DOMAIN, None) for service_name in hass.services.async_services()[DOMAIN]: hass.services.async_remove(DOMAIN, service_name) diff --git a/homeassistant/components/rainmachine/__init__.py b/homeassistant/components/rainmachine/__init__.py index 4d486c9c6aa..65648b8d44f 100644 --- a/homeassistant/components/rainmachine/__init__.py +++ b/homeassistant/components/rainmachine/__init__.py @@ -13,7 +13,7 @@ from regenmaschine.controller import Controller from regenmaschine.errors import RainMachineError, UnknownAPICallError import voluptuous as vol -from homeassistant.config_entries import ConfigEntry, ConfigEntryState +from homeassistant.config_entries import ConfigEntry from homeassistant.const import ( CONF_DEVICE_ID, CONF_IP_ADDRESS, @@ -465,12 +465,7 @@ async def async_unload_entry( ) -> bool: """Unload an RainMachine config entry.""" unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS) - loaded_entries = [ - entry - for entry in hass.config_entries.async_entries(DOMAIN) - if entry.state is ConfigEntryState.LOADED - ] - if len(loaded_entries) == 1: + if not hass.config_entries.async_loaded_entries(DOMAIN): # If this is the last loaded instance of RainMachine, deregister any services # defined during integration setup: for service_name in ( diff --git a/homeassistant/components/simplisafe/__init__.py b/homeassistant/components/simplisafe/__init__.py index 2f19c5117a4..8a75baa69c6 100644 --- a/homeassistant/components/simplisafe/__init__.py +++ b/homeassistant/components/simplisafe/__init__.py @@ -39,7 +39,7 @@ from simplipy.websocket import ( ) import voluptuous as vol -from homeassistant.config_entries import ConfigEntry, ConfigEntryState +from homeassistant.config_entries import ConfigEntry from homeassistant.const import ( ATTR_CODE, ATTR_DEVICE_ID, @@ -402,12 +402,7 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: if unload_ok: hass.data[DOMAIN].pop(entry.entry_id) - loaded_entries = [ - entry - for entry in hass.config_entries.async_entries(DOMAIN) - if entry.state == ConfigEntryState.LOADED - ] - if len(loaded_entries) == 1: + if not hass.config_entries.async_loaded_entries(DOMAIN): # If this is the last loaded instance of SimpliSafe, deregister any services # defined during integration setup: for service_name in SERVICES: diff --git a/homeassistant/components/tplink_omada/__init__.py b/homeassistant/components/tplink_omada/__init__.py index 06df118463b..7ea7fd95fef 100644 --- a/homeassistant/components/tplink_omada/__init__.py +++ b/homeassistant/components/tplink_omada/__init__.py @@ -11,7 +11,7 @@ from tplink_omada_client.exceptions import ( UnsupportedControllerVersion, ) -from homeassistant.config_entries import ConfigEntry, ConfigEntryState +from homeassistant.config_entries import ConfigEntry from homeassistant.const import Platform from homeassistant.core import HomeAssistant, ServiceCall from homeassistant.exceptions import ConfigEntryAuthFailed, ConfigEntryNotReady @@ -80,12 +80,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: OmadaConfigEntry) -> boo async def async_unload_entry(hass: HomeAssistant, entry: OmadaConfigEntry) -> bool: """Unload a config entry.""" unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS) - loaded_entries = [ - entry - for entry in hass.config_entries.async_entries(DOMAIN) - if entry.state == ConfigEntryState.LOADED - ] - if len(loaded_entries) == 1: + if not hass.config_entries.async_loaded_entries(DOMAIN): # This is the last loaded instance of Omada, deregister any services hass.services.async_remove(DOMAIN, "reconnect_client") diff --git a/homeassistant/components/xiaomi_aqara/__init__.py b/homeassistant/components/xiaomi_aqara/__init__.py index 579994aaf6b..6e4d143d84e 100644 --- a/homeassistant/components/xiaomi_aqara/__init__.py +++ b/homeassistant/components/xiaomi_aqara/__init__.py @@ -7,7 +7,7 @@ import voluptuous as vol from xiaomi_gateway import AsyncXiaomiGatewayMulticast, XiaomiGateway from homeassistant.components import persistent_notification -from homeassistant.config_entries import ConfigEntry, ConfigEntryState +from homeassistant.config_entries import ConfigEntry from homeassistant.const import ( ATTR_DEVICE_ID, CONF_HOST, @@ -216,12 +216,7 @@ async def async_unload_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> if unload_ok: hass.data[DOMAIN][GATEWAYS_KEY].pop(config_entry.entry_id) - loaded_entries = [ - entry - for entry in hass.config_entries.async_entries(DOMAIN) - if entry.state == ConfigEntryState.LOADED - ] - if len(loaded_entries) == 1: + if not hass.config_entries.async_loaded_entries(DOMAIN): # No gateways left, stop Xiaomi socket unsub_stop = hass.data[DOMAIN].pop(KEY_UNSUB_STOP) unsub_stop() diff --git a/homeassistant/config_entries.py b/homeassistant/config_entries.py index a103148e3b1..871b476227c 100644 --- a/homeassistant/config_entries.py +++ b/homeassistant/config_entries.py @@ -155,6 +155,8 @@ class ConfigEntryState(Enum): """An error occurred when trying to unload the entry""" SETUP_IN_PROGRESS = "setup_in_progress", False """The config entry is setting up.""" + UNLOAD_IN_PROGRESS = "unload_in_progress", False + """The config entry is being unloaded.""" _recoverable: bool @@ -955,18 +957,25 @@ class ConfigEntry[_DataT = Any]: ) return False + if domain_is_integration: + self._async_set_state(hass, ConfigEntryState.UNLOAD_IN_PROGRESS, None) try: result = await component.async_unload_entry(hass, self) assert isinstance(result, bool) - # Only adjust state if we unloaded the component - if domain_is_integration and result: - await self._async_process_on_unload(hass) - if hasattr(self, "runtime_data"): - object.__delattr__(self, "runtime_data") + # Only do side effects if we unloaded the integration + if domain_is_integration: + if result: + await self._async_process_on_unload(hass) + if hasattr(self, "runtime_data"): + object.__delattr__(self, "runtime_data") - self._async_set_state(hass, ConfigEntryState.NOT_LOADED, None) + self._async_set_state(hass, ConfigEntryState.NOT_LOADED, None) + else: + self._async_set_state( + hass, ConfigEntryState.FAILED_UNLOAD, "Unload failed" + ) except Exception as exc: _LOGGER.exception( @@ -2052,9 +2061,9 @@ class ConfigEntries: else: unload_success = await self.async_unload(entry_id, _lock=False) + del self._entries[entry.entry_id] await entry.async_remove(self.hass) - del self._entries[entry.entry_id] self.async_update_issues() self._async_schedule_save() diff --git a/tests/components/matter/test_init.py b/tests/components/matter/test_init.py index f6576689413..553358f12e3 100644 --- a/tests/components/matter/test_init.py +++ b/tests/components/matter/test_init.py @@ -502,7 +502,7 @@ async def test_issue_registry_invalid_version( ("stop_addon_side_effect", "entry_state"), [ (None, ConfigEntryState.NOT_LOADED), - (SupervisorError("Boom"), ConfigEntryState.LOADED), + (SupervisorError("Boom"), ConfigEntryState.FAILED_UNLOAD), ], ) async def test_stop_addon( diff --git a/tests/components/unifi/test_hub.py b/tests/components/unifi/test_hub.py index 5492f6fe0df..8b129d3d648 100644 --- a/tests/components/unifi/test_hub.py +++ b/tests/components/unifi/test_hub.py @@ -76,7 +76,7 @@ async def test_reset_fails( return_value=False, ): assert not await hass.config_entries.async_unload(config_entry_setup.entry_id) - assert config_entry_setup.state is ConfigEntryState.LOADED + assert config_entry_setup.state is ConfigEntryState.FAILED_UNLOAD @pytest.mark.usefixtures("mock_device_registry") diff --git a/tests/components/zwave_js/test_init.py b/tests/components/zwave_js/test_init.py index 4f858f3e545..c575066b57c 100644 --- a/tests/components/zwave_js/test_init.py +++ b/tests/components/zwave_js/test_init.py @@ -847,7 +847,7 @@ async def test_issue_registry( ("stop_addon_side_effect", "entry_state"), [ (None, ConfigEntryState.NOT_LOADED), - (SupervisorError("Boom"), ConfigEntryState.LOADED), + (SupervisorError("Boom"), ConfigEntryState.FAILED_UNLOAD), ], ) async def test_stop_addon( diff --git a/tests/test_config_entries.py b/tests/test_config_entries.py index bf2280790fa..acc79deb538 100644 --- a/tests/test_config_entries.py +++ b/tests/test_config_entries.py @@ -468,8 +468,8 @@ async def test_remove_entry( hass: HomeAssistant, entry: config_entries.ConfigEntry ) -> None: """Mock removing an entry.""" - # Check that the entry is not yet removed from config entries - assert hass.config_entries.async_get_entry(entry.entry_id) + # Check that the entry is no longer in the config entries + assert not hass.config_entries.async_get_entry(entry.entry_id) remove_entry_calls.append(None) entity = MockEntity(unique_id="1234", name="Test Entity") @@ -2623,7 +2623,7 @@ async def test_entry_setup_invalid_state( ("unload_result", "expected_result", "expected_state", "has_runtime_data"), [ (True, True, config_entries.ConfigEntryState.NOT_LOADED, False), - (False, False, config_entries.ConfigEntryState.LOADED, True), + (False, False, config_entries.ConfigEntryState.FAILED_UNLOAD, True), ], ) async def test_entry_unload( @@ -2648,7 +2648,7 @@ async def test_entry_unload( """Mock unload entry.""" unload_entry_calls.append(None) verify_runtime_data() - assert entry.state is config_entries.ConfigEntryState.LOADED + assert entry.state is config_entries.ConfigEntryState.UNLOAD_IN_PROGRESS return unload_result entry = MockConfigEntry(domain="comp", state=config_entries.ConfigEntryState.LOADED) From d7e796e9f9c7c44986b378c5544448697a192db7 Mon Sep 17 00:00:00 2001 From: Norbert Rittel Date: Mon, 17 Feb 2025 18:37:46 +0100 Subject: [PATCH 43/52] Fix typos in qBittorrent exceptions strings (#138728) --- homeassistant/components/qbittorrent/strings.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/homeassistant/components/qbittorrent/strings.json b/homeassistant/components/qbittorrent/strings.json index 83d93766ee4..eb7cd19faca 100644 --- a/homeassistant/components/qbittorrent/strings.json +++ b/homeassistant/components/qbittorrent/strings.json @@ -109,16 +109,16 @@ }, "exceptions": { "invalid_device": { - "message": "No device with id {device_id} was found" + "message": "No device with ID {device_id} was found" }, "invalid_entry_id": { - "message": "No entry with id {device_id} was found" + "message": "No entry with ID {device_id} was found" }, "login_error": { - "message": "A login error occured. Please check you username and password." + "message": "A login error occured. Please check your username and password." }, "cannot_connect": { - "message": "Can't connect to QBittorrent, please check your configuration." + "message": "Can't connect to qBittorrent, please check your configuration." } } } From da9fbf21dffc93c1392f85007f67d5294826399f Mon Sep 17 00:00:00 2001 From: Andrew Sayre <6730289+andrewsayre@users.noreply.github.com> Date: Mon, 17 Feb 2025 13:04:39 -0600 Subject: [PATCH 44/52] Update HEOS repair issues quality scale item (#138724) --- homeassistant/components/heos/quality_scale.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/homeassistant/components/heos/quality_scale.yaml b/homeassistant/components/heos/quality_scale.yaml index a08e2dca544..6ade4e6ffb9 100644 --- a/homeassistant/components/heos/quality_scale.yaml +++ b/homeassistant/components/heos/quality_scale.yaml @@ -57,7 +57,7 @@ rules: exception-translations: done icon-translations: done reconfiguration-flow: done - repair-issues: todo + repair-issues: done stale-devices: done # Platinum async-dependency: done From 3b6e3fe457a7f206a562dea43fdfb74ba9bca541 Mon Sep 17 00:00:00 2001 From: Sid <27780930+autinerd@users.noreply.github.com> Date: Mon, 17 Feb 2025 20:10:56 +0100 Subject: [PATCH 45/52] Fix race condition on eheimdigital coordinator setup (#138580) --- .../components/eheimdigital/coordinator.py | 19 +++++++-- tests/components/eheimdigital/conftest.py | 13 ++++++ tests/components/eheimdigital/test_climate.py | 35 +++++++++------- tests/components/eheimdigital/test_init.py | 5 ++- tests/components/eheimdigital/test_light.py | 42 ++++++++++--------- 5 files changed, 76 insertions(+), 38 deletions(-) diff --git a/homeassistant/components/eheimdigital/coordinator.py b/homeassistant/components/eheimdigital/coordinator.py index 4359a314494..6e96fb388ee 100644 --- a/homeassistant/components/eheimdigital/coordinator.py +++ b/homeassistant/components/eheimdigital/coordinator.py @@ -2,16 +2,18 @@ from __future__ import annotations +import asyncio from collections.abc import Callable from aiohttp import ClientError from eheimdigital.device import EheimDigitalDevice from eheimdigital.hub import EheimDigitalHub -from eheimdigital.types import EheimDeviceType +from eheimdigital.types import EheimDeviceType, EheimDigitalClientError from homeassistant.config_entries import ConfigEntry from homeassistant.const import CONF_HOST from homeassistant.core import HomeAssistant +from homeassistant.exceptions import ConfigEntryNotReady from homeassistant.helpers.aiohttp_client import async_get_clientsession from homeassistant.helpers.entity_component import DEFAULT_SCAN_INTERVAL from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed @@ -43,12 +45,14 @@ class EheimDigitalUpdateCoordinator( name=DOMAIN, update_interval=DEFAULT_SCAN_INTERVAL, ) + self.main_device_added_event = asyncio.Event() self.hub = EheimDigitalHub( host=self.config_entry.data[CONF_HOST], session=async_get_clientsession(hass), loop=hass.loop, receive_callback=self._async_receive_callback, device_found_callback=self._async_device_found, + main_device_added_event=self.main_device_added_event, ) self.known_devices: set[str] = set() self.platform_callbacks: set[AsyncSetupDeviceEntitiesCallback] = set() @@ -76,8 +80,17 @@ class EheimDigitalUpdateCoordinator( self.async_set_updated_data(self.hub.devices) async def _async_setup(self) -> None: - await self.hub.connect() - await self.hub.update() + try: + await self.hub.connect() + async with asyncio.timeout(2): + # This event gets triggered when the first message is received from + # the device, it contains the data necessary to create the main device. + # This removes the race condition where the main device is accessed + # before the response from the device is parsed. + await self.main_device_added_event.wait() + await self.hub.update() + except (TimeoutError, EheimDigitalClientError) as err: + raise ConfigEntryNotReady from err async def _async_update_data(self) -> dict[str, EheimDigitalDevice]: try: diff --git a/tests/components/eheimdigital/conftest.py b/tests/components/eheimdigital/conftest.py index afb97b97569..ae1bc74df90 100644 --- a/tests/components/eheimdigital/conftest.py +++ b/tests/components/eheimdigital/conftest.py @@ -11,6 +11,7 @@ import pytest from homeassistant.components.eheimdigital.const import DOMAIN from homeassistant.const import CONF_HOST +from homeassistant.core import HomeAssistant from tests.common import MockConfigEntry @@ -79,3 +80,15 @@ def eheimdigital_hub_mock( } eheimdigital_hub_mock.return_value.main = classic_led_ctrl_mock yield eheimdigital_hub_mock + + +async def init_integration( + hass: HomeAssistant, mock_config_entry: MockConfigEntry +) -> None: + """Initialize the integration.""" + + mock_config_entry.add_to_hass(hass) + with patch( + "homeassistant.components.eheimdigital.coordinator.asyncio.Event", new=AsyncMock + ): + await hass.config_entries.async_setup(mock_config_entry.entry_id) diff --git a/tests/components/eheimdigital/test_climate.py b/tests/components/eheimdigital/test_climate.py index f1f29ce9d34..4abc33e449e 100644 --- a/tests/components/eheimdigital/test_climate.py +++ b/tests/components/eheimdigital/test_climate.py @@ -1,6 +1,6 @@ """Tests for the climate module.""" -from unittest.mock import MagicMock, patch +from unittest.mock import AsyncMock, MagicMock, patch from eheimdigital.types import ( EheimDeviceType, @@ -31,6 +31,8 @@ from homeassistant.core import HomeAssistant from homeassistant.exceptions import HomeAssistantError from homeassistant.helpers import entity_registry as er +from .conftest import init_integration + from tests.common import MockConfigEntry, snapshot_platform @@ -45,7 +47,13 @@ async def test_setup_heater( """Test climate platform setup for heater.""" mock_config_entry.add_to_hass(hass) - with patch("homeassistant.components.eheimdigital.PLATFORMS", [Platform.CLIMATE]): + with ( + patch("homeassistant.components.eheimdigital.PLATFORMS", [Platform.CLIMATE]), + patch( + "homeassistant.components.eheimdigital.coordinator.asyncio.Event", + new=AsyncMock, + ), + ): await hass.config_entries.async_setup(mock_config_entry.entry_id) await eheimdigital_hub_mock.call_args.kwargs["device_found_callback"]( @@ -69,7 +77,13 @@ async def test_dynamic_new_devices( eheimdigital_hub_mock.return_value.devices = {} - with patch("homeassistant.components.eheimdigital.PLATFORMS", [Platform.CLIMATE]): + with ( + patch("homeassistant.components.eheimdigital.PLATFORMS", [Platform.CLIMATE]), + patch( + "homeassistant.components.eheimdigital.coordinator.asyncio.Event", + new=AsyncMock, + ), + ): await hass.config_entries.async_setup(mock_config_entry.entry_id) assert ( @@ -108,9 +122,7 @@ async def test_set_preset_mode( heater_mode: HeaterMode, ) -> None: """Test setting a preset mode.""" - mock_config_entry.add_to_hass(hass) - - await hass.config_entries.async_setup(mock_config_entry.entry_id) + await init_integration(hass, mock_config_entry) await eheimdigital_hub_mock.call_args.kwargs["device_found_callback"]( "00:00:00:00:00:02", EheimDeviceType.VERSION_EHEIM_EXT_HEATER @@ -146,9 +158,7 @@ async def test_set_temperature( mock_config_entry: MockConfigEntry, ) -> None: """Test setting a preset mode.""" - mock_config_entry.add_to_hass(hass) - - await hass.config_entries.async_setup(mock_config_entry.entry_id) + await init_integration(hass, mock_config_entry) await eheimdigital_hub_mock.call_args.kwargs["device_found_callback"]( "00:00:00:00:00:02", EheimDeviceType.VERSION_EHEIM_EXT_HEATER @@ -189,9 +199,7 @@ async def test_set_hvac_mode( active: bool, ) -> None: """Test setting a preset mode.""" - mock_config_entry.add_to_hass(hass) - - await hass.config_entries.async_setup(mock_config_entry.entry_id) + await init_integration(hass, mock_config_entry) await eheimdigital_hub_mock.call_args.kwargs["device_found_callback"]( "00:00:00:00:00:02", EheimDeviceType.VERSION_EHEIM_EXT_HEATER @@ -231,9 +239,8 @@ async def test_state_update( heater_mock.is_heating = False heater_mock.operation_mode = HeaterMode.BIO - mock_config_entry.add_to_hass(hass) + await init_integration(hass, mock_config_entry) - await hass.config_entries.async_setup(mock_config_entry.entry_id) await eheimdigital_hub_mock.call_args.kwargs["device_found_callback"]( "00:00:00:00:00:02", EheimDeviceType.VERSION_EHEIM_EXT_HEATER ) diff --git a/tests/components/eheimdigital/test_init.py b/tests/components/eheimdigital/test_init.py index 211a8b3b6fd..c64997ee372 100644 --- a/tests/components/eheimdigital/test_init.py +++ b/tests/components/eheimdigital/test_init.py @@ -8,6 +8,8 @@ from homeassistant.core import HomeAssistant from homeassistant.helpers import device_registry as dr from homeassistant.setup import async_setup_component +from .conftest import init_integration + from tests.common import MockConfigEntry from tests.typing import WebSocketGenerator @@ -21,9 +23,8 @@ async def test_remove_device( ) -> None: """Test removing a device.""" assert await async_setup_component(hass, "config", {}) - mock_config_entry.add_to_hass(hass) - await hass.config_entries.async_setup(mock_config_entry.entry_id) + await init_integration(hass, mock_config_entry) await eheimdigital_hub_mock.call_args.kwargs["device_found_callback"]( "00:00:00:00:00:01", EheimDeviceType.VERSION_EHEIM_CLASSIC_LED_CTRL_PLUS_E diff --git a/tests/components/eheimdigital/test_light.py b/tests/components/eheimdigital/test_light.py index da224979c43..81b63218085 100644 --- a/tests/components/eheimdigital/test_light.py +++ b/tests/components/eheimdigital/test_light.py @@ -1,7 +1,7 @@ """Tests for the light module.""" from datetime import timedelta -from unittest.mock import MagicMock, patch +from unittest.mock import AsyncMock, MagicMock, patch from aiohttp import ClientError from eheimdigital.types import EheimDeviceType, LightMode @@ -26,6 +26,8 @@ from homeassistant.core import HomeAssistant from homeassistant.helpers import entity_registry as er from homeassistant.util.color import value_to_brightness +from .conftest import init_integration + from tests.common import MockConfigEntry, async_fire_time_changed, snapshot_platform @@ -51,7 +53,13 @@ async def test_setup_classic_led_ctrl( classic_led_ctrl_mock.tankconfig = tankconfig - with patch("homeassistant.components.eheimdigital.PLATFORMS", [Platform.LIGHT]): + with ( + patch("homeassistant.components.eheimdigital.PLATFORMS", [Platform.LIGHT]), + patch( + "homeassistant.components.eheimdigital.coordinator.asyncio.Event", + new=AsyncMock, + ), + ): await hass.config_entries.async_setup(mock_config_entry.entry_id) await eheimdigital_hub_mock.call_args.kwargs["device_found_callback"]( @@ -75,7 +83,13 @@ async def test_dynamic_new_devices( eheimdigital_hub_mock.return_value.devices = {} - with patch("homeassistant.components.eheimdigital.PLATFORMS", [Platform.LIGHT]): + with ( + patch("homeassistant.components.eheimdigital.PLATFORMS", [Platform.LIGHT]), + patch( + "homeassistant.components.eheimdigital.coordinator.asyncio.Event", + new=AsyncMock, + ), + ): await hass.config_entries.async_setup(mock_config_entry.entry_id) assert ( @@ -106,10 +120,8 @@ async def test_turn_off( classic_led_ctrl_mock: MagicMock, ) -> None: """Test turning off the light.""" - mock_config_entry.add_to_hass(hass) + await init_integration(hass, mock_config_entry) - with patch("homeassistant.components.eheimdigital.PLATFORMS", [Platform.LIGHT]): - await hass.config_entries.async_setup(mock_config_entry.entry_id) await mock_config_entry.runtime_data._async_device_found( "00:00:00:00:00:01", EheimDeviceType.VERSION_EHEIM_CLASSIC_LED_CTRL_PLUS_E ) @@ -143,10 +155,8 @@ async def test_turn_on_brightness( expected_dim_value: int, ) -> None: """Test turning on the light with different brightness values.""" - mock_config_entry.add_to_hass(hass) + await init_integration(hass, mock_config_entry) - with patch("homeassistant.components.eheimdigital.PLATFORMS", [Platform.LIGHT]): - await hass.config_entries.async_setup(mock_config_entry.entry_id) await eheimdigital_hub_mock.call_args.kwargs["device_found_callback"]( "00:00:00:00:00:01", EheimDeviceType.VERSION_EHEIM_CLASSIC_LED_CTRL_PLUS_E ) @@ -173,12 +183,10 @@ async def test_turn_on_effect( classic_led_ctrl_mock: MagicMock, ) -> None: """Test turning on the light with an effect value.""" - mock_config_entry.add_to_hass(hass) - classic_led_ctrl_mock.light_mode = LightMode.MAN_MODE - with patch("homeassistant.components.eheimdigital.PLATFORMS", [Platform.LIGHT]): - await hass.config_entries.async_setup(mock_config_entry.entry_id) + await init_integration(hass, mock_config_entry) + await eheimdigital_hub_mock.call_args.kwargs["device_found_callback"]( "00:00:00:00:00:01", EheimDeviceType.VERSION_EHEIM_CLASSIC_LED_CTRL_PLUS_E ) @@ -204,10 +212,8 @@ async def test_state_update( classic_led_ctrl_mock: MagicMock, ) -> None: """Test the light state update.""" - mock_config_entry.add_to_hass(hass) + await init_integration(hass, mock_config_entry) - with patch("homeassistant.components.eheimdigital.PLATFORMS", [Platform.LIGHT]): - await hass.config_entries.async_setup(mock_config_entry.entry_id) await eheimdigital_hub_mock.call_args.kwargs["device_found_callback"]( "00:00:00:00:00:01", EheimDeviceType.VERSION_EHEIM_CLASSIC_LED_CTRL_PLUS_E ) @@ -228,10 +234,8 @@ async def test_update_failed( freezer: FrozenDateTimeFactory, ) -> None: """Test an failed update.""" - mock_config_entry.add_to_hass(hass) + await init_integration(hass, mock_config_entry) - with patch("homeassistant.components.eheimdigital.PLATFORMS", [Platform.LIGHT]): - await hass.config_entries.async_setup(mock_config_entry.entry_id) await eheimdigital_hub_mock.call_args.kwargs["device_found_callback"]( "00:00:00:00:00:01", EheimDeviceType.VERSION_EHEIM_CLASSIC_LED_CTRL_PLUS_E ) From 9ac60f1c7f5061a761b4f7895cc7504f6f6ad80d Mon Sep 17 00:00:00 2001 From: Xitee <59659167+Xitee1@users.noreply.github.com> Date: Mon, 17 Feb 2025 20:37:33 +0100 Subject: [PATCH 46/52] Fix small typo in qbittorrent strings.json (#138734) --- homeassistant/components/qbittorrent/strings.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/homeassistant/components/qbittorrent/strings.json b/homeassistant/components/qbittorrent/strings.json index eb7cd19faca..0dcb9298f1f 100644 --- a/homeassistant/components/qbittorrent/strings.json +++ b/homeassistant/components/qbittorrent/strings.json @@ -53,7 +53,7 @@ "connection_status": { "name": "Connection status", "state": { - "connected": "Conencted", + "connected": "Connected", "firewalled": "Firewalled", "disconnected": "Disconnected" } From 772e7147bd9dfab5f4c42707eabab4ff4db95b07 Mon Sep 17 00:00:00 2001 From: Norbert Rittel Date: Mon, 17 Feb 2025 20:51:30 +0100 Subject: [PATCH 47/52] Fix user-facing strings of the NWS integration (#138727) - fix sentence-casing of "API key" to match common string - remove excessive trailing period from action name - reword action description to match HA style - make "Forecast type" description UI-friendly (a selector is available) --- homeassistant/components/nws/strings.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/homeassistant/components/nws/strings.json b/homeassistant/components/nws/strings.json index c9ee8349631..72b6a2c86b6 100644 --- a/homeassistant/components/nws/strings.json +++ b/homeassistant/components/nws/strings.json @@ -2,7 +2,7 @@ "config": { "step": { "user": { - "description": "If a METAR station code is not specified, the latitude and longitude will be used to find the closest station. For now, an API Key can be anything. It is recommended to use a valid email address.", + "description": "If a METAR station code is not specified, the latitude and longitude will be used to find the closest station. For now, the API key can be anything. It is recommended to use a valid email address.", "title": "Connect to the National Weather Service", "data": { "api_key": "[%key:common::config_flow::data::api_key%]", @@ -30,12 +30,12 @@ }, "services": { "get_forecasts_extra": { - "name": "Get extra forecasts data.", - "description": "Get extra data for weather forecasts.", + "name": "Get extra forecasts data", + "description": "Retrieves extra data for weather forecasts.", "fields": { "type": { "name": "Forecast type", - "description": "Forecast type: hourly or twice_daily." + "description": "The scope of the weather forecast." } } } From bbfb9fbdaeb3c9bcb023e1c01ddfb722023d00f1 Mon Sep 17 00:00:00 2001 From: Jonas Fors Lellky Date: Mon, 17 Feb 2025 21:10:18 +0100 Subject: [PATCH 48/52] Mark reauthentication-flow as exempt for flexit_bacnet (#138740) --- homeassistant/components/flexit_bacnet/quality_scale.yaml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/homeassistant/components/flexit_bacnet/quality_scale.yaml b/homeassistant/components/flexit_bacnet/quality_scale.yaml index f59435bad0d..9a4a4eace40 100644 --- a/homeassistant/components/flexit_bacnet/quality_scale.yaml +++ b/homeassistant/components/flexit_bacnet/quality_scale.yaml @@ -48,7 +48,10 @@ rules: comment: | Done implicitly with coordinator. parallel-updates: done - reauthentication-flow: todo + reauthentication-flow: + status: exempt + comment: | + Integration doesn't require any form of authentication. test-coverage: todo # Gold entity-translations: done From f9047d022342222733858a76d906915a9e530792 Mon Sep 17 00:00:00 2001 From: Jonas Fors Lellky Date: Mon, 17 Feb 2025 21:15:37 +0100 Subject: [PATCH 49/52] Mark action-exceptions as exempt for flexit_bacnet (#138739) * Mark action-exceptions as exempt for flexit_bacnet * Update homeassistant/components/flexit_bacnet/quality_scale.yaml --------- Co-authored-by: Josef Zweck --- homeassistant/components/flexit_bacnet/quality_scale.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/homeassistant/components/flexit_bacnet/quality_scale.yaml b/homeassistant/components/flexit_bacnet/quality_scale.yaml index 9a4a4eace40..eb649656c9d 100644 --- a/homeassistant/components/flexit_bacnet/quality_scale.yaml +++ b/homeassistant/components/flexit_bacnet/quality_scale.yaml @@ -31,7 +31,7 @@ rules: Done implicitly with `await coordinator.async_config_entry_first_refresh()`. unique-config-entry: done # Silver - action-exceptions: todo + action-exceptions: done config-entry-unloading: done docs-configuration-parameters: status: exempt From 5658f9ca405eadc96be42a76fc4896b5d6c08ade Mon Sep 17 00:00:00 2001 From: Norbert Rittel Date: Mon, 17 Feb 2025 22:28:45 +0100 Subject: [PATCH 50/52] Fix wrong description of teslemetry.set_scheduled_charging action (#138723) The action allows the user to set a time at which to start charging, but the action's description uses the wrong word "completed". --- homeassistant/components/teslemetry/strings.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/homeassistant/components/teslemetry/strings.json b/homeassistant/components/teslemetry/strings.json index 68ad12a46b6..b6b3d17e37c 100644 --- a/homeassistant/components/teslemetry/strings.json +++ b/homeassistant/components/teslemetry/strings.json @@ -712,7 +712,7 @@ "name": "Navigate to coordinates" }, "set_scheduled_charging": { - "description": "Sets a time at which charging should be completed.", + "description": "Sets a time at which charging should be started.", "fields": { "device_id": { "description": "Vehicle to schedule.", From 25865b4849b1a2eb5133fe3ab2fdfe3fd3b46818 Mon Sep 17 00:00:00 2001 From: Christopher Fenner <9592452+CFenner@users.noreply.github.com> Date: Mon, 17 Feb 2025 23:28:49 +0100 Subject: [PATCH 51/52] Bump PyViCare to 2.43.1 (#138737) bump PyViCare to 2.43.1 --- homeassistant/components/vicare/manifest.json | 2 +- requirements_all.txt | 2 +- requirements_test_all.txt | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/vicare/manifest.json b/homeassistant/components/vicare/manifest.json index a5718962f55..e39adaf6c4c 100644 --- a/homeassistant/components/vicare/manifest.json +++ b/homeassistant/components/vicare/manifest.json @@ -11,5 +11,5 @@ "documentation": "https://www.home-assistant.io/integrations/vicare", "iot_class": "cloud_polling", "loggers": ["PyViCare"], - "requirements": ["PyViCare==2.43.0"] + "requirements": ["PyViCare==2.43.1"] } diff --git a/requirements_all.txt b/requirements_all.txt index 9efa46334a6..56eb939bbd5 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -100,7 +100,7 @@ PyTransportNSW==0.1.1 PyTurboJPEG==1.7.5 # homeassistant.components.vicare -PyViCare==2.43.0 +PyViCare==2.43.1 # homeassistant.components.xiaomi_aqara PyXiaomiGateway==0.14.3 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index 0ced3ce92ab..cc2b3578e2a 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -94,7 +94,7 @@ PyTransportNSW==0.1.1 PyTurboJPEG==1.7.5 # homeassistant.components.vicare -PyViCare==2.43.0 +PyViCare==2.43.1 # homeassistant.components.xiaomi_aqara PyXiaomiGateway==0.14.3 From 0dc1151a25a9768e2c6c24de61b3a8439a466152 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Mon, 17 Feb 2025 17:08:38 -0600 Subject: [PATCH 52/52] Bump aioesphomeapi to 29.1.0 (#138742) --- homeassistant/components/esphome/manifest.json | 2 +- requirements_all.txt | 2 +- requirements_test_all.txt | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/esphome/manifest.json b/homeassistant/components/esphome/manifest.json index 8f9f06e6967..08be23ae001 100644 --- a/homeassistant/components/esphome/manifest.json +++ b/homeassistant/components/esphome/manifest.json @@ -16,7 +16,7 @@ "loggers": ["aioesphomeapi", "noiseprotocol", "bleak_esphome"], "mqtt": ["esphome/discover/#"], "requirements": [ - "aioesphomeapi==29.0.2", + "aioesphomeapi==29.1.0", "esphome-dashboard-api==1.2.3", "bleak-esphome==2.7.1" ], diff --git a/requirements_all.txt b/requirements_all.txt index 56eb939bbd5..60eb811f076 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -243,7 +243,7 @@ aioelectricitymaps==0.4.0 aioemonitor==1.0.5 # homeassistant.components.esphome -aioesphomeapi==29.0.2 +aioesphomeapi==29.1.0 # homeassistant.components.flo aioflo==2021.11.0 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index cc2b3578e2a..b4921cccf89 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -231,7 +231,7 @@ aioelectricitymaps==0.4.0 aioemonitor==1.0.5 # homeassistant.components.esphome -aioesphomeapi==29.0.2 +aioesphomeapi==29.1.0 # homeassistant.components.flo aioflo==2021.11.0