mirror of
https://github.com/home-assistant/core.git
synced 2025-07-28 07:37:34 +00:00
Resolve delay sending multiple commands to harmony remotes (#34410)
* Switch harmony to entity service * Fix delay between sending commands, collapse function
This commit is contained in:
parent
e6a2507b50
commit
f492a7678d
@ -25,6 +25,7 @@ from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry
|
|||||||
from homeassistant.const import ATTR_ENTITY_ID, CONF_HOST, CONF_NAME
|
from homeassistant.const import ATTR_ENTITY_ID, CONF_HOST, CONF_NAME
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.exceptions import PlatformNotReady
|
from homeassistant.exceptions import PlatformNotReady
|
||||||
|
from homeassistant.helpers import entity_platform
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||||
|
|
||||||
@ -45,6 +46,9 @@ from .util import (
|
|||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
# We want to fire remote commands right away
|
||||||
|
PARALLEL_UPDATES = 0
|
||||||
|
|
||||||
ATTR_CHANNEL = "channel"
|
ATTR_CHANNEL = "channel"
|
||||||
ATTR_CURRENT_ACTIVITY = "current_activity"
|
ATTR_CURRENT_ACTIVITY = "current_activity"
|
||||||
|
|
||||||
@ -110,44 +114,14 @@ async def async_setup_entry(
|
|||||||
_LOGGER.debug("Harmony Remote: %s", device)
|
_LOGGER.debug("Harmony Remote: %s", device)
|
||||||
|
|
||||||
async_add_entities([device])
|
async_add_entities([device])
|
||||||
register_services(hass)
|
|
||||||
|
|
||||||
|
platform = entity_platform.current_platform.get()
|
||||||
|
|
||||||
def register_services(hass):
|
platform.async_register_entity_service(
|
||||||
"""Register all services for harmony devices."""
|
SERVICE_SYNC, HARMONY_SYNC_SCHEMA, "sync",
|
||||||
|
|
||||||
async def _apply_service(service, service_func, *service_func_args):
|
|
||||||
"""Handle services to apply."""
|
|
||||||
entity_ids = service.data.get("entity_id")
|
|
||||||
|
|
||||||
want_devices = [
|
|
||||||
hass.data[DOMAIN][config_entry_id] for config_entry_id in hass.data[DOMAIN]
|
|
||||||
]
|
|
||||||
|
|
||||||
if entity_ids:
|
|
||||||
want_devices = [
|
|
||||||
device for device in want_devices if device.entity_id in entity_ids
|
|
||||||
]
|
|
||||||
|
|
||||||
for device in want_devices:
|
|
||||||
await service_func(device, *service_func_args)
|
|
||||||
|
|
||||||
async def _sync_service(service):
|
|
||||||
await _apply_service(service, HarmonyRemote.sync)
|
|
||||||
|
|
||||||
async def _change_channel_service(service):
|
|
||||||
channel = service.data.get(ATTR_CHANNEL)
|
|
||||||
await _apply_service(service, HarmonyRemote.change_channel, channel)
|
|
||||||
|
|
||||||
hass.services.async_register(
|
|
||||||
DOMAIN, SERVICE_SYNC, _sync_service, schema=HARMONY_SYNC_SCHEMA
|
|
||||||
)
|
)
|
||||||
|
platform.async_register_entity_service(
|
||||||
hass.services.async_register(
|
SERVICE_CHANGE_CHANNEL, HARMONY_CHANGE_CHANNEL_SCHEMA, "change_channel"
|
||||||
DOMAIN,
|
|
||||||
SERVICE_CHANGE_CHANNEL,
|
|
||||||
_change_channel_service,
|
|
||||||
schema=HARMONY_CHANGE_CHANNEL_SCHEMA,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user