mirror of
https://github.com/home-assistant/core.git
synced 2025-07-25 22:27:07 +00:00
- added send packet service to send ir packets directly from scripts (no need to define a switch for each command) (#5768)
- changed ip suffix of SERVICE_LEARN to use _ instead of . as ip seperator to avoid errors if used in yaml
This commit is contained in:
parent
0d89f2bc69
commit
4a341ff55f
@ -28,7 +28,9 @@ _LOGGER = logging.getLogger(__name__)
|
|||||||
DOMAIN = "broadlink"
|
DOMAIN = "broadlink"
|
||||||
DEFAULT_NAME = 'Broadlink switch'
|
DEFAULT_NAME = 'Broadlink switch'
|
||||||
DEFAULT_TIMEOUT = 10
|
DEFAULT_TIMEOUT = 10
|
||||||
|
DEFAULT_RETRY = 3
|
||||||
SERVICE_LEARN = "learn_command"
|
SERVICE_LEARN = "learn_command"
|
||||||
|
SERVICE_SEND = "send_packet"
|
||||||
|
|
||||||
RM_TYPES = ["rm", "rm2", "rm_mini", "rm_pro_phicomm", "rm2_home_plus",
|
RM_TYPES = ["rm", "rm2", "rm_mini", "rm_pro_phicomm", "rm2_home_plus",
|
||||||
"rm2_home_plus_gdt", "rm2_pro_plus", "rm2_pro_plus2",
|
"rm2_home_plus_gdt", "rm2_pro_plus", "rm2_pro_plus2",
|
||||||
@ -101,10 +103,30 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
|||||||
"Did not received any signal",
|
"Did not received any signal",
|
||||||
title='Broadlink switch')
|
title='Broadlink switch')
|
||||||
|
|
||||||
|
@asyncio.coroutine
|
||||||
|
def _send_packet(call):
|
||||||
|
packets = call.data.get('packet', [])
|
||||||
|
for packet in packets:
|
||||||
|
for retry in range(DEFAULT_RETRY):
|
||||||
|
try:
|
||||||
|
payload = b64decode(packet)
|
||||||
|
yield from hass.loop.run_in_executor(
|
||||||
|
None, broadlink_device.send_data, payload)
|
||||||
|
break
|
||||||
|
except (socket.timeout, ValueError):
|
||||||
|
try:
|
||||||
|
yield from hass.loop.run_in_executor(
|
||||||
|
None, broadlink_device.auth)
|
||||||
|
except socket.timeout:
|
||||||
|
if retry == DEFAULT_RETRY-1:
|
||||||
|
_LOGGER.error("Failed to send packet to device.")
|
||||||
|
|
||||||
if switch_type in RM_TYPES:
|
if switch_type in RM_TYPES:
|
||||||
broadlink_device = broadlink.rm((ip_addr, 80), mac_addr)
|
broadlink_device = broadlink.rm((ip_addr, 80), mac_addr)
|
||||||
hass.services.register(DOMAIN, SERVICE_LEARN + '_' + ip_addr,
|
hass.services.register(DOMAIN, SERVICE_LEARN + '_' +
|
||||||
_learn_command)
|
ip_addr.replace('.', '_'), _learn_command)
|
||||||
|
hass.services.register(DOMAIN, SERVICE_SEND + '_' +
|
||||||
|
ip_addr.replace('.', '_'), _send_packet)
|
||||||
switches = []
|
switches = []
|
||||||
for object_id, device_config in devices.items():
|
for object_id, device_config in devices.items():
|
||||||
switches.append(
|
switches.append(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user