Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix form network #31

Merged
merged 2 commits into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading