Remove support for area, device, or entity targets for screenlogic actions (#123432)
* Remove non-configentry service target * Remove unneeded tests * Remove unneeded issue strings
This commit is contained in:
parent
c4cc158a77
commit
f6c681eb5d
4 changed files with 7 additions and 133 deletions
|
@ -10,12 +10,7 @@ import voluptuous as vol
|
||||||
from homeassistant.config_entries import ConfigEntryState
|
from homeassistant.config_entries import ConfigEntryState
|
||||||
from homeassistant.core import HomeAssistant, ServiceCall, callback
|
from homeassistant.core import HomeAssistant, ServiceCall, callback
|
||||||
from homeassistant.exceptions import HomeAssistantError, ServiceValidationError
|
from homeassistant.exceptions import HomeAssistantError, ServiceValidationError
|
||||||
from homeassistant.helpers import (
|
from homeassistant.helpers import selector
|
||||||
config_validation as cv,
|
|
||||||
issue_registry as ir,
|
|
||||||
selector,
|
|
||||||
)
|
|
||||||
from homeassistant.helpers.service import async_extract_config_entry_ids
|
|
||||||
|
|
||||||
from .const import (
|
from .const import (
|
||||||
ATTR_COLOR_MODE,
|
ATTR_COLOR_MODE,
|
||||||
|
@ -44,19 +39,10 @@ BASE_SERVICE_SCHEMA = vol.Schema(
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
SET_COLOR_MODE_SCHEMA = vol.All(
|
SET_COLOR_MODE_SCHEMA = BASE_SERVICE_SCHEMA.extend(
|
||||||
vol.Schema(
|
|
||||||
{
|
{
|
||||||
vol.Optional(ATTR_CONFIG_ENTRY): selector.ConfigEntrySelector(
|
|
||||||
{
|
|
||||||
"integration": DOMAIN,
|
|
||||||
}
|
|
||||||
),
|
|
||||||
**cv.ENTITY_SERVICE_FIELDS,
|
|
||||||
vol.Required(ATTR_COLOR_MODE): vol.In(SUPPORTED_COLOR_MODES),
|
vol.Required(ATTR_COLOR_MODE): vol.In(SUPPORTED_COLOR_MODES),
|
||||||
}
|
}
|
||||||
),
|
|
||||||
cv.has_at_least_one_key(ATTR_CONFIG_ENTRY, *cv.ENTITY_SERVICE_FIELDS),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
TURN_ON_SUPER_CHLOR_SCHEMA = BASE_SERVICE_SCHEMA.extend(
|
TURN_ON_SUPER_CHLOR_SCHEMA = BASE_SERVICE_SCHEMA.extend(
|
||||||
|
@ -72,37 +58,10 @@ TURN_ON_SUPER_CHLOR_SCHEMA = BASE_SERVICE_SCHEMA.extend(
|
||||||
def async_load_screenlogic_services(hass: HomeAssistant):
|
def async_load_screenlogic_services(hass: HomeAssistant):
|
||||||
"""Set up services for the ScreenLogic integration."""
|
"""Set up services for the ScreenLogic integration."""
|
||||||
|
|
||||||
async def extract_screenlogic_config_entry_ids(service_call: ServiceCall):
|
|
||||||
if not (
|
|
||||||
screenlogic_entry_ids := await async_extract_config_entry_ids(
|
|
||||||
hass, service_call
|
|
||||||
)
|
|
||||||
):
|
|
||||||
raise ServiceValidationError(
|
|
||||||
f"Failed to call service '{service_call.service}'. Config entry for "
|
|
||||||
"target not found"
|
|
||||||
)
|
|
||||||
return screenlogic_entry_ids
|
|
||||||
|
|
||||||
async def get_coordinators(
|
async def get_coordinators(
|
||||||
service_call: ServiceCall,
|
service_call: ServiceCall,
|
||||||
) -> list[ScreenlogicDataUpdateCoordinator]:
|
) -> list[ScreenlogicDataUpdateCoordinator]:
|
||||||
entry_ids: set[str]
|
entry_ids = {service_call.data[ATTR_CONFIG_ENTRY]}
|
||||||
if entry_id := service_call.data.get(ATTR_CONFIG_ENTRY):
|
|
||||||
entry_ids = {entry_id}
|
|
||||||
else:
|
|
||||||
ir.async_create_issue(
|
|
||||||
hass,
|
|
||||||
DOMAIN,
|
|
||||||
"service_target_deprecation",
|
|
||||||
breaks_in_ha_version="2024.8.0",
|
|
||||||
is_fixable=True,
|
|
||||||
is_persistent=True,
|
|
||||||
severity=ir.IssueSeverity.WARNING,
|
|
||||||
translation_key="service_target_deprecation",
|
|
||||||
)
|
|
||||||
entry_ids = await extract_screenlogic_config_entry_ids(service_call)
|
|
||||||
|
|
||||||
coordinators: list[ScreenlogicDataUpdateCoordinator] = []
|
coordinators: list[ScreenlogicDataUpdateCoordinator] = []
|
||||||
for entry_id in entry_ids:
|
for entry_id in entry_ids:
|
||||||
config_entry = cast(
|
config_entry = cast(
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
set_color_mode:
|
set_color_mode:
|
||||||
fields:
|
fields:
|
||||||
config_entry:
|
config_entry:
|
||||||
required: false
|
required: true
|
||||||
selector:
|
selector:
|
||||||
config_entry:
|
config_entry:
|
||||||
integration: screenlogic
|
integration: screenlogic
|
||||||
|
|
|
@ -75,18 +75,5 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
|
||||||
"issues": {
|
|
||||||
"service_target_deprecation": {
|
|
||||||
"title": "Deprecating use of target for ScreenLogic actions",
|
|
||||||
"fix_flow": {
|
|
||||||
"step": {
|
|
||||||
"confirm": {
|
|
||||||
"title": "Deprecating target for ScreenLogic actions",
|
|
||||||
"description": "Use of an Area, Device, or Entity as a target for ScreenLogic actions is being deprecated. Instead, use `config_entry` with the entry_id of the desired ScreenLogic integration.\n\nPlease update your automations and scripts and select **submit** to fix this issue."
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,11 +18,9 @@ from homeassistant.components.screenlogic.const import (
|
||||||
SERVICE_STOP_SUPER_CHLORINATION,
|
SERVICE_STOP_SUPER_CHLORINATION,
|
||||||
)
|
)
|
||||||
from homeassistant.config_entries import ConfigEntryState
|
from homeassistant.config_entries import ConfigEntryState
|
||||||
from homeassistant.const import ATTR_AREA_ID, ATTR_DEVICE_ID, ATTR_ENTITY_ID, Platform
|
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.exceptions import ServiceValidationError
|
from homeassistant.exceptions import ServiceValidationError
|
||||||
from homeassistant.helpers import device_registry as dr
|
from homeassistant.helpers import device_registry as dr
|
||||||
from homeassistant.util import slugify
|
|
||||||
|
|
||||||
from . import (
|
from . import (
|
||||||
DATA_FULL_CHEM,
|
DATA_FULL_CHEM,
|
||||||
|
@ -102,22 +100,6 @@ async def setup_screenlogic_services_fixture(
|
||||||
},
|
},
|
||||||
None,
|
None,
|
||||||
),
|
),
|
||||||
(
|
|
||||||
{
|
|
||||||
ATTR_COLOR_MODE: COLOR_MODE.ALL_ON.name.lower(),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
ATTR_AREA_ID: MOCK_DEVICE_AREA,
|
|
||||||
},
|
|
||||||
),
|
|
||||||
(
|
|
||||||
{
|
|
||||||
ATTR_COLOR_MODE: COLOR_MODE.ALL_ON.name.lower(),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
ATTR_ENTITY_ID: f"{Platform.SENSOR}.{slugify(f'{MOCK_ADAPTER_NAME} Air Temperature')}",
|
|
||||||
},
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
async def test_service_set_color_mode(
|
async def test_service_set_color_mode(
|
||||||
|
@ -148,30 +130,6 @@ async def test_service_set_color_mode(
|
||||||
mocked_async_set_color_lights.assert_awaited_once()
|
mocked_async_set_color_lights.assert_awaited_once()
|
||||||
|
|
||||||
|
|
||||||
async def test_service_set_color_mode_with_device(
|
|
||||||
hass: HomeAssistant,
|
|
||||||
service_fixture: dict[str, Any],
|
|
||||||
) -> None:
|
|
||||||
"""Test set_color_mode service with a device target."""
|
|
||||||
mocked_async_set_color_lights: AsyncMock = service_fixture["gateway"][
|
|
||||||
"async_set_color_lights"
|
|
||||||
]
|
|
||||||
|
|
||||||
assert hass.services.has_service(DOMAIN, SERVICE_SET_COLOR_MODE)
|
|
||||||
|
|
||||||
sl_device: dr.DeviceEntry = service_fixture["device"]
|
|
||||||
|
|
||||||
await hass.services.async_call(
|
|
||||||
DOMAIN,
|
|
||||||
SERVICE_SET_COLOR_MODE,
|
|
||||||
service_data={ATTR_COLOR_MODE: COLOR_MODE.ALL_ON.name.lower()},
|
|
||||||
blocking=True,
|
|
||||||
target={ATTR_DEVICE_ID: sl_device.id},
|
|
||||||
)
|
|
||||||
|
|
||||||
mocked_async_set_color_lights.assert_awaited_once()
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
("data", "target", "error_msg"),
|
("data", "target", "error_msg"),
|
||||||
[
|
[
|
||||||
|
@ -193,36 +151,6 @@ async def test_service_set_color_mode_with_device(
|
||||||
f"Failed to call service '{SERVICE_SET_COLOR_MODE}'. Config entry "
|
f"Failed to call service '{SERVICE_SET_COLOR_MODE}'. Config entry "
|
||||||
"'test' is not a screenlogic config",
|
"'test' is not a screenlogic config",
|
||||||
),
|
),
|
||||||
(
|
|
||||||
{
|
|
||||||
ATTR_COLOR_MODE: COLOR_MODE.ALL_ON.name.lower(),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
ATTR_AREA_ID: "invalidareaid",
|
|
||||||
},
|
|
||||||
f"Failed to call service '{SERVICE_SET_COLOR_MODE}'. Config entry for "
|
|
||||||
"target not found",
|
|
||||||
),
|
|
||||||
(
|
|
||||||
{
|
|
||||||
ATTR_COLOR_MODE: COLOR_MODE.ALL_ON.name.lower(),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
ATTR_DEVICE_ID: "invaliddeviceid",
|
|
||||||
},
|
|
||||||
f"Failed to call service '{SERVICE_SET_COLOR_MODE}'. Config entry for "
|
|
||||||
"target not found",
|
|
||||||
),
|
|
||||||
(
|
|
||||||
{
|
|
||||||
ATTR_COLOR_MODE: COLOR_MODE.ALL_ON.name.lower(),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
ATTR_ENTITY_ID: "sensor.invalidentityid",
|
|
||||||
},
|
|
||||||
f"Failed to call service '{SERVICE_SET_COLOR_MODE}'. Config entry for "
|
|
||||||
"target not found",
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
async def test_service_set_color_mode_error(
|
async def test_service_set_color_mode_error(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue