Пример #1
0
    async def subscribe(self, group_id) -> t.EmberStatus:
        if group_id in self._multicast:
            LOGGER.debug("%s is already subscribed",
                         t.EmberMulticastId(group_id))
            return t.EmberStatus.SUCCESS

        try:
            idx = self._available.pop()
        except KeyError:
            LOGGER.error("No more available slots MulticastId subscription")
            return t.EmberStatus.INDEX_OUT_OF_RANGE
        entry = t.EmberMulticastTableEntry()
        entry.endpoint = t.uint8_t(1)
        entry.multicastId = t.EmberMulticastId(group_id)
        entry.networkIndex = t.uint8_t(0)
        status = await self._ezsp.setMulticastTableEntry(idx, entry)
        if status[0] != t.EmberStatus.SUCCESS:
            LOGGER.warning(
                "Set MulticastTableEntry #%s for %s multicast id: %s", idx,
                entry.multicastId, status)
            self._available.add(idx)
            return status[0]

        self._multicast[entry.multicastId] = (entry, idx)
        LOGGER.debug("Set MulticastTableEntry #%s for %s multicast id: %s",
                     idx, entry.multicastId, status)
        return status[0]
Пример #2
0
 async def mock_get(*args):
     nonlocal group_id
     entry = t.EmberMulticastTableEntry()
     entry.endpoint = t.uint8_t(group_id % 3 + 1)
     entry.multicastId = t.EmberMulticastId(group_id)
     entry.networkIndex = t.uint8_t(0)
     group_id += 1
     return [t.EmberStatus.ERR_FATAL, entry]
Пример #3
0
 async def mock_get(*args):
     nonlocal group_id, mct
     entry = t.EmberMulticastTableEntry()
     if mct > 0:
         entry.endpoint = t.uint8_t(group_id % 3 + 1)
     else:
         entry.endpoint = t.uint8_t(0)
     entry.multicastId = t.EmberMulticastId(group_id)
     entry.networkIndex = t.uint8_t(0)
     group_id += 1
     mct -= 1
     return [t.EmberStatus.SUCCESS, entry]
Пример #4
0
    async def subscribe_group(self, group_id):
        # check if already subscribed, if not find a free entry and subscribe group_id

        e = self._ezsp
        index = None
        for entry_id in self._multicast_table.keys():
            if self._multicast_table[entry_id].multicastId == group_id:
                LOGGER.debug("multicast group %s already subscribed", group_id)
                return
            if self._multicast_table[entry_id].endpoint == 0:
                index = entry_id
        if index is None:
            LOGGER.critical("multicast table full,  can not add %s", group_id)
            return
        self._multicast_table[index].endpoint = t.uint8_t(1)
        self._multicast_table[index].multicastId = t.EmberMulticastId(group_id)
        result = await e.setMulticastTableEntry(t.uint8_t(index), self._multicast_table[index])
        return result