Skip to content

Commit

Permalink
Merge pull request #31 from kardia-as/fix-form-network
Browse files Browse the repository at this point in the history
Fix form network
  • Loading branch information
DamKast authored Nov 14, 2023
2 parents 6d7b5e0 + 8b8731e commit 55cf1b4
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 19 deletions.
4 changes: 3 additions & 1 deletion zigpy_zboss/uart.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ async def connect(config: conf.ConfigType, api) -> ZbossNcpProtocol:
baudrate = config[conf.CONF_DEVICE_BAUDRATE]
flow_control = config[conf.CONF_DEVICE_FLOW_CONTROL]

LOGGER.info("Connecting to %s at %s baud", port, baudrate)
LOGGER.debug("Connecting to %s at %s baud", port, baudrate)

_, protocol = await zigpy.serial.create_serial_connection(
loop=loop,
Expand All @@ -293,4 +293,6 @@ async def connect(config: conf.ConfigType, api) -> ZbossNcpProtocol:
protocol.close()
raise RuntimeError("Could not communicate with NCP!")

LOGGER.debug("Connected to %s at %s baud", port, baudrate)

return protocol
37 changes: 19 additions & 18 deletions zigpy_zboss/zigbee/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,19 +130,20 @@ def get_default_stack_specific_formation_settings(self):

async def write_network_info(self, *, network_info, node_info):
"""Write the provided network and node info to the radio hardware."""
network_info.stack_specific = \
self.get_default_stack_specific_formation_settings()
if node_info.ieee == t.EUI64.UNKNOWN:
node_info.ieee = network_info.extended_pan_id
if not network_info.stack_specific.get("form_quickly", False):
await self.reset_network_info()

# Write self.state.node_info.
await self._api.request(
c.NcpConfig.SetLocalIEEE.Req(
TSN=self.get_sequence(),
MacInterfaceNum=0,
IEEE=node_info.ieee
)
network_info.stack_specific.update(
self.get_default_stack_specific_formation_settings()
)
if node_info.ieee != t.EUI64.UNKNOWN:
await self._api.request(
c.NcpConfig.SetLocalIEEE.Req(
TSN=self.get_sequence(),
MacInterfaceNum=0,
IEEE=node_info.ieee
)
)

await self._api.request(
request=c.NcpConfig.SetZigbeeRole.Req(
Expand Down Expand Up @@ -173,6 +174,10 @@ async def write_network_info(self, *, network_info, node_info):
)
)

if network_info.stack_specific.get("form_quickly", False):
await self._form_network(network_info, node_info)
return

await self._api.request(
request=c.NcpConfig.SetNwkKey.Req(
TSN=self.get_sequence(),
Expand Down Expand Up @@ -294,6 +299,7 @@ async def load_network_info(self, *, load_devices=False):
"""Populate state.node_info and state.network_info."""
res = await self._api.request(
c.NcpConfig.GetJoinStatus.Req(TSN=self.get_sequence()))
self.state.network_info.stack_specific["joined"] = res.Joined
if not res.Joined & 0x01:
raise zigpy.exceptions.NetworkNotFormed

Expand Down Expand Up @@ -390,12 +396,6 @@ async def load_network_info(self, *, load_devices=False):
"max_children"
] = res.ChildrenNbr

res = await self._api.request(
c.NcpConfig.GetJoinStatus.Req(TSN=self.get_sequence()))
self.state.network_info.stack_specific[
"joined"
] = res.Joined

res = await self._api.request(
c.NcpConfig.GetAuthenticationStatus.Req(TSN=self.get_sequence()))
self.state.network_info.stack_specific[
Expand Down Expand Up @@ -440,7 +440,8 @@ async def load_network_info(self, *, load_devices=False):

async def reset_network_info(self) -> None:
"""Reset node network information and leaves the current network."""
pass
assert self._api is not None
await self._api.reset(option=t_zboss.ResetOptions.FactoryReset)

async def start_without_formation(self):
"""Start the network with settings currently stored on the module."""
Expand Down

0 comments on commit 55cf1b4

Please sign in to comment.