async def startup(self, auto_form=False): """Perform a complete application startup""" self._ezsp = await bellows.ezsp.EZSP.initialize(self.config) ezsp = self._ezsp self._multicast = bellows.multicast.Multicast(ezsp) status, count = await ezsp.getConfigurationValue( ezsp.types.EzspConfigId.CONFIG_APS_UNICAST_MESSAGE_COUNT) assert status == t.EmberStatus.SUCCESS self._in_flight_msg = asyncio.Semaphore(count) LOGGER.debug("APS_UNICAST_MESSAGE_COUNT is set to %s", count) await self.add_endpoint( output_clusters=[zigpy.zcl.clusters.security.IasZone.cluster_id]) brd_manuf, brd_name, version = await self._ezsp.get_board_info() LOGGER.info("EZSP Radio manufacturer: %s", brd_manuf) LOGGER.info("EZSP Radio board name: %s", brd_name) LOGGER.info("EmberZNet version: %s", version) v = await ezsp.networkInit() if v[0] != t.EmberStatus.SUCCESS: if not auto_form: raise ControllerError("Could not initialize network") await self.form_network() status, node_type, nwk_params = await ezsp.getNetworkParameters() assert status == t.EmberStatus.SUCCESS # TODO: Better check if node_type != t.EmberNodeType.COORDINATOR: if not auto_form: raise ControllerError("Network not configured as coordinator") LOGGER.info( "Leaving current network as %s and forming new network", node_type.name) (status, ) = await self._ezsp.leaveNetwork() assert status == t.EmberStatus.NETWORK_DOWN await self.form_network() status, node_type, nwk_params = await ezsp.getNetworkParameters() assert status == t.EmberStatus.SUCCESS LOGGER.info("Node type: %s, Network parameters: %s", node_type, nwk_params) await ezsp.update_policies(self.config) nwk = await ezsp.getNodeId() self._nwk = nwk[0] ieee = await ezsp.getEui64() self._ieee = ieee[0] ezsp.add_callback(self.ezsp_callback_handler) self.controller_event.set() self._watchdog_task = asyncio.create_task(self._watchdog()) self.handle_join(self.nwk, self.ieee, 0) LOGGER.debug("EZSP nwk=0x%04x, IEEE=%s", self._nwk, str(self._ieee)) await self.multicast.startup(self.get_device(self.ieee))
async def startup(self, auto_form=False): """Perform a complete application startup""" ezsp = bellows.ezsp.EZSP(self.config[zigpy.config.CONF_DEVICE]) self._ezsp = ezsp await self.initialize() await self.set_source_routing() v = await ezsp.networkInit() if v[0] != t.EmberStatus.SUCCESS: if not auto_form: raise Exception("Could not initialize network") await self.form_network() v = await ezsp.getNetworkParameters() assert v[0] == t.EmberStatus.SUCCESS # TODO: Better check if v[1] != t.EmberNodeType.COORDINATOR: if not auto_form: raise Exception("Network not configured as coordinator") LOGGER.info("Forming network") await self._ezsp.leaveNetwork() await asyncio.sleep(1) # TODO await self.form_network() await self._policy() nwk = await ezsp.getNodeId() self._nwk = nwk[0] ieee = await ezsp.getEui64() self._ieee = ieee[0] ezsp.add_callback(self.ezsp_callback_handler) self.controller_event.set() self._watchdog_task = asyncio.ensure_future(self._watchdog()) self.handle_join(self.nwk, self.ieee, 0) LOGGER.debug("EZSP nwk=0x%04x, IEEE=%s", self._nwk, str(self._ieee)) await self.multicast.startup(self.get_device(self.ieee))