async def initialise(znp: API, version, options: NetworkOptions): await znp.request(Subsystem.SYS, 'resetReq', {"type": Constants.SYS.resetType.SOFT}) await znp.request(Subsystem.SYS, 'osalNvWrite', Items.startupOption(0x02)) await znp.request(Subsystem.SYS, 'resetReq', {"type": Constants.SYS.resetType.SOFT}) await znp.request( Subsystem.SYS, 'osalNvWrite', Items.logicalType(Constants.ZDO.deviceLogicalType.COORDINATOR)) await znp.request(Subsystem.SYS, 'osalNvWrite', Items.networkKeyDistribute(options.networkKeyDistribute)) await znp.request(Subsystem.SYS, 'osalNvWrite', Items.zdoDirectCb()) await znp.request(Subsystem.SYS, 'osalNvWrite', Items.channelList(options.channelList)) await znp.request(Subsystem.SYS, 'osalNvWrite', Items.panID(options.panID)) await znp.request(Subsystem.SYS, 'osalNvWrite', Items.extendedPanID(options.extendedPanID)) if version == ZnpVersion.zStack30x or version == ZnpVersion.zStack3x0: await znp.request(Subsystem.SYS, 'osalNvWrite', Items.networkKey(options.networkKey)) # Default link key is already OK for Z-Stack 3 ('ZigBeeAlliance09') channelMask = int.from_bytes( bytes(getChannelMask(options.channelList)), 'little') await znp.request(Subsystem.APP_CNF, 'bdbSetChannel', { "isPrimary": 0x1, "channel": channelMask }) await znp.request(Subsystem.APP_CNF, 'bdbSetChannel', { "isPrimary": 0x0, "channel": 0x0 }) started = znp.wait_for(CommandType.AREQ, Subsystem.ZDO, 'stateChangeInd', {"state": 9}, 60000) await znp.request(Subsystem.APP_CNF, 'bdbStartCommissioning', {"mode": 0x04}) try: await started.wait() except: raise Exception( 'Coordinator failed to start, probably the panID is already in use, try a different panID or channel' ) await znp.request(Subsystem.APP_CNF, 'bdbStartCommissioning', {"mode": 0x02}) else: await znp.request(Subsystem.SAPI, 'writeConfiguration', Items.networkKey(options.networkKey)) await znp.request(Subsystem.SYS, 'osalNvWrite', Items.tcLinkKey()) # expect status code 9 (= item created and initialized) await znp.request(Subsystem.SYS, 'osalNvItemInit', Items.znpHasConfiguredInit(version), [0, 9]) await znp.request(Subsystem.SYS, 'osalNvWrite', Items.znpHasConfigured(version))
async def boot(znp: API): result = await znp.request(Subsystem.UTIL, "getDeviceInfo", {}) if result.payload["devicestate"] != Common.devStates["ZB_COORD"]: LOGGER.debug("Start ZNP as coordinator...") started = znp.wait_for(CommandType.AREQ, Subsystem.ZDO, "stateChangeInd", {"state": 9}, 60000) await znp.request(Subsystem.ZDO, "startupFromApp", {"startdelay": 100}, None, [0, 1]) await started.wait() LOGGER.info("ZNP started as coordinator") else: LOGGER.info("ZNP is already started as coordinator")
async def boot(znp: API): result = await znp.request(Subsystem.UTIL, 'getDeviceInfo', {}) if result.payload['devicestate'] != Common.devStates["ZB_COORD"]: LOGGER.debug('Start ZNP as coordinator...') started = znp.wait_for(CommandType.AREQ, Subsystem.ZDO, 'stateChangeInd', {"state": 9}, 60000) await znp.request(Subsystem.ZDO, 'startupFromApp', {"startdelay": 100}, [0, 1]) await started.wait() LOGGER.debug('ZNP started as coordinator') else: LOGGER.debug('ZNP is already started as coordinator')
async def registerEndpoints(znp: API): LOGGER.debug("Register endpoints...") active_ep_response = znp.wait_for(CommandType.AREQ, Subsystem.ZDO, "activeEpRsp") asyncio.create_task( znp.request(Subsystem.ZDO, "activeEpReq", { "dstaddr": 0, "nwkaddrofinterest": 0 })) active_ep = await active_ep_response.wait() for endpoint in Endpoints: if endpoint.endpoint in active_ep.payload["activeeplist"]: LOGGER.debug("Endpoint '%s' already registered", endpoint.endpoint) else: LOGGER.debug("Registering endpoint '%s'", endpoint.endpoint) await znp.request(Subsystem.AF, "register", vars(endpoint))
async def registerEndpoints(znp: API): LOGGER.debug('Register endpoints...') activeEpResponse = znp.wait_for(CommandType.AREQ, Subsystem.ZDO, 'activeEpRsp') try: await znp.request(Subsystem.ZDO, 'activeEpReq', { "dstaddr": 0, "nwkaddrofinterest": 0 }) except Exception as e: LOGGER.debug(e) activeEp = await activeEpResponse.wait() for endpoint in Endpoints: if endpoint.endpoint in activeEp.payload["activeeplist"]: LOGGER.debug("Endpoint '%s' already registered", endpoint.endpoint) else: LOGGER.debug("Registering endpoint '%s'", endpoint.endpoint) await znp.request(Subsystem.AF, 'register', vars(endpoint))