Skip to content

Commit

Permalink
Fix CLI (#596)
Browse files Browse the repository at this point in the history
  • Loading branch information
puddly authored Nov 20, 2023
1 parent 6b85794 commit f466452
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 42 deletions.
7 changes: 3 additions & 4 deletions bellows/cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import click
import click_log
import zigpy.config

from . import opts

Expand All @@ -15,9 +14,9 @@
@click.pass_context
def main(ctx, device, baudrate, flow_control):
ctx.obj = {
zigpy.config.CONF_DEVICE_PATH: device,
zigpy.config.CONF_DEVICE_BAUDRATE: baudrate,
zigpy.config.CONF_DEVICE_FLOW_CONTROL: flow_control,
"device": device,
"baudrate": baudrate,
"flow_control": flow_control,
}
click_log.basic_config()

Expand Down
3 changes: 1 addition & 2 deletions bellows/cli/opts.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import os

import click
from zigpy.config import CONF_DEVICE_FLOW_CONTROL

from . import util

Expand Down Expand Up @@ -61,7 +60,7 @@
flow_control = click.option(
"--flow-control",
default="software",
type=click.Choice(CONF_DEVICE_FLOW_CONTROL),
type=click.Choice(["hardware", "software", "None"]),
envvar="EZSP_FLOW_CONTROL",
help="use hardware flow control",
)
Expand Down
56 changes: 20 additions & 36 deletions bellows/cli/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import click
import zigpy.config as zigpy_conf

import bellows.config as config
import bellows.ezsp
import bellows.types as t

Expand Down Expand Up @@ -50,10 +49,10 @@ async def async_inner(ctx, *args, **kwargs):
nonlocal database_file
nonlocal application
app_config = {
config.CONF_DEVICE: {
config.CONF_DEVICE_PATH: ctx.obj[config.CONF_DEVICE],
config.CONF_DEVICE_BAUDRATE: ctx.obj[config.CONF_DEVICE_BAUDRATE],
config.CONF_FLOW_CONTROL: ctx.obj[config.CONF_FLOW_CONTROL],
zigpy_conf.CONF_DEVICE: {
zigpy_conf.CONF_DEVICE_PATH: ctx.obj["device"],
zigpy_conf.CONF_DEVICE_BAUDRATE: ctx.obj["baudrate"],
zigpy_conf.CONF_FLOW_CONTROL: ctx.obj["flow_control"],
},
zigpy_conf.CONF_DATABASE: ctx.obj["database_file"],
}
Expand Down Expand Up @@ -100,38 +99,23 @@ def channel_mask(channels):


async def setup(dev, baudrate, cbh=None, configure=True):
device_config = {
config.CONF_DEVICE_PATH: dev,
config.CONF_DEVICE_BAUDRATE: baudrate,
config.CONF_FLOW_CONTROL: config.CONF_FLOW_CONTROL_DEFAULT,
}
s = bellows.ezsp.EZSP(device_config)
app_config = bellows.zigbee.application.ControllerApplication.SCHEMA(
{
zigpy_conf.CONF_DEVICE: {
zigpy_conf.CONF_DEVICE_PATH: dev,
zigpy_conf.CONF_DEVICE_BAUDRATE: baudrate,
zigpy_conf.CONF_DEVICE_FLOW_CONTROL: zigpy_conf.CONF_DEVICE_FLOW_CONTROL_DEFAULT,
}
}
)

app = bellows.zigbee.application.ControllerApplication(app_config)
await app.connect()

if cbh:
s.add_callback(cbh)
try:
await s.connect()
await s.startup_reset()
except Exception as e:
LOGGER.error(e)
s.close()
raise click.Abort()
LOGGER.debug("Connected")
await s.version()

async def cfg(config_id, value):
v = await s.setConfigurationValue(config_id, value)
check(v[0], f"Setting config {config_id} to {value}: {v[0]}")

c = s.types.EzspConfigId

if configure:
LOGGER.debug("Configuring...")
await cfg(c.CONFIG_STACK_PROFILE, 2)
await cfg(c.CONFIG_SECURITY_LEVEL, 5)
await cfg(c.CONFIG_SUPPORTED_NETWORKS, 1)
await cfg(c.CONFIG_PACKET_BUFFER_COUNT, 64)

return s
app._ezsp.add_callback(cbh)

return app._ezsp


async def setup_application(app_config, startup=True):
Expand Down

0 comments on commit f466452

Please sign in to comment.