Skip to content

Commit cc3045d

Browse files
committed
Include CHANNELS_LIST
1 parent 40e94cd commit cc3045d

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

zigpy_cli/common.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import click
2+
from zigpy.types import Channels
23

34

45
class HexOrDecIntParamType(click.ParamType):
@@ -17,4 +18,18 @@ def convert(self, value, param, ctx):
1718
self.fail(f"{value!r} is not a valid integer", param, ctx)
1819

1920

21+
class ChannelsType(click.ParamType):
22+
name = "channels"
23+
24+
def convert(self, value, param, ctx):
25+
if isinstance(value, Channels):
26+
return value
27+
28+
try:
29+
return Channels.from_channel_list(map(int, value.split(",")))
30+
except ValueError:
31+
self.fail(f"{value!r} is not a valid channel list", param, ctx)
32+
33+
2034
HEX_OR_DEC_INT = HexOrDecIntParamType()
35+
CHANNELS_LIST = ChannelsType()

0 commit comments

Comments
 (0)