Remove previously deprecated ISY994 services (#91569)

This commit is contained in:
shbatm 2023-04-17 16:43:01 -05:00 committed by GitHub
parent da4c144a5e
commit c663f7677c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 6 additions and 464 deletions

View File

@ -10,19 +10,13 @@ from pyisy.nodes import Node
from homeassistant.components.light import ColorMode, LightEntity
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import Platform
from homeassistant.core import HomeAssistant, ServiceCall, callback
from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers.entity import DeviceInfo
from homeassistant.helpers.entity_platform import AddEntitiesCallback
import homeassistant.helpers.entity_registry as er
from homeassistant.helpers.restore_state import RestoreEntity
from .const import _LOGGER, CONF_RESTORE_LIGHT_STATE, DOMAIN, UOM_PERCENTAGE
from .entity import ISYNodeEntity
from .services import (
SERVICE_SET_ON_LEVEL,
async_log_deprecated_service_call,
async_setup_light_services,
)
ATTR_LAST_BRIGHTNESS = "last_brightness"
@ -43,7 +37,6 @@ async def async_setup_entry(
)
async_add_entities(entities)
async_setup_light_services(hass)
class ISYLightEntity(ISYNodeEntity, LightEntity, RestoreEntity):
@ -127,35 +120,3 @@ class ISYLightEntity(ISYNodeEntity, LightEntity, RestoreEntity):
and last_state.attributes[ATTR_LAST_BRIGHTNESS]
):
self._last_brightness = last_state.attributes[ATTR_LAST_BRIGHTNESS]
async def async_set_on_level(self, value: int) -> None:
"""Set the ON Level for a device."""
entity_registry = er.async_get(self.hass)
async_log_deprecated_service_call(
self.hass,
call=ServiceCall(domain=DOMAIN, service=SERVICE_SET_ON_LEVEL),
alternate_service="number.set_value",
alternate_target=entity_registry.async_get_entity_id(
Platform.NUMBER,
DOMAIN,
f"{self._node.isy.uuid}_{self._node.address}_OL",
),
breaks_in_ha_version="2023.5.0",
)
await self._node.set_on_level(value)
async def async_set_ramp_rate(self, value: int) -> None:
"""Set the Ramp Rate for a device."""
entity_registry = er.async_get(self.hass)
async_log_deprecated_service_call(
self.hass,
call=ServiceCall(domain=DOMAIN, service=SERVICE_SET_ON_LEVEL),
alternate_service="select.select_option",
alternate_target=entity_registry.async_get_entity_id(
Platform.NUMBER,
DOMAIN,
f"{self._node.isy.uuid}_{self._node.address}_RR",
),
breaks_in_ha_version="2023.5.0",
)
await self._node.set_ramp_rate(value)

View File

@ -10,36 +10,17 @@ from homeassistant.const import (
CONF_ADDRESS,
CONF_COMMAND,
CONF_NAME,
CONF_TYPE,
CONF_UNIT_OF_MEASUREMENT,
SERVICE_RELOAD,
Platform,
)
from homeassistant.core import HomeAssistant, ServiceCall, callback
from homeassistant.helpers import entity_platform
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.entity_platform import async_get_platforms
import homeassistant.helpers.entity_registry as er
from homeassistant.helpers.issue_registry import IssueSeverity, async_create_issue
from homeassistant.helpers.service import entity_service_call
from .const import _LOGGER, CONF_NETWORK, DOMAIN, ISY_CONF_NAME
from .util import _async_cleanup_registry_entries
from .const import _LOGGER, DOMAIN
# Common Services for All Platforms:
SERVICE_SYSTEM_QUERY = "system_query"
SERVICE_SET_VARIABLE = "set_variable"
SERVICE_SEND_PROGRAM_COMMAND = "send_program_command"
SERVICE_RUN_NETWORK_RESOURCE = "run_network_resource"
SERVICE_CLEANUP = "cleanup_entities"
INTEGRATION_SERVICES = [
SERVICE_SYSTEM_QUERY,
SERVICE_SET_VARIABLE,
SERVICE_SEND_PROGRAM_COMMAND,
SERVICE_RUN_NETWORK_RESOURCE,
SERVICE_CLEANUP,
]
# Entity specific methods (valid for most Groups/ISY Scenes, Lights, Switches, Fans)
SERVICE_SEND_RAW_NODE_COMMAND = "send_raw_node_command"
@ -48,10 +29,6 @@ SERVICE_GET_ZWAVE_PARAMETER = "get_zwave_parameter"
SERVICE_SET_ZWAVE_PARAMETER = "set_zwave_parameter"
SERVICE_RENAME_NODE = "rename_node"
# Services valid only for dimmable lights.
SERVICE_SET_ON_LEVEL = "set_on_level"
SERVICE_SET_RAMP_RATE = "set_ramp_rate"
# Services valid only for Z-Wave Locks
SERVICE_SET_ZWAVE_LOCK_USER_CODE = "set_zwave_lock_user_code"
SERVICE_DELETE_ZWAVE_LOCK_USER_CODE = "delete_zwave_lock_user_code"
@ -102,18 +79,6 @@ def valid_isy_commands(value: Any) -> str:
SCHEMA_GROUP = "name-address"
SERVICE_SYSTEM_QUERY_SCHEMA = vol.Schema(
{vol.Optional(CONF_ADDRESS): cv.string, vol.Optional(CONF_ISY): cv.string}
)
SERVICE_SET_RAMP_RATE_SCHEMA = {
vol.Required(CONF_VALUE): vol.All(vol.Coerce(int), vol.Range(0, 31))
}
SERVICE_SET_VALUE_SCHEMA = {
vol.Required(CONF_VALUE): vol.All(vol.Coerce(int), vol.Range(0, 255))
}
SERVICE_SEND_RAW_NODE_COMMAND_SCHEMA = {
vol.Required(CONF_COMMAND): vol.All(cv.string, valid_isy_commands),
vol.Optional(CONF_VALUE): vol.All(vol.Coerce(int), vol.Range(0, 255)),
@ -142,22 +107,6 @@ SERVICE_SET_USER_CODE_SCHEMA = {
SERVICE_DELETE_USER_CODE_SCHEMA = {vol.Required(CONF_USER_NUM): vol.Coerce(int)}
SERVICE_SET_VARIABLE_SCHEMA = vol.All(
cv.has_at_least_one_key(CONF_ADDRESS, CONF_TYPE, CONF_NAME),
vol.Schema(
{
vol.Exclusive(CONF_NAME, SCHEMA_GROUP): cv.string,
vol.Inclusive(CONF_ADDRESS, SCHEMA_GROUP): vol.Coerce(int),
vol.Inclusive(CONF_TYPE, SCHEMA_GROUP): vol.All(
vol.Coerce(int), vol.Range(1, 2)
),
vol.Optional(CONF_INIT, default=False): bool,
vol.Required(CONF_VALUE): vol.Coerce(int),
vol.Optional(CONF_ISY): cv.string,
}
),
)
SERVICE_SEND_PROGRAM_COMMAND_SCHEMA = vol.All(
cv.has_at_least_one_key(CONF_ADDRESS, CONF_NAME),
vol.Schema(
@ -170,108 +119,15 @@ SERVICE_SEND_PROGRAM_COMMAND_SCHEMA = vol.All(
),
)
SERVICE_RUN_NETWORK_RESOURCE_SCHEMA = vol.All(
cv.has_at_least_one_key(CONF_ADDRESS, CONF_NAME),
vol.Schema(
{
vol.Exclusive(CONF_NAME, SCHEMA_GROUP): cv.string,
vol.Exclusive(CONF_ADDRESS, SCHEMA_GROUP): vol.Coerce(int),
vol.Optional(CONF_ISY): cv.string,
}
),
)
@callback
def async_setup_services(hass: HomeAssistant) -> None: # noqa: C901
"""Create and register services for the ISY integration."""
existing_services = hass.services.async_services().get(DOMAIN)
if existing_services and any(
service in INTEGRATION_SERVICES for service in existing_services
):
if existing_services and SERVICE_SEND_PROGRAM_COMMAND in existing_services:
# Integration-level services have already been added. Return.
return
async def async_system_query_service_handler(service: ServiceCall) -> None:
"""Handle a system query service call."""
address = service.data.get(CONF_ADDRESS)
isy_name = service.data.get(CONF_ISY)
entity_registry = er.async_get(hass)
for config_entry_id in hass.data[DOMAIN]:
isy_data = hass.data[DOMAIN][config_entry_id]
isy = isy_data.root
if isy_name and isy_name != isy.conf["name"]:
continue
# If an address is provided, make sure we query the correct ISY.
# Otherwise, query the whole system on all ISY's connected.
if address and isy.nodes.get_by_id(address) is not None:
_LOGGER.debug(
"Requesting query of device %s on ISY %s",
address,
isy.uuid,
)
await isy.query(address)
async_log_deprecated_service_call(
hass,
call=service,
alternate_service="button.press",
alternate_target=entity_registry.async_get_entity_id(
Platform.BUTTON,
DOMAIN,
f"{isy.uuid}_{address}_query",
),
breaks_in_ha_version="2023.5.0",
)
return
_LOGGER.debug("Requesting system query of ISY %s", isy.uuid)
await isy.query()
async_log_deprecated_service_call(
hass,
call=service,
alternate_service="button.press",
alternate_target=entity_registry.async_get_entity_id(
Platform.BUTTON, DOMAIN, f"{isy.uuid}_query"
),
breaks_in_ha_version="2023.5.0",
)
async def async_run_network_resource_service_handler(service: ServiceCall) -> None:
"""Handle a network resource service call."""
address = service.data.get(CONF_ADDRESS)
name = service.data.get(CONF_NAME)
isy_name = service.data.get(CONF_ISY)
for config_entry_id in hass.data[DOMAIN]:
isy_data = hass.data[DOMAIN][config_entry_id]
isy = isy_data.root
if isy_name and isy_name != isy.conf[ISY_CONF_NAME]:
continue
if isy.networking is None:
continue
command = None
if address:
command = isy.networking.get_by_id(address)
if name:
command = isy.networking.get_by_name(name)
if command is not None:
await command.run()
entity_registry = er.async_get(hass)
async_log_deprecated_service_call(
hass,
call=service,
alternate_service="button.press",
alternate_target=entity_registry.async_get_entity_id(
Platform.BUTTON,
DOMAIN,
f"{isy.uuid}_{CONF_NETWORK}_{address}",
),
breaks_in_ha_version="2023.5.0",
)
return
_LOGGER.error(
"Could not run network resource command; not found or enabled on the ISY"
)
async def async_send_program_command_service_handler(service: ServiceCall) -> None:
"""Handle a send program command service call."""
address = service.data.get(CONF_ADDRESS)
@ -294,81 +150,6 @@ def async_setup_services(hass: HomeAssistant) -> None: # noqa: C901
return
_LOGGER.error("Could not send program command; not found or enabled on the ISY")
async def async_set_variable_service_handler(service: ServiceCall) -> None:
"""Handle a set variable service call."""
address = service.data.get(CONF_ADDRESS)
vtype = service.data.get(CONF_TYPE)
name = service.data.get(CONF_NAME)
value = service.data.get(CONF_VALUE)
init = service.data.get(CONF_INIT, False)
isy_name = service.data.get(CONF_ISY)
for config_entry_id in hass.data[DOMAIN]:
isy_data = hass.data[DOMAIN][config_entry_id]
isy = isy_data.root
if isy_name and isy_name != isy.conf["name"]:
continue
variable = None
if name:
variable = isy.variables.get_by_name(name)
if address and vtype:
variable = isy.variables.vobjs[vtype].get(address)
if variable is not None:
await variable.set_value(value, init)
entity_registry = er.async_get(hass)
async_log_deprecated_service_call(
hass,
call=service,
alternate_service="number.set_value",
alternate_target=entity_registry.async_get_entity_id(
Platform.NUMBER,
DOMAIN,
f"{isy.uuid}_{address}{'_init' if init else ''}",
),
breaks_in_ha_version="2023.5.0",
)
return
_LOGGER.error("Could not set variable value; not found or enabled on the ISY")
@callback
def async_cleanup_registry_entries(service: ServiceCall) -> None:
"""Remove extra entities that are no longer part of the integration."""
async_log_deprecated_service_call(
hass,
call=service,
alternate_service="homeassistant.reload_core_config",
alternate_target=None,
breaks_in_ha_version="2023.5.0",
)
for config_entry_id in hass.data[DOMAIN]:
_async_cleanup_registry_entries(hass, config_entry_id)
async def async_reload_config_entries(service: ServiceCall) -> None:
"""Trigger a reload of all ISY config entries."""
async_log_deprecated_service_call(
hass,
call=service,
alternate_service="homeassistant.reload_core_config",
alternate_target=None,
breaks_in_ha_version="2023.5.0",
)
for config_entry_id in hass.data[DOMAIN]:
hass.async_create_task(hass.config_entries.async_reload(config_entry_id))
hass.services.async_register(
domain=DOMAIN,
service=SERVICE_SYSTEM_QUERY,
service_func=async_system_query_service_handler,
schema=SERVICE_SYSTEM_QUERY_SCHEMA,
)
hass.services.async_register(
domain=DOMAIN,
service=SERVICE_RUN_NETWORK_RESOURCE,
service_func=async_run_network_resource_service_handler,
schema=SERVICE_RUN_NETWORK_RESOURCE_SCHEMA,
)
hass.services.async_register(
domain=DOMAIN,
service=SERVICE_SEND_PROGRAM_COMMAND,
@ -376,23 +157,6 @@ def async_setup_services(hass: HomeAssistant) -> None: # noqa: C901
schema=SERVICE_SEND_PROGRAM_COMMAND_SCHEMA,
)
hass.services.async_register(
domain=DOMAIN,
service=SERVICE_SET_VARIABLE,
service_func=async_set_variable_service_handler,
schema=SERVICE_SET_VARIABLE_SCHEMA,
)
hass.services.async_register(
domain=DOMAIN,
service=SERVICE_CLEANUP,
service_func=async_cleanup_registry_entries,
)
hass.services.async_register(
domain=DOMAIN, service=SERVICE_RELOAD, service_func=async_reload_config_entries
)
async def _async_send_raw_node_command(call: ServiceCall) -> None:
await entity_service_call(
hass, async_get_platforms(hass, DOMAIN), "async_send_raw_node_command", call
@ -462,74 +226,12 @@ def async_unload_services(hass: HomeAssistant) -> None:
return
existing_services = hass.services.async_services().get(DOMAIN)
if not existing_services or not any(
service in INTEGRATION_SERVICES for service in existing_services
):
if not existing_services or SERVICE_SEND_PROGRAM_COMMAND not in existing_services:
return
_LOGGER.info("Unloading ISY994 Services")
hass.services.async_remove(domain=DOMAIN, service=SERVICE_SYSTEM_QUERY)
hass.services.async_remove(domain=DOMAIN, service=SERVICE_RUN_NETWORK_RESOURCE)
hass.services.async_remove(domain=DOMAIN, service=SERVICE_SEND_PROGRAM_COMMAND)
hass.services.async_remove(domain=DOMAIN, service=SERVICE_SET_VARIABLE)
hass.services.async_remove(domain=DOMAIN, service=SERVICE_CLEANUP)
hass.services.async_remove(domain=DOMAIN, service=SERVICE_RELOAD)
hass.services.async_remove(domain=DOMAIN, service=SERVICE_SEND_RAW_NODE_COMMAND)
hass.services.async_remove(domain=DOMAIN, service=SERVICE_SEND_NODE_COMMAND)
@callback
def async_setup_light_services(hass: HomeAssistant) -> None:
"""Create device-specific services for the ISY Integration."""
platform = entity_platform.async_get_current_platform()
platform.async_register_entity_service(
SERVICE_SET_ON_LEVEL, SERVICE_SET_VALUE_SCHEMA, "async_set_on_level"
)
platform.async_register_entity_service(
SERVICE_SET_RAMP_RATE, SERVICE_SET_RAMP_RATE_SCHEMA, "async_set_ramp_rate"
)
@callback
def async_log_deprecated_service_call(
hass: HomeAssistant,
call: ServiceCall,
alternate_service: str,
alternate_target: str | None,
breaks_in_ha_version: str,
) -> None:
"""Log a warning about a deprecated service call."""
deprecated_service = f"{call.domain}.{call.service}"
alternate_target = alternate_target or "this device"
async_create_issue(
hass,
DOMAIN,
f"deprecated_service_{deprecated_service}",
breaks_in_ha_version=breaks_in_ha_version,
is_fixable=True,
is_persistent=True,
severity=IssueSeverity.WARNING,
translation_key="deprecated_service",
translation_placeholders={
"alternate_service": alternate_service,
"alternate_target": alternate_target,
"deprecated_service": deprecated_service,
},
)
alternate_text = ""
if alternate_target:
alternate_text = f' and pass it a target entity ID of "{alternate_target}"'
_LOGGER.warning(
(
'The "%s" service is deprecated and will be removed in %s; use the "%s" '
"service %s"
),
deprecated_service,
breaks_in_ha_version,
alternate_service,
alternate_text,
)
hass.services.async_remove(domain=DOMAIN, service=SERVICE_GET_ZWAVE_PARAMETER)
hass.services.async_remove(domain=DOMAIN, service=SERVICE_SET_ZWAVE_PARAMETER)

View File

@ -181,98 +181,6 @@ rename_node:
example: "Front Door Light"
selector:
text:
set_on_level:
name: Set On Level (Deprecated)
description: "Send a ISY set_on_level command to a Node. Deprecated: Use On Level Number entity instead."
target:
entity:
integration: isy994
domain: light
fields:
value:
name: Value
description: integer value to set.
required: true
selector:
number:
min: 0
max: 255
set_ramp_rate:
name: Set ramp rate (Deprecated)
description: "Send a ISY set_ramp_rate command to a Node. Deprecated: Use On Level Number entity instead."
target:
entity:
integration: isy994
domain: light
fields:
value:
name: Value
description: Integer value to set, see PyISY/ISY documentation for values to actual ramp times.
required: true
selector:
number:
min: 0
max: 31
system_query:
name: System query (Deprecated)
description: "Request the ISY Query the connected devices. Deprecated: Use device Query button entity."
fields:
address:
name: Address
description: ISY Address to Query. Omitting this requests a system-wide scan (typically scheduled once per day).
example: "1A 2B 3C 1"
selector:
text:
isy:
name: ISY
description: If you have more than one ISY connected, provide the name of the ISY to query (as shown on the Device Registry or as the top-first node in the ISY Admin Console). Omitting this will cause all ISYs to be queried.
example: "ISY"
selector:
text:
set_variable:
name: Set variable (Deprecated)
description: "Set an ISY variable's current or initial value. Variables can be set by either type/address or by name. Deprecated: Use number entities instead."
fields:
address:
name: Address
description: The address of the variable for which to set the value.
selector:
number:
min: 0
max: 255
type:
name: Type
description: The variable type, 1 = Integer, 2 = State.
selector:
number:
min: 1
max: 2
name:
name: Name
description: The name of the variable to set (use instead of type/address).
example: "my_variable_name"
selector:
text:
init:
name: Init
description: If True, the initial (init) value will be updated instead of the current value.
default: false
selector:
boolean:
value:
name: Value
description: The integer value to be sent.
required: true
selector:
number:
min: 0
max: 255
isy:
name: ISY
description: If you have more than one ISY connected, provide the name of the ISY to query (as shown on the Device Registry or as the top-first node in the ISY Admin Console). If you have the same variable name or address on multiple ISYs, omitting this will run the command on them all.
example: "ISY"
selector:
text:
send_program_command:
name: Send program command
description: >-
@ -312,32 +220,3 @@ send_program_command:
example: "ISY"
selector:
text:
run_network_resource:
name: Run network resource (Deprecated)
description: "Run a network resource on the ISY. Deprecated: Use Network Resource button entity."
fields:
address:
name: Address
description: The address of the network resource to execute (use either address or name).
selector:
number:
min: 0
max: 255
name:
name: Name
description: The name of the network resource to execute (use either address or name).
example: "Network Resource 1"
selector:
text:
isy:
name: ISY
description: If you have more than one ISY connected, provide the name of the ISY to query (as shown on the Device Registry or as the top-first node in the ISY Admin Console). If you have the same resource name or address on multiple ISYs, omitting this will run the command on them all.
example: "ISY"
selector:
text:
reload:
name: Reload
description: Reload the ISY connection(s) without restarting Home Assistant. Use to pick up new devices that have been added or changed on the ISY.
cleanup_entities:
name: Cleanup entities
description: Cleanup old entities and devices no longer used by the ISY integration. Useful if you've removed devices from the ISY or changed the options in the configuration to exclude additional items.