mirror of
https://github.com/home-assistant/core.git
synced 2025-07-10 14:57:09 +00:00
Fix Shelly initialization if device runs large script (#142487)
* Don't check the whole script to see if it generates events * Fix tests --------- Co-authored-by: Shay Levy <levyshay1@gmail.com>
This commit is contained in:
parent
d4f47bfc6b
commit
06a2de4d1c
@ -277,3 +277,7 @@ ROLE_TO_DEVICE_CLASS_MAP = {
|
|||||||
"current_humidity": SensorDeviceClass.HUMIDITY,
|
"current_humidity": SensorDeviceClass.HUMIDITY,
|
||||||
"current_temperature": SensorDeviceClass.TEMPERATURE,
|
"current_temperature": SensorDeviceClass.TEMPERATURE,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# We want to check only the first 5 KB of the script if it contains emitEvent()
|
||||||
|
# so that the integration startup remains fast.
|
||||||
|
MAX_SCRIPT_SIZE = 5120
|
||||||
|
@ -58,6 +58,7 @@ from .const import (
|
|||||||
GEN2_BETA_RELEASE_URL,
|
GEN2_BETA_RELEASE_URL,
|
||||||
GEN2_RELEASE_URL,
|
GEN2_RELEASE_URL,
|
||||||
LOGGER,
|
LOGGER,
|
||||||
|
MAX_SCRIPT_SIZE,
|
||||||
RPC_INPUTS_EVENTS_TYPES,
|
RPC_INPUTS_EVENTS_TYPES,
|
||||||
SHAIR_MAX_WORK_HOURS,
|
SHAIR_MAX_WORK_HOURS,
|
||||||
SHBTN_INPUTS_EVENTS_TYPES,
|
SHBTN_INPUTS_EVENTS_TYPES,
|
||||||
@ -642,7 +643,7 @@ def get_rpc_ws_url(hass: HomeAssistant) -> str | None:
|
|||||||
|
|
||||||
async def get_rpc_script_event_types(device: RpcDevice, id: int) -> list[str]:
|
async def get_rpc_script_event_types(device: RpcDevice, id: int) -> list[str]:
|
||||||
"""Return a list of event types for a specific script."""
|
"""Return a list of event types for a specific script."""
|
||||||
code_response = await device.script_getcode(id)
|
code_response = await device.script_getcode(id, bytes_to_read=MAX_SCRIPT_SIZE)
|
||||||
matches = SHELLY_EMIT_EVENT_PATTERN.finditer(code_response["data"])
|
matches = SHELLY_EMIT_EVENT_PATTERN.finditer(code_response["data"])
|
||||||
return sorted([*{str(event_type.group(1)) for event_type in matches}])
|
return sorted([*{str(event_type.group(1)) for event_type in matches}])
|
||||||
|
|
||||||
|
@ -492,7 +492,9 @@ def _mock_rpc_device(version: str | None = None):
|
|||||||
initialized=True,
|
initialized=True,
|
||||||
connected=True,
|
connected=True,
|
||||||
script_getcode=AsyncMock(
|
script_getcode=AsyncMock(
|
||||||
side_effect=lambda script_id: {"data": MOCK_SCRIPTS[script_id - 1]}
|
side_effect=lambda script_id, bytes_to_read: {
|
||||||
|
"data": MOCK_SCRIPTS[script_id - 1]
|
||||||
|
}
|
||||||
),
|
),
|
||||||
xmod_info={},
|
xmod_info={},
|
||||||
)
|
)
|
||||||
@ -514,7 +516,9 @@ def _mock_blu_rtv_device(version: str | None = None):
|
|||||||
initialized=True,
|
initialized=True,
|
||||||
connected=True,
|
connected=True,
|
||||||
script_getcode=AsyncMock(
|
script_getcode=AsyncMock(
|
||||||
side_effect=lambda script_id: {"data": MOCK_SCRIPTS[script_id - 1]}
|
side_effect=lambda script_id, bytes_to_read: {
|
||||||
|
"data": MOCK_SCRIPTS[script_id - 1]
|
||||||
|
}
|
||||||
),
|
),
|
||||||
xmod_info={},
|
xmod_info={},
|
||||||
)
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user