From 0084b8e25b3fafdd73094f2b8227a11ff6a26ea6 Mon Sep 17 00:00:00 2001 From: puddly <32534428+puddly@users.noreply.github.com> Date: Tue, 15 Oct 2024 15:07:55 -0400 Subject: [PATCH] Add support for the `GET_FLOW_CONTROL_TYPE` XNCP command --- bellows/ezsp/__init__.py | 7 ++++++- bellows/ezsp/xncp.py | 20 ++++++++++++++++++++ bellows/zigbee/application.py | 15 ++++++++++++++- 3 files changed, 40 insertions(+), 2 deletions(-) diff --git a/bellows/ezsp/__init__.py b/bellows/ezsp/__init__.py index 109d5473..bbd74280 100644 --- a/bellows/ezsp/__init__.py +++ b/bellows/ezsp/__init__.py @@ -23,7 +23,7 @@ from bellows.exception import EzspError, InvalidCommandError from bellows.ezsp import xncp from bellows.ezsp.config import DEFAULT_CONFIG, RuntimeConfig, ValueConfig -from bellows.ezsp.xncp import FirmwareFeatures +from bellows.ezsp.xncp import FirmwareFeatures, FlowControlType import bellows.types as t import bellows.uart @@ -709,3 +709,8 @@ async def xncp_get_build_string(self) -> bytes: """Get build string.""" rsp = await self.send_xncp_frame(xncp.GetBuildStringReq()) return rsp.build_string.decode("utf-8") + + async def xncp_get_flow_control_type(self) -> FlowControlType: + """Get flow control type.""" + rsp = await self.send_xncp_frame(xncp.GetFlowControlTypeReq()) + return rsp.flow_control_type diff --git a/bellows/ezsp/xncp.py b/bellows/ezsp/xncp.py index af7c03ec..f6dc52ce 100644 --- a/bellows/ezsp/xncp.py +++ b/bellows/ezsp/xncp.py @@ -47,11 +47,13 @@ class XncpCommandId(t.enum16): SET_SOURCE_ROUTE_REQ = 0x0001 GET_MFG_TOKEN_OVERRIDE_REQ = 0x0002 GET_BUILD_STRING_REQ = 0x0003 + GET_FLOW_CONTROL_TYPE_REQ = 0x0004 GET_SUPPORTED_FEATURES_RSP = GET_SUPPORTED_FEATURES_REQ | 0x8000 SET_SOURCE_ROUTE_RSP = SET_SOURCE_ROUTE_REQ | 0x8000 GET_MFG_TOKEN_OVERRIDE_RSP = GET_MFG_TOKEN_OVERRIDE_REQ | 0x8000 GET_BUILD_STRING_RSP = GET_BUILD_STRING_REQ | 0x8000 + GET_FLOW_CONTROL_TYPE_RSP = GET_FLOW_CONTROL_TYPE_REQ | 0x8000 UNKNOWN = 0xFFFF @@ -104,11 +106,19 @@ class FirmwareFeatures(t.bitmap32): # The firmware contains a free-form build string BUILD_STRING = 1 << 3 + # The flow control type (software or hardware) can be queried + FLOW_CONTROL_TYPE = 1 << 4 + class XncpCommandPayload(t.Struct): pass +class FlowControlType(t.enum8): + Software = 0x00 + Hardware = 0x01 + + @register_command(XncpCommandId.GET_SUPPORTED_FEATURES_REQ) class GetSupportedFeaturesReq(XncpCommandPayload): pass @@ -148,3 +158,13 @@ class GetBuildStringReq(XncpCommandPayload): @register_command(XncpCommandId.GET_BUILD_STRING_RSP) class GetBuildStringRsp(XncpCommandPayload): build_string: Bytes + + +@register_command(XncpCommandId.GET_FLOW_CONTROL_TYPE_REQ) +class GetFlowControlTypeReq(XncpCommandPayload): + pass + + +@register_command(XncpCommandId.GET_FLOW_CONTROL_TYPE_RSP) +class GetFlowControlTypeRsp(XncpCommandPayload): + flow_control_type: FlowControlType diff --git a/bellows/zigbee/application.py b/bellows/zigbee/application.py index 761778a2..e533ebfc 100644 --- a/bellows/zigbee/application.py +++ b/bellows/zigbee/application.py @@ -32,7 +32,12 @@ CONF_USE_THREAD, CONFIG_SCHEMA, ) -from bellows.exception import ControllerError, EzspError, StackAlreadyRunning +from bellows.exception import ( + ControllerError, + EzspError, + InvalidCommandError, + StackAlreadyRunning, +) import bellows.ezsp from bellows.ezsp.xncp import FirmwareFeatures import bellows.multicast @@ -295,6 +300,11 @@ async def load_network_info(self, *, load_devices=False) -> None: can_burn_userdata_custom_eui64 = await ezsp.can_burn_userdata_custom_eui64() can_rewrite_custom_eui64 = await ezsp.can_rewrite_custom_eui64() + try: + flow_control = await self._ezsp.xncp_get_flow_control_type() + except InvalidCommandError: + flow_control = None + self.state.network_info = zigpy.state.NetworkInfo( source=f"bellows@{LIB_VERSION}", extended_pan_id=zigpy.types.ExtendedPanId(nwk_params.extendedPanId), @@ -315,6 +325,9 @@ async def load_network_info(self, *, load_devices=False) -> None: "stack_version": ezsp.ezsp_version, "can_burn_userdata_custom_eui64": can_burn_userdata_custom_eui64, "can_rewrite_custom_eui64": can_rewrite_custom_eui64, + "flow_control": ( + flow_control.name.lower() if flow_control is not None else None + ), } }, )