mirror of
https://github.com/home-assistant/core.git
synced 2025-07-13 16:27:08 +00:00
Fix isy994 send_node_command (#39806)
This commit is contained in:
parent
f1de903fb5
commit
a5dec53e1b
@ -49,7 +49,6 @@ from .const import (
|
|||||||
)
|
)
|
||||||
from .entity import ISYNodeEntity, ISYProgramEntity
|
from .entity import ISYNodeEntity, ISYProgramEntity
|
||||||
from .helpers import migrate_old_unique_ids
|
from .helpers import migrate_old_unique_ids
|
||||||
from .services import async_setup_device_services
|
|
||||||
|
|
||||||
DEVICE_PARENT_REQUIRED = [
|
DEVICE_PARENT_REQUIRED = [
|
||||||
DEVICE_CLASS_OPENING,
|
DEVICE_CLASS_OPENING,
|
||||||
@ -172,7 +171,6 @@ async def async_setup_entry(
|
|||||||
|
|
||||||
await migrate_old_unique_ids(hass, BINARY_SENSOR, devices)
|
await migrate_old_unique_ids(hass, BINARY_SENSOR, devices)
|
||||||
async_add_entities(devices)
|
async_add_entities(devices)
|
||||||
async_setup_device_services(hass)
|
|
||||||
|
|
||||||
|
|
||||||
def _detect_device_type_and_class(node: Union[Group, Node]) -> (str, str):
|
def _detect_device_type_and_class(node: Union[Group, Node]) -> (str, str):
|
||||||
|
@ -52,7 +52,6 @@ from .const import (
|
|||||||
)
|
)
|
||||||
from .entity import ISYNodeEntity
|
from .entity import ISYNodeEntity
|
||||||
from .helpers import convert_isy_value_to_hass, migrate_old_unique_ids
|
from .helpers import convert_isy_value_to_hass, migrate_old_unique_ids
|
||||||
from .services import async_setup_device_services
|
|
||||||
|
|
||||||
ISY_SUPPORTED_FEATURES = (
|
ISY_SUPPORTED_FEATURES = (
|
||||||
SUPPORT_FAN_MODE | SUPPORT_TARGET_TEMPERATURE | SUPPORT_TARGET_TEMPERATURE_RANGE
|
SUPPORT_FAN_MODE | SUPPORT_TARGET_TEMPERATURE | SUPPORT_TARGET_TEMPERATURE_RANGE
|
||||||
@ -73,7 +72,6 @@ async def async_setup_entry(
|
|||||||
|
|
||||||
await migrate_old_unique_ids(hass, CLIMATE, entities)
|
await migrate_old_unique_ids(hass, CLIMATE, entities)
|
||||||
async_add_entities(entities)
|
async_add_entities(entities)
|
||||||
async_setup_device_services(hass)
|
|
||||||
|
|
||||||
|
|
||||||
class ISYThermostatEntity(ISYNodeEntity, ClimateEntity):
|
class ISYThermostatEntity(ISYNodeEntity, ClimateEntity):
|
||||||
|
@ -24,7 +24,6 @@ from .const import (
|
|||||||
)
|
)
|
||||||
from .entity import ISYNodeEntity, ISYProgramEntity
|
from .entity import ISYNodeEntity, ISYProgramEntity
|
||||||
from .helpers import migrate_old_unique_ids
|
from .helpers import migrate_old_unique_ids
|
||||||
from .services import async_setup_device_services
|
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(
|
async def async_setup_entry(
|
||||||
@ -43,7 +42,6 @@ async def async_setup_entry(
|
|||||||
|
|
||||||
await migrate_old_unique_ids(hass, COVER, devices)
|
await migrate_old_unique_ids(hass, COVER, devices)
|
||||||
async_add_entities(devices)
|
async_add_entities(devices)
|
||||||
async_setup_device_services(hass)
|
|
||||||
|
|
||||||
|
|
||||||
class ISYCoverEntity(ISYNodeEntity, CoverEntity):
|
class ISYCoverEntity(ISYNodeEntity, CoverEntity):
|
||||||
|
@ -18,7 +18,6 @@ from homeassistant.helpers.typing import HomeAssistantType
|
|||||||
from .const import _LOGGER, DOMAIN as ISY994_DOMAIN, ISY994_NODES, ISY994_PROGRAMS
|
from .const import _LOGGER, DOMAIN as ISY994_DOMAIN, ISY994_NODES, ISY994_PROGRAMS
|
||||||
from .entity import ISYNodeEntity, ISYProgramEntity
|
from .entity import ISYNodeEntity, ISYProgramEntity
|
||||||
from .helpers import migrate_old_unique_ids
|
from .helpers import migrate_old_unique_ids
|
||||||
from .services import async_setup_device_services
|
|
||||||
|
|
||||||
VALUE_TO_STATE = {
|
VALUE_TO_STATE = {
|
||||||
0: SPEED_OFF,
|
0: SPEED_OFF,
|
||||||
@ -51,7 +50,6 @@ async def async_setup_entry(
|
|||||||
|
|
||||||
await migrate_old_unique_ids(hass, FAN, devices)
|
await migrate_old_unique_ids(hass, FAN, devices)
|
||||||
async_add_entities(devices)
|
async_add_entities(devices)
|
||||||
async_setup_device_services(hass)
|
|
||||||
|
|
||||||
|
|
||||||
class ISYFanEntity(ISYNodeEntity, FanEntity):
|
class ISYFanEntity(ISYNodeEntity, FanEntity):
|
||||||
|
@ -20,7 +20,7 @@ from .const import (
|
|||||||
)
|
)
|
||||||
from .entity import ISYNodeEntity
|
from .entity import ISYNodeEntity
|
||||||
from .helpers import migrate_old_unique_ids
|
from .helpers import migrate_old_unique_ids
|
||||||
from .services import async_setup_device_services, async_setup_light_services
|
from .services import async_setup_light_services
|
||||||
|
|
||||||
ATTR_LAST_BRIGHTNESS = "last_brightness"
|
ATTR_LAST_BRIGHTNESS = "last_brightness"
|
||||||
|
|
||||||
@ -41,7 +41,6 @@ async def async_setup_entry(
|
|||||||
|
|
||||||
await migrate_old_unique_ids(hass, LIGHT, devices)
|
await migrate_old_unique_ids(hass, LIGHT, devices)
|
||||||
async_add_entities(devices)
|
async_add_entities(devices)
|
||||||
async_setup_device_services(hass)
|
|
||||||
async_setup_light_services(hass)
|
async_setup_light_services(hass)
|
||||||
|
|
||||||
|
|
||||||
|
@ -10,7 +10,6 @@ from homeassistant.helpers.typing import HomeAssistantType
|
|||||||
from .const import _LOGGER, DOMAIN as ISY994_DOMAIN, ISY994_NODES, ISY994_PROGRAMS
|
from .const import _LOGGER, DOMAIN as ISY994_DOMAIN, ISY994_NODES, ISY994_PROGRAMS
|
||||||
from .entity import ISYNodeEntity, ISYProgramEntity
|
from .entity import ISYNodeEntity, ISYProgramEntity
|
||||||
from .helpers import migrate_old_unique_ids
|
from .helpers import migrate_old_unique_ids
|
||||||
from .services import async_setup_device_services
|
|
||||||
|
|
||||||
VALUE_TO_STATE = {0: False, 100: True}
|
VALUE_TO_STATE = {0: False, 100: True}
|
||||||
|
|
||||||
@ -31,7 +30,6 @@ async def async_setup_entry(
|
|||||||
|
|
||||||
await migrate_old_unique_ids(hass, LOCK, devices)
|
await migrate_old_unique_ids(hass, LOCK, devices)
|
||||||
async_add_entities(devices)
|
async_add_entities(devices)
|
||||||
async_setup_device_services(hass)
|
|
||||||
|
|
||||||
|
|
||||||
class ISYLockEntity(ISYNodeEntity, LockEntity):
|
class ISYLockEntity(ISYNodeEntity, LockEntity):
|
||||||
|
@ -19,7 +19,6 @@ from .const import (
|
|||||||
)
|
)
|
||||||
from .entity import ISYEntity, ISYNodeEntity
|
from .entity import ISYEntity, ISYNodeEntity
|
||||||
from .helpers import convert_isy_value_to_hass, migrate_old_unique_ids
|
from .helpers import convert_isy_value_to_hass, migrate_old_unique_ids
|
||||||
from .services import async_setup_device_services
|
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(
|
async def async_setup_entry(
|
||||||
@ -40,7 +39,6 @@ async def async_setup_entry(
|
|||||||
|
|
||||||
await migrate_old_unique_ids(hass, SENSOR, devices)
|
await migrate_old_unique_ids(hass, SENSOR, devices)
|
||||||
async_add_entities(devices)
|
async_add_entities(devices)
|
||||||
async_setup_device_services(hass)
|
|
||||||
|
|
||||||
|
|
||||||
class ISYSensorEntity(ISYNodeEntity):
|
class ISYSensorEntity(ISYNodeEntity):
|
||||||
|
@ -13,9 +13,10 @@ from homeassistant.const import (
|
|||||||
CONF_UNIT_OF_MEASUREMENT,
|
CONF_UNIT_OF_MEASUREMENT,
|
||||||
SERVICE_RELOAD,
|
SERVICE_RELOAD,
|
||||||
)
|
)
|
||||||
from homeassistant.core import callback
|
from homeassistant.core import ServiceCall, callback
|
||||||
from homeassistant.helpers import entity_platform
|
from homeassistant.helpers import entity_platform
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
|
from homeassistant.helpers.entity_platform import async_get_platforms
|
||||||
import homeassistant.helpers.entity_registry as er
|
import homeassistant.helpers.entity_registry as er
|
||||||
from homeassistant.helpers.typing import HomeAssistantType
|
from homeassistant.helpers.typing import HomeAssistantType
|
||||||
|
|
||||||
@ -353,6 +354,30 @@ def async_setup_services(hass: HomeAssistantType):
|
|||||||
domain=DOMAIN, service=SERVICE_RELOAD, service_func=async_reload_config_entries
|
domain=DOMAIN, service=SERVICE_RELOAD, service_func=async_reload_config_entries
|
||||||
)
|
)
|
||||||
|
|
||||||
|
async def _async_send_raw_node_command(call: ServiceCall):
|
||||||
|
await hass.helpers.service.entity_service_call(
|
||||||
|
async_get_platforms(hass, DOMAIN), SERVICE_SEND_RAW_NODE_COMMAND, call
|
||||||
|
)
|
||||||
|
|
||||||
|
hass.services.async_register(
|
||||||
|
domain=DOMAIN,
|
||||||
|
service=SERVICE_SEND_RAW_NODE_COMMAND,
|
||||||
|
schema=cv.make_entity_service_schema(SERVICE_SEND_RAW_NODE_COMMAND_SCHEMA),
|
||||||
|
service_func=_async_send_raw_node_command,
|
||||||
|
)
|
||||||
|
|
||||||
|
async def _async_send_node_command(call: ServiceCall):
|
||||||
|
await hass.helpers.service.entity_service_call(
|
||||||
|
async_get_platforms(hass, DOMAIN), SERVICE_SEND_NODE_COMMAND, call
|
||||||
|
)
|
||||||
|
|
||||||
|
hass.services.async_register(
|
||||||
|
domain=DOMAIN,
|
||||||
|
service=SERVICE_SEND_NODE_COMMAND,
|
||||||
|
schema=cv.make_entity_service_schema(SERVICE_SEND_NODE_COMMAND_SCHEMA),
|
||||||
|
service_func=_async_send_node_command,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def async_unload_services(hass: HomeAssistantType):
|
def async_unload_services(hass: HomeAssistantType):
|
||||||
@ -374,23 +399,8 @@ def async_unload_services(hass: HomeAssistantType):
|
|||||||
hass.services.async_remove(domain=DOMAIN, service=SERVICE_SET_VARIABLE)
|
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_CLEANUP)
|
||||||
hass.services.async_remove(domain=DOMAIN, service=SERVICE_RELOAD)
|
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_device_services(hass: HomeAssistantType):
|
|
||||||
"""Create device-specific services for the ISY Integration."""
|
|
||||||
platform = entity_platform.current_platform.get()
|
|
||||||
|
|
||||||
platform.async_register_entity_service(
|
|
||||||
SERVICE_SEND_RAW_NODE_COMMAND,
|
|
||||||
SERVICE_SEND_RAW_NODE_COMMAND_SCHEMA,
|
|
||||||
SERVICE_SEND_RAW_NODE_COMMAND,
|
|
||||||
)
|
|
||||||
platform.async_register_entity_service(
|
|
||||||
SERVICE_SEND_NODE_COMMAND,
|
|
||||||
SERVICE_SEND_NODE_COMMAND_SCHEMA,
|
|
||||||
SERVICE_SEND_NODE_COMMAND,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
|
@ -10,7 +10,6 @@ from homeassistant.helpers.typing import HomeAssistantType
|
|||||||
from .const import _LOGGER, DOMAIN as ISY994_DOMAIN, ISY994_NODES, ISY994_PROGRAMS
|
from .const import _LOGGER, DOMAIN as ISY994_DOMAIN, ISY994_NODES, ISY994_PROGRAMS
|
||||||
from .entity import ISYNodeEntity, ISYProgramEntity
|
from .entity import ISYNodeEntity, ISYProgramEntity
|
||||||
from .helpers import migrate_old_unique_ids
|
from .helpers import migrate_old_unique_ids
|
||||||
from .services import async_setup_device_services
|
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(
|
async def async_setup_entry(
|
||||||
@ -29,7 +28,6 @@ async def async_setup_entry(
|
|||||||
|
|
||||||
await migrate_old_unique_ids(hass, SWITCH, devices)
|
await migrate_old_unique_ids(hass, SWITCH, devices)
|
||||||
async_add_entities(devices)
|
async_add_entities(devices)
|
||||||
async_setup_device_services(hass)
|
|
||||||
|
|
||||||
|
|
||||||
class ISYSwitchEntity(ISYNodeEntity, SwitchEntity):
|
class ISYSwitchEntity(ISYNodeEntity, SwitchEntity):
|
||||||
|
@ -595,3 +595,19 @@ class EntityPlatform:
|
|||||||
current_platform: ContextVar[Optional[EntityPlatform]] = ContextVar(
|
current_platform: ContextVar[Optional[EntityPlatform]] = ContextVar(
|
||||||
"current_platform", default=None
|
"current_platform", default=None
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@callback
|
||||||
|
def async_get_platforms(
|
||||||
|
hass: HomeAssistantType, integration_name: str
|
||||||
|
) -> List[EntityPlatform]:
|
||||||
|
"""Find existing platforms."""
|
||||||
|
if (
|
||||||
|
DATA_ENTITY_PLATFORM not in hass.data
|
||||||
|
or integration_name not in hass.data[DATA_ENTITY_PLATFORM]
|
||||||
|
):
|
||||||
|
return []
|
||||||
|
|
||||||
|
platforms: List[EntityPlatform] = hass.data[DATA_ENTITY_PLATFORM][integration_name]
|
||||||
|
|
||||||
|
return platforms
|
||||||
|
@ -9,7 +9,7 @@ from homeassistant.const import SERVICE_RELOAD
|
|||||||
from homeassistant.core import Event, callback
|
from homeassistant.core import Event, callback
|
||||||
from homeassistant.exceptions import HomeAssistantError
|
from homeassistant.exceptions import HomeAssistantError
|
||||||
from homeassistant.helpers import config_per_platform
|
from homeassistant.helpers import config_per_platform
|
||||||
from homeassistant.helpers.entity_platform import DATA_ENTITY_PLATFORM, EntityPlatform
|
from homeassistant.helpers.entity_platform import EntityPlatform, async_get_platforms
|
||||||
from homeassistant.helpers.typing import HomeAssistantType
|
from homeassistant.helpers.typing import HomeAssistantType
|
||||||
from homeassistant.loader import async_get_integration
|
from homeassistant.loader import async_get_integration
|
||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
@ -141,13 +141,7 @@ def async_get_platform(
|
|||||||
hass: HomeAssistantType, integration_name: str, integration_platform_name: str
|
hass: HomeAssistantType, integration_name: str, integration_platform_name: str
|
||||||
) -> Optional[EntityPlatform]:
|
) -> Optional[EntityPlatform]:
|
||||||
"""Find an existing platform."""
|
"""Find an existing platform."""
|
||||||
if (
|
for integration_platform in async_get_platforms(hass, integration_name):
|
||||||
DATA_ENTITY_PLATFORM not in hass.data
|
|
||||||
or integration_name not in hass.data[DATA_ENTITY_PLATFORM]
|
|
||||||
):
|
|
||||||
return None
|
|
||||||
|
|
||||||
for integration_platform in hass.data[DATA_ENTITY_PLATFORM][integration_name]:
|
|
||||||
if integration_platform.domain == integration_platform_name:
|
if integration_platform.domain == integration_platform_name:
|
||||||
platform: EntityPlatform = integration_platform
|
platform: EntityPlatform = integration_platform
|
||||||
return platform
|
return platform
|
||||||
|
Loading…
x
Reference in New Issue
Block a user