|
|
@@ -13,7 +13,7 @@ from itertools import product
|
|
|
from typing import Any
|
|
|
|
|
|
import voluptuous as vol
|
|
|
-from homeassistant.components import persistent_notification
|
|
|
+from homeassistant.components import infrared, persistent_notification
|
|
|
from homeassistant.components.remote import (
|
|
|
ATTR_ALTERNATIVE,
|
|
|
ATTR_COMMAND_TYPE,
|
|
|
@@ -21,29 +21,23 @@ from homeassistant.components.remote import (
|
|
|
ATTR_DEVICE,
|
|
|
ATTR_NUM_REPEATS,
|
|
|
DEFAULT_DELAY_SECS,
|
|
|
+ DOMAIN as RM_DOMAIN,
|
|
|
SERVICE_DELETE_COMMAND,
|
|
|
SERVICE_LEARN_COMMAND,
|
|
|
SERVICE_SEND_COMMAND,
|
|
|
RemoteEntity,
|
|
|
RemoteEntityFeature,
|
|
|
)
|
|
|
-from homeassistant.components.remote import (
|
|
|
- DOMAIN as RM_DOMAIN,
|
|
|
-)
|
|
|
from homeassistant.const import ATTR_COMMAND
|
|
|
from homeassistant.helpers import config_validation as cv
|
|
|
from homeassistant.helpers.storage import Store
|
|
|
from homeassistant.util import dt as dt_util
|
|
|
|
|
|
-# from tinytuya.Contrib.IRRemoteControlDevice import (
|
|
|
-# base64_to_pulses,
|
|
|
-# pulses_to_pronto,
|
|
|
-# pulses_to_width_encoded,
|
|
|
-# )
|
|
|
from .device import TuyaLocalDevice
|
|
|
from .entity import TuyaLocalEntity
|
|
|
from .helpers.config import async_tuya_setup_platform
|
|
|
from .helpers.device_config import TuyaEntityConfig
|
|
|
+from .infrared import TuyaRemoteCommand
|
|
|
|
|
|
_LOGGER = logging.getLogger(__name__)
|
|
|
|
|
|
@@ -257,7 +251,7 @@ class TuyaLocalRemote(TuyaLocalEntity, RemoteEntity):
|
|
|
kwargs = SERVICE_SEND_SCHEMA(kwargs)
|
|
|
subdevice = kwargs.get(ATTR_DEVICE)
|
|
|
repeat = kwargs.get(ATTR_NUM_REPEATS)
|
|
|
- delay = kwargs.get(ATTR_DELAY_SECS, DEFAULT_DELAY_SECS) * 1000
|
|
|
+ delay = kwargs.get(ATTR_DELAY_SECS, DEFAULT_DELAY_SECS)
|
|
|
service = f"{RM_DOMAIN}.{SERVICE_SEND_COMMAND}"
|
|
|
if not self._storage_loaded:
|
|
|
await self._async_load_storage()
|
|
|
@@ -271,17 +265,18 @@ class TuyaLocalRemote(TuyaLocalEntity, RemoteEntity):
|
|
|
at_least_one_sent = False
|
|
|
for _, codes in product(range(repeat), code_list):
|
|
|
if at_least_one_sent:
|
|
|
- await asyncio.sleep(delay / 1000) # delay is in ms
|
|
|
+ await asyncio.sleep(delay)
|
|
|
|
|
|
if len(codes) > 1:
|
|
|
code = codes[self._flags[subdevice]]
|
|
|
else:
|
|
|
code = codes[0]
|
|
|
|
|
|
+ # Tuya delay is in milliseconds
|
|
|
if code.startswith("rf:"):
|
|
|
- dps_to_set = self._encode_send_code(code[3:], delay, is_rf=True)
|
|
|
+ dps_to_set = self._encode_send_code(code[3:], delay * 1000, is_rf=True)
|
|
|
else:
|
|
|
- dps_to_set = self._encode_send_code(code, delay)
|
|
|
+ dps_to_set = self._encode_send_code(code, delay * 1000)
|
|
|
_LOGGER.info(
|
|
|
"%s sending command %s to %s",
|
|
|
self._config.config_id,
|
|
|
@@ -314,9 +309,6 @@ class TuyaLocalRemote(TuyaLocalEntity, RemoteEntity):
|
|
|
for command in commands:
|
|
|
code = await self._async_learn_command(command, is_rf=is_rf)
|
|
|
_LOGGER.info("Learning %s for %s: %s", command, subdevice, code)
|
|
|
- # pulses = base64_to_pulses(code)
|
|
|
- # _LOGGER.debug("= pronto code: %s", pulses_to_pronto(pulses))
|
|
|
- # _LOGGER.debug("= width encoded: %s", pulses_to_width_encoded(pulses))
|
|
|
if toggle:
|
|
|
code = [code, await self._async_learn_command(command, is_rf=is_rf)]
|
|
|
self._codes.setdefault(subdevice, {}).update({command: code})
|