Example #1
0
def app_mock():
    """ConntrollerApplication Mock."""

    config = App.SCHEMA({
        CONF_DATABASE: None,
        CONF_DEVICE: {
            CONF_DEVICE_PATH: "/dev/null"
        }
    })
    app_mock = MagicMock(spec_set=App(config))
    app_mock.state.node_information = app_state.NodeInfo(
        t.NWK(0x0000),
        ieee=NCP_IEEE,
        logical_type=zdo_t.LogicalType.Coordinator)
    return app_mock
Example #2
0
def app():
    class App(zigpy.application.ControllerApplication):
        async def shutdown(self):
            pass

        async def startup(self, auto_form=False):
            self._ieee = t.EUI64.convert("aa:de:de:be:ef:11:22:11")
            self._nwk = t.NWK(0x0000)

        async def request(
            self,
            device,
            profile,
            cluster,
            src_ep,
            dst_ep,
            sequence,
            data,
            expect_reply=True,
            use_ieee=False,
        ):
            pass

        async def permit_ncp(self, time_s=60):
            pass

        async def probe(self, config):
            return True

    config = App.SCHEMA({
        CONF_DATABASE: None,
        CONF_DEVICE: {
            CONF_DEVICE_PATH: "/dev/null"
        }
    })
    app = App(config)
    app.state.node_information = app_state.NodeInfo(
        t.NWK(0x0000),
        ieee=NCP_IEEE,
        logical_type=zdo_t.LogicalType.Coordinator)
    return app
Example #3
0
    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()
        (ieee, ) = await ezsp.getEui64()

        node_info = app_state.NodeInfo(nwk, ieee, node_type.zdo_logical_type)
        self.state.node_information = node_info
        self.state.network_information = nwk_params.zigpy_network_information
        for cnt_group in self.state.counters:
            cnt_group.reset()

        if ezsp.ezsp_version >= 8:
            for device in self.devices.values():
                device.relays = None

        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))
Example #4
0
def node_info():
    return app_state.NodeInfo(
        nwk=t.NWK(0x0000),
        ieee=t.EUI64.convert("93:2C:A9:34:D9:D0:5D:12"),
        logical_type=zdo_t.LogicalType.Coordinator,
    )