Fix isy994 send_node_command ()

pull/39819/head
J. Nick Koston 2020-09-08 10:31:08 -05:00 committed by GitHub
parent 4bbd69955b
commit 8adfcf23f0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 47 additions and 42 deletions

View File

@ -49,7 +49,6 @@ from .const import (
)
from .entity import ISYNodeEntity, ISYProgramEntity
from .helpers import migrate_old_unique_ids
from .services import async_setup_device_services
DEVICE_PARENT_REQUIRED = [
DEVICE_CLASS_OPENING,
@ -172,7 +171,6 @@ async def async_setup_entry(
await migrate_old_unique_ids(hass, BINARY_SENSOR, devices)
async_add_entities(devices)
async_setup_device_services(hass)
def _detect_device_type_and_class(node: Union[Group, Node]) -> (str, str):

View File

@ -52,7 +52,6 @@ from .const import (
)
from .entity import ISYNodeEntity
from .helpers import convert_isy_value_to_hass, migrate_old_unique_ids
from .services import async_setup_device_services
ISY_SUPPORTED_FEATURES = (
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)
async_add_entities(entities)
async_setup_device_services(hass)
class ISYThermostatEntity(ISYNodeEntity, ClimateEntity):

View File

@ -24,7 +24,6 @@ from .const import (
)
from .entity import ISYNodeEntity, ISYProgramEntity
from .helpers import migrate_old_unique_ids
from .services import async_setup_device_services
async def async_setup_entry(
@ -43,7 +42,6 @@ async def async_setup_entry(
await migrate_old_unique_ids(hass, COVER, devices)
async_add_entities(devices)
async_setup_device_services(hass)
class ISYCoverEntity(ISYNodeEntity, CoverEntity):

View File

@ -18,7 +18,6 @@ from homeassistant.helpers.typing import HomeAssistantType
from .const import _LOGGER, DOMAIN as ISY994_DOMAIN, ISY994_NODES, ISY994_PROGRAMS
from .entity import ISYNodeEntity, ISYProgramEntity
from .helpers import migrate_old_unique_ids
from .services import async_setup_device_services
VALUE_TO_STATE = {
0: SPEED_OFF,
@ -51,7 +50,6 @@ async def async_setup_entry(
await migrate_old_unique_ids(hass, FAN, devices)
async_add_entities(devices)
async_setup_device_services(hass)
class ISYFanEntity(ISYNodeEntity, FanEntity):

View File

@ -20,7 +20,7 @@ from .const import (
)
from .entity import ISYNodeEntity
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"
@ -41,7 +41,6 @@ async def async_setup_entry(
await migrate_old_unique_ids(hass, LIGHT, devices)
async_add_entities(devices)
async_setup_device_services(hass)
async_setup_light_services(hass)

View File

@ -10,7 +10,6 @@ from homeassistant.helpers.typing import HomeAssistantType
from .const import _LOGGER, DOMAIN as ISY994_DOMAIN, ISY994_NODES, ISY994_PROGRAMS
from .entity import ISYNodeEntity, ISYProgramEntity
from .helpers import migrate_old_unique_ids
from .services import async_setup_device_services
VALUE_TO_STATE = {0: False, 100: True}
@ -31,7 +30,6 @@ async def async_setup_entry(
await migrate_old_unique_ids(hass, LOCK, devices)
async_add_entities(devices)
async_setup_device_services(hass)
class ISYLockEntity(ISYNodeEntity, LockEntity):

View File

@ -19,7 +19,6 @@ from .const import (
)
from .entity import ISYEntity, ISYNodeEntity
from .helpers import convert_isy_value_to_hass, migrate_old_unique_ids
from .services import async_setup_device_services
async def async_setup_entry(
@ -40,7 +39,6 @@ async def async_setup_entry(
await migrate_old_unique_ids(hass, SENSOR, devices)
async_add_entities(devices)
async_setup_device_services(hass)
class ISYSensorEntity(ISYNodeEntity):

View File

@ -13,9 +13,10 @@ from homeassistant.const import (
CONF_UNIT_OF_MEASUREMENT,
SERVICE_RELOAD,
)
from homeassistant.core import callback
from homeassistant.core import 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.typing import HomeAssistantType
@ -353,6 +354,30 @@ def async_setup_services(hass: HomeAssistantType):
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
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_CLEANUP)
hass.services.async_remove(domain=DOMAIN, service=SERVICE_RELOAD)
@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,
)
hass.services.async_remove(domain=DOMAIN, service=SERVICE_SEND_RAW_NODE_COMMAND)
hass.services.async_remove(domain=DOMAIN, service=SERVICE_SEND_NODE_COMMAND)
@callback

View File

@ -10,7 +10,6 @@ from homeassistant.helpers.typing import HomeAssistantType
from .const import _LOGGER, DOMAIN as ISY994_DOMAIN, ISY994_NODES, ISY994_PROGRAMS
from .entity import ISYNodeEntity, ISYProgramEntity
from .helpers import migrate_old_unique_ids
from .services import async_setup_device_services
async def async_setup_entry(
@ -29,7 +28,6 @@ async def async_setup_entry(
await migrate_old_unique_ids(hass, SWITCH, devices)
async_add_entities(devices)
async_setup_device_services(hass)
class ISYSwitchEntity(ISYNodeEntity, SwitchEntity):

View File

@ -595,3 +595,19 @@ class EntityPlatform:
current_platform: ContextVar[Optional[EntityPlatform]] = ContextVar(
"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

View File

@ -9,7 +9,7 @@ from homeassistant.const import SERVICE_RELOAD
from homeassistant.core import Event, callback
from homeassistant.exceptions import HomeAssistantError
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.loader import async_get_integration
from homeassistant.setup import async_setup_component
@ -141,13 +141,7 @@ def async_get_platform(
hass: HomeAssistantType, integration_name: str, integration_platform_name: str
) -> Optional[EntityPlatform]:
"""Find an existing platform."""
if (
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]:
for integration_platform in async_get_platforms(hass, integration_name):
if integration_platform.domain == integration_platform_name:
platform: EntityPlatform = integration_platform
return platform