Remove counter configure service (#103204)
* Remove counter configure service after deprecation * reproduce state
This commit is contained in:
parent
2d3318e767
commit
72c02d4d63
5 changed files with 7 additions and 206 deletions
|
@ -18,7 +18,6 @@ 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
|
||||
|
@ -44,7 +43,6 @@ ENTITY_ID_FORMAT = DOMAIN + ".{}"
|
|||
SERVICE_DECREMENT = "decrement"
|
||||
SERVICE_INCREMENT = "increment"
|
||||
SERVICE_RESET = "reset"
|
||||
SERVICE_CONFIGURE = "configure"
|
||||
SERVICE_SET_VALUE = "set_value"
|
||||
|
||||
STORAGE_KEY = DOMAIN
|
||||
|
@ -131,17 +129,6 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
|||
{vol.Required(VALUE): cv.positive_int},
|
||||
"async_set_value",
|
||||
)
|
||||
component.async_register_entity_service(
|
||||
SERVICE_CONFIGURE,
|
||||
{
|
||||
vol.Optional(ATTR_MINIMUM): vol.Any(None, vol.Coerce(int)),
|
||||
vol.Optional(ATTR_MAXIMUM): vol.Any(None, vol.Coerce(int)),
|
||||
vol.Optional(ATTR_STEP): cv.positive_int,
|
||||
vol.Optional(ATTR_INITIAL): cv.positive_int,
|
||||
vol.Optional(VALUE): cv.positive_int,
|
||||
},
|
||||
"async_configure",
|
||||
)
|
||||
|
||||
return True
|
||||
|
||||
|
@ -285,25 +272,6 @@ class Counter(collection.CollectionEntity, RestoreEntity):
|
|||
self._state = value
|
||||
self.async_write_ha_state()
|
||||
|
||||
@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.12.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)
|
||||
self.async_write_ha_state()
|
||||
|
||||
async def async_update_config(self, config: ConfigType) -> None:
|
||||
"""Change the counter's settings WS CRUD."""
|
||||
self._config = config
|
||||
|
|
|
@ -9,15 +9,7 @@ from typing import Any
|
|||
from homeassistant.const import ATTR_ENTITY_ID
|
||||
from homeassistant.core import Context, HomeAssistant, State
|
||||
|
||||
from . import (
|
||||
ATTR_INITIAL,
|
||||
ATTR_MAXIMUM,
|
||||
ATTR_MINIMUM,
|
||||
ATTR_STEP,
|
||||
DOMAIN,
|
||||
SERVICE_CONFIGURE,
|
||||
VALUE,
|
||||
)
|
||||
from . import ATTR_MAXIMUM, ATTR_MINIMUM, ATTR_STEP, DOMAIN, SERVICE_SET_VALUE, VALUE
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
@ -43,7 +35,6 @@ async def _async_reproduce_state(
|
|||
# Return if we are already at the right state.
|
||||
if (
|
||||
cur_state.state == state.state
|
||||
and cur_state.attributes.get(ATTR_INITIAL) == state.attributes.get(ATTR_INITIAL)
|
||||
and cur_state.attributes.get(ATTR_MAXIMUM) == state.attributes.get(ATTR_MAXIMUM)
|
||||
and cur_state.attributes.get(ATTR_MINIMUM) == state.attributes.get(ATTR_MINIMUM)
|
||||
and cur_state.attributes.get(ATTR_STEP) == state.attributes.get(ATTR_STEP)
|
||||
|
@ -51,9 +42,7 @@ async def _async_reproduce_state(
|
|||
return
|
||||
|
||||
service_data = {ATTR_ENTITY_ID: state.entity_id, VALUE: state.state}
|
||||
service = SERVICE_CONFIGURE
|
||||
if ATTR_INITIAL in state.attributes:
|
||||
service_data[ATTR_INITIAL] = state.attributes[ATTR_INITIAL]
|
||||
service = SERVICE_SET_VALUE
|
||||
if ATTR_MAXIMUM in state.attributes:
|
||||
service_data[ATTR_MAXIMUM] = state.attributes[ATTR_MAXIMUM]
|
||||
if ATTR_MINIMUM in state.attributes:
|
||||
|
|
|
@ -26,19 +26,6 @@
|
|||
}
|
||||
}
|
||||
},
|
||||
"issues": {
|
||||
"deprecated_configure_service": {
|
||||
"title": "The counter configure service is being removed",
|
||||
"fix_flow": {
|
||||
"step": {
|
||||
"confirm": {
|
||||
"title": "[%key:component::counter::issues::deprecated_configure_service::title%]",
|
||||
"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 this service from your automations and scripts and select **submit** to close this issue."
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"services": {
|
||||
"decrement": {
|
||||
"name": "Decrement",
|
||||
|
|
|
@ -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, issue_registry as ir
|
||||
from homeassistant.helpers import entity_registry as er
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
from .common import async_decrement, async_increment, async_reset
|
||||
|
@ -432,148 +432,6 @@ 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, 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"}}}
|
||||
)
|
||||
|
||||
state = hass.states.get("counter.test")
|
||||
assert state is not None
|
||||
assert state.state == "10"
|
||||
assert state.attributes.get("maximum") == 10
|
||||
|
||||
# update max
|
||||
await hass.services.async_call(
|
||||
"counter",
|
||||
"configure",
|
||||
{"entity_id": state.entity_id, "maximum": 0},
|
||||
True,
|
||||
Context(user_id=hass_admin_user.id),
|
||||
)
|
||||
|
||||
state = hass.states.get("counter.test")
|
||||
assert state is not 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",
|
||||
"configure",
|
||||
{"entity_id": state.entity_id, "maximum": None},
|
||||
True,
|
||||
Context(user_id=hass_admin_user.id),
|
||||
)
|
||||
|
||||
state = hass.states.get("counter.test")
|
||||
assert state is not None
|
||||
assert state.state == "0"
|
||||
assert state.attributes.get("maximum") is None
|
||||
|
||||
# update min
|
||||
assert state.attributes.get("minimum") is None
|
||||
await hass.services.async_call(
|
||||
"counter",
|
||||
"configure",
|
||||
{"entity_id": state.entity_id, "minimum": 5},
|
||||
True,
|
||||
Context(user_id=hass_admin_user.id),
|
||||
)
|
||||
|
||||
state = hass.states.get("counter.test")
|
||||
assert state is not None
|
||||
assert state.state == "5"
|
||||
assert state.attributes.get("minimum") == 5
|
||||
|
||||
# disable min
|
||||
await hass.services.async_call(
|
||||
"counter",
|
||||
"configure",
|
||||
{"entity_id": state.entity_id, "minimum": None},
|
||||
True,
|
||||
Context(user_id=hass_admin_user.id),
|
||||
)
|
||||
|
||||
state = hass.states.get("counter.test")
|
||||
assert state is not None
|
||||
assert state.state == "5"
|
||||
assert state.attributes.get("minimum") is None
|
||||
|
||||
# update step
|
||||
assert state.attributes.get("step") == 1
|
||||
await hass.services.async_call(
|
||||
"counter",
|
||||
"configure",
|
||||
{"entity_id": state.entity_id, "step": 3},
|
||||
True,
|
||||
Context(user_id=hass_admin_user.id),
|
||||
)
|
||||
|
||||
state = hass.states.get("counter.test")
|
||||
assert state is not None
|
||||
assert state.state == "5"
|
||||
assert state.attributes.get("step") == 3
|
||||
|
||||
# update value
|
||||
await hass.services.async_call(
|
||||
"counter",
|
||||
"configure",
|
||||
{"entity_id": state.entity_id, "value": 6},
|
||||
True,
|
||||
Context(user_id=hass_admin_user.id),
|
||||
)
|
||||
|
||||
state = hass.states.get("counter.test")
|
||||
assert state is not None
|
||||
assert state.state == "6"
|
||||
|
||||
# update initial
|
||||
await hass.services.async_call(
|
||||
"counter",
|
||||
"configure",
|
||||
{"entity_id": state.entity_id, "initial": 5},
|
||||
True,
|
||||
Context(user_id=hass_admin_user.id),
|
||||
)
|
||||
|
||||
state = hass.states.get("counter.test")
|
||||
assert state is not None
|
||||
assert state.state == "6"
|
||||
assert state.attributes.get("initial") == 5
|
||||
|
||||
# update all
|
||||
await hass.services.async_call(
|
||||
"counter",
|
||||
"configure",
|
||||
{
|
||||
"entity_id": state.entity_id,
|
||||
"step": 5,
|
||||
"minimum": 0,
|
||||
"maximum": 9,
|
||||
"value": 5,
|
||||
"initial": 6,
|
||||
},
|
||||
True,
|
||||
Context(user_id=hass_admin_user.id),
|
||||
)
|
||||
|
||||
state = hass.states.get("counter.test")
|
||||
assert state is not None
|
||||
assert state.state == "5"
|
||||
assert state.attributes.get("step") == 5
|
||||
assert state.attributes.get("minimum") == 0
|
||||
assert state.attributes.get("maximum") == 9
|
||||
assert state.attributes.get("initial") == 6
|
||||
|
||||
|
||||
async def test_load_from_storage(hass: HomeAssistant, storage_setup) -> None:
|
||||
"""Test set up from storage."""
|
||||
assert await storage_setup()
|
||||
|
|
|
@ -15,10 +15,10 @@ async def test_reproducing_states(
|
|||
hass.states.async_set(
|
||||
"counter.entity_attr",
|
||||
"8",
|
||||
{"initial": 12, "minimum": 5, "maximum": 15, "step": 3},
|
||||
{"minimum": 5, "maximum": 15, "step": 3},
|
||||
)
|
||||
|
||||
configure_calls = async_mock_service(hass, "counter", "configure")
|
||||
configure_calls = async_mock_service(hass, "counter", "set_value")
|
||||
|
||||
# These calls should do nothing as entities already in desired state
|
||||
await async_reproduce_state(
|
||||
|
@ -28,7 +28,7 @@ async def test_reproducing_states(
|
|||
State(
|
||||
"counter.entity_attr",
|
||||
"8",
|
||||
{"initial": 12, "minimum": 5, "maximum": 15, "step": 3},
|
||||
{"minimum": 5, "maximum": 15, "step": 3},
|
||||
),
|
||||
],
|
||||
)
|
||||
|
@ -49,7 +49,7 @@ async def test_reproducing_states(
|
|||
State(
|
||||
"counter.entity_attr",
|
||||
"7",
|
||||
{"initial": 10, "minimum": 3, "maximum": 21, "step": 5},
|
||||
{"minimum": 3, "maximum": 21, "step": 5},
|
||||
),
|
||||
# Should not raise
|
||||
State("counter.non_existing", "6"),
|
||||
|
@ -61,7 +61,6 @@ async def test_reproducing_states(
|
|||
{
|
||||
"entity_id": "counter.entity_attr",
|
||||
"value": "7",
|
||||
"initial": 10,
|
||||
"minimum": 3,
|
||||
"maximum": 21,
|
||||
"step": 5,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue