diff --git a/homeassistant/components/counter/__init__.py b/homeassistant/components/counter/__init__.py index a77e4340882..91a90c1aa50 100644 --- a/homeassistant/components/counter/__init__.py +++ b/homeassistant/components/counter/__init__.py @@ -18,6 +18,7 @@ from homeassistant.core import HomeAssistant, callback from homeassistant.helpers import collection import homeassistant.helpers.config_validation as cv from homeassistant.helpers.entity_component import EntityComponent +from homeassistant.helpers.issue_registry import IssueSeverity, async_create_issue from homeassistant.helpers.restore_state import RestoreEntity from homeassistant.helpers.storage import Store from homeassistant.helpers.typing import ConfigType @@ -291,6 +292,17 @@ class Counter(collection.CollectionEntity, RestoreEntity): @callback def async_configure(self, **kwargs) -> None: """Change the counter's settings with a service.""" + async_create_issue( + self.hass, + DOMAIN, + "deprecated_configure_service", + breaks_in_ha_version="2023.8.0", + is_fixable=True, + is_persistent=True, + severity=IssueSeverity.WARNING, + translation_key="deprecated_configure_service", + ) + new_state = kwargs.pop(VALUE, self._state) self._config = {**self._config, **kwargs} self._state = self.compute_next_state(new_state) diff --git a/homeassistant/components/counter/services.yaml b/homeassistant/components/counter/services.yaml index d94d05dd7bd..835d39c9d2e 100644 --- a/homeassistant/components/counter/services.yaml +++ b/homeassistant/components/counter/services.yaml @@ -37,51 +37,3 @@ set_value: min: 0 max: 9223372036854775807 mode: box - -configure: - name: Configure - description: Change counter parameters. - target: - entity: - domain: counter - fields: - minimum: - name: Minimum - description: New minimum value for the counter or None to remove minimum. - selector: - number: - min: -9223372036854775807 - max: 9223372036854775807 - mode: box - maximum: - name: Maximum - description: New maximum value for the counter or None to remove maximum. - selector: - number: - min: -9223372036854775807 - max: 9223372036854775807 - mode: box - step: - name: Step - description: New value for step. - selector: - number: - min: 1 - max: 9223372036854775807 - mode: box - initial: - name: Initial - description: New value for initial. - selector: - number: - min: 0 - max: 9223372036854775807 - mode: box - value: - name: Value - description: New state value. - selector: - number: - min: 0 - max: 9223372036854775807 - mode: box diff --git a/homeassistant/components/counter/strings.json b/homeassistant/components/counter/strings.json index 548d1554080..09592594659 100644 --- a/homeassistant/components/counter/strings.json +++ b/homeassistant/components/counter/strings.json @@ -25,5 +25,18 @@ } } } + }, + "issues": { + "deprecated_configure_service": { + "title": "The counter configure service is being removed", + "fix_flow": { + "step": { + "confirm": { + "title": "The counter configure service is being removed", + "description": "The counter service `counter.configure` is being removed and use of it has been detected. If you want to change the current value of a counter, use the new `counter.set_value` service instead.\n\nPlease remove the use of this service from your automations and scripts and select **submit** to close this issue." + } + } + } + } } } diff --git a/tests/components/counter/test_init.py b/tests/components/counter/test_init.py index 5c6dbba71ce..6730b4dec84 100644 --- a/tests/components/counter/test_init.py +++ b/tests/components/counter/test_init.py @@ -24,7 +24,7 @@ from homeassistant.components.counter import ( ) from homeassistant.const import ATTR_ENTITY_ID, ATTR_FRIENDLY_NAME, ATTR_ICON, ATTR_NAME from homeassistant.core import Context, CoreState, HomeAssistant, State -from homeassistant.helpers import entity_registry as er +from homeassistant.helpers import entity_registry as er, issue_registry as ir from homeassistant.setup import async_setup_component from .common import async_decrement, async_increment, async_reset @@ -443,7 +443,9 @@ async def test_counter_max(hass: HomeAssistant, hass_admin_user: MockUser) -> No assert state2.state == "-1" -async def test_configure(hass: HomeAssistant, hass_admin_user: MockUser) -> None: +async def test_configure( + hass: HomeAssistant, hass_admin_user: MockUser, issue_registry: ir.IssueRegistry +) -> None: """Test that setting values through configure works.""" assert await async_setup_component( hass, "counter", {"counter": {"test": {"maximum": "10", "initial": "10"}}} @@ -468,6 +470,11 @@ async def test_configure(hass: HomeAssistant, hass_admin_user: MockUser) -> None assert state.state == "0" assert state.attributes.get("maximum") == 0 + # Ensure an issue is raised for the use of this deprecated service + assert issue_registry.async_get_issue( + domain=DOMAIN, issue_id="deprecated_configure_service" + ) + # disable max await hass.services.async_call( "counter",