mirror of
https://github.com/home-assistant/core.git
synced 2025-07-13 08:17:08 +00:00
Deprecate counter.configure service (#93343)
This commit is contained in:
parent
6df030a455
commit
f2899a19c1
@ -18,6 +18,7 @@ from homeassistant.core import HomeAssistant, callback
|
|||||||
from homeassistant.helpers import collection
|
from homeassistant.helpers import collection
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
from homeassistant.helpers.entity_component import EntityComponent
|
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.restore_state import RestoreEntity
|
||||||
from homeassistant.helpers.storage import Store
|
from homeassistant.helpers.storage import Store
|
||||||
from homeassistant.helpers.typing import ConfigType
|
from homeassistant.helpers.typing import ConfigType
|
||||||
@ -291,6 +292,17 @@ class Counter(collection.CollectionEntity, RestoreEntity):
|
|||||||
@callback
|
@callback
|
||||||
def async_configure(self, **kwargs) -> None:
|
def async_configure(self, **kwargs) -> None:
|
||||||
"""Change the counter's settings with a service."""
|
"""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)
|
new_state = kwargs.pop(VALUE, self._state)
|
||||||
self._config = {**self._config, **kwargs}
|
self._config = {**self._config, **kwargs}
|
||||||
self._state = self.compute_next_state(new_state)
|
self._state = self.compute_next_state(new_state)
|
||||||
|
@ -37,51 +37,3 @@ set_value:
|
|||||||
min: 0
|
min: 0
|
||||||
max: 9223372036854775807
|
max: 9223372036854775807
|
||||||
mode: box
|
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
|
|
||||||
|
@ -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."
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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.const import ATTR_ENTITY_ID, ATTR_FRIENDLY_NAME, ATTR_ICON, ATTR_NAME
|
||||||
from homeassistant.core import Context, CoreState, HomeAssistant, State
|
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 homeassistant.setup import async_setup_component
|
||||||
|
|
||||||
from .common import async_decrement, async_increment, async_reset
|
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"
|
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."""
|
"""Test that setting values through configure works."""
|
||||||
assert await async_setup_component(
|
assert await async_setup_component(
|
||||||
hass, "counter", {"counter": {"test": {"maximum": "10", "initial": "10"}}}
|
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.state == "0"
|
||||||
assert state.attributes.get("maximum") == 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
|
# disable max
|
||||||
await hass.services.async_call(
|
await hass.services.async_call(
|
||||||
"counter",
|
"counter",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user