Skip to content

Commit

Permalink
Merge pull request #464 from puddly/rc
Browse files Browse the repository at this point in the history
0.31.0 Release
  • Loading branch information
puddly authored Jun 27, 2022
2 parents 0a0e4da + 559bd0a commit 66b2fb4
Show file tree
Hide file tree
Showing 33 changed files with 4,042 additions and 249 deletions.
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,8 @@ ENV/
.*.swp

# Visual Studio Code
.vscode
.vscode


# macOS
.DS_Store
2 changes: 1 addition & 1 deletion bellows/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
MAJOR_VERSION = 0
MINOR_VERSION = 30
MINOR_VERSION = 31
PATCH_VERSION = "0"
__short_version__ = f"{MAJOR_VERSION}.{MINOR_VERSION}"
__version__ = f"{__short_version__}.{PATCH_VERSION}"
5 changes: 3 additions & 2 deletions bellows/ezsp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
import bellows.types as t
import bellows.uart

from . import v4, v5, v6, v7, v8
from . import v4, v5, v6, v7, v8, v9

EZSP_LATEST = v8.EZSP_VERSION
EZSP_LATEST = v9.EZSP_VERSION
PROBE_TIMEOUT = 3
NETWORK_OPS_TIMEOUT = 10
LOGGER = logging.getLogger(__name__)
Expand All @@ -40,6 +40,7 @@ class EZSP:
v6.EZSP_VERSION: v6.EZSPv6,
v7.EZSP_VERSION: v7.EZSPv7,
v8.EZSP_VERSION: v8.EZSPv8,
v9.EZSP_VERSION: v9.EZSPv9,
}

def __init__(self, device_config: Dict):
Expand Down
2 changes: 1 addition & 1 deletion bellows/ezsp/v7/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@
"getChildData": (
0x4A,
(t.uint8_t,),
(t.EmberStatus, t.EmberNodeId, t.EmberEUI64, t.EmberNodeType),
(t.EmberStatus, t.EmberChildData),
),
"getSourceRouteTableTotalSize": (0xC3, (), (t.uint8_t,)),
"getSourceRouteTableFilledSize": (0xC2, (), (t.uint8_t,)),
Expand Down
22 changes: 22 additions & 0 deletions bellows/ezsp/v7/types/struct.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,3 +189,25 @@ class EmberPerDeviceDutyCycle(EzspStruct):
nodeId: named.EmberNodeId
# Amount of overall duty cycle consumed (up to suspend limit).
dutyCycleConsumed: named.EmberDutyCycleHectoPct


class EmberChildData(EzspStruct):
"""A structure containing a child node's data."""

# The EUI64 of the child
eui64: named.EmberEUI64
# The node type of the child
type: named.EmberNodeType
# The short address of the child
id: named.EmberNodeId
# The phy of the child
phy: basic.uint8_t
# The power of the child
power: basic.uint8_t
# The timeout of the child
timeout: basic.uint8_t

# The GPD's EUI64.
# gpdIeeeAddress: named.EmberEUI64
# The GPD's source ID.
# sourceId: basic.uint32_t
2 changes: 1 addition & 1 deletion bellows/ezsp/v8/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@
"getChildData": (
0x004A,
(t.uint8_t,),
(t.EmberStatus, t.EmberNodeId, t.EmberEUI64, t.EmberNodeType),
(t.EmberStatus, t.EmberChildData),
),
"getSourceRouteTableTotalSize": (0x00C3, (), (t.uint8_t,)),
"getSourceRouteTableFilledSize": (0x00C2, (), (t.uint8_t,)),
Expand Down
22 changes: 22 additions & 0 deletions bellows/ezsp/v8/types/struct.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,3 +202,25 @@ class EmberTransientKeyData(EzspStruct):
# The number of seconds remaining before the key is automatically timed out of the
# transient key table.
remainingTimeSeconds: basic.uint16_t


class EmberChildData(EzspStruct):
"""A structure containing a child node's data."""

# The EUI64 of the child
eui64: named.EmberEUI64
# The node type of the child
type: named.EmberNodeType
# The short address of the child
id: named.EmberNodeId
# The phy of the child
phy: basic.uint8_t
# The power of the child
power: basic.uint8_t
# The timeout of the child
timeout: basic.uint8_t

# The GPD's EUI64.
# gpdIeeeAddress: named.EmberEUI64
# The GPD's source ID.
# sourceId: basic.uint32_t
58 changes: 58 additions & 0 deletions bellows/ezsp/v9/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
""""EZSP Protocol version 8 protocol handler."""
import asyncio
import logging
from typing import Tuple

import voluptuous

import bellows.config

from . import commands, config, types as v9_types
from .. import protocol

EZSP_VERSION = 9
LOGGER = logging.getLogger(__name__)


class EZSPv9(protocol.ProtocolHandler):
"""EZSP Version 8 Protocol version handler."""

COMMANDS = commands.COMMANDS
SCHEMAS = {
bellows.config.CONF_EZSP_CONFIG: voluptuous.Schema(config.EZSP_SCHEMA),
bellows.config.CONF_EZSP_POLICIES: voluptuous.Schema(config.EZSP_POLICIES_SCH),
}
types = v9_types

def _ezsp_frame_tx(self, name: str) -> bytes:
"""Serialize the frame id."""
cmd_id = self.COMMANDS[name][0]
hdr = [self._seq, 0x00, 0x01]
return bytes(hdr) + self.types.uint16_t(cmd_id).serialize()

def _ezsp_frame_rx(self, data: bytes) -> Tuple[int, int, bytes]:
"""Handler for received data frame."""
seq, data = data[0], data[3:]
frame_id, data = self.types.uint16_t.deserialize(data)

return seq, frame_id, data

async def pre_permit(self, time_s: int) -> None:
"""Temporarily change TC policy while allowing new joins."""
wild_card_ieee = v9_types.EmberEUI64([0xFF] * 8)
tc_link_key = v9_types.EmberKeyData(b"ZigBeeAlliance09")
await self.addTransientLinkKey(wild_card_ieee, tc_link_key)
await self.setPolicy(
v9_types.EzspPolicyId.TRUST_CENTER_POLICY,
v9_types.EzspDecisionBitmask.ALLOW_JOINS
| v9_types.EzspDecisionBitmask.ALLOW_UNSECURED_REJOINS,
)
await asyncio.sleep(time_s + 2)
await self.setPolicy(
v9_types.EzspPolicyId.TRUST_CENTER_POLICY,
self.tc_policy,
)

async def set_source_routing(self) -> None:
"""Enable source routing on NCP."""
await self.setSourceRouteDiscoveryMode(1)
Loading

0 comments on commit 66b2fb4

Please sign in to comment.