1
- from .cli import Flag , cli
2
- from .exceptions import HostNotFoundWarning
1
+ from .cli import Flag
3
2
from .history import history
4
3
from .host import host
5
- from .log import cli_error , cli_info , cli_warning
6
- from .util import (
7
- host_info_by_name ,
8
- print_table ,
9
- get ,
10
- get_list ,
11
- post ,
12
- delete ,
13
- )
4
+ from .log import cli_error , cli_info
5
+ from .util import delete , get , get_list , host_info_by_name , post , print_table
6
+
14
7
15
8
def bacnetid_add (args ):
16
9
info = host_info_by_name (args .name )
17
- if 'bacnetid' in info and info ['bacnetid' ] is not None :
18
- cli_error ("{} already has BACnet ID {}." .format (info ['name' ],info ['bacnetid' ]['id' ]))
19
- postdata = {'hostname' : info ['name' ]}
20
- path = '/api/v1/bacnet/ids/'
21
- bacnetid = getattr (args , 'id' )
10
+ if "bacnetid" in info and info ["bacnetid" ] is not None :
11
+ cli_error (
12
+ "{} already has BACnet ID {}." .format (info ["name" ], info ["bacnetid" ]["id" ])
13
+ )
14
+ postdata = {"hostname" : info ["name" ]}
15
+ path = "/api/v1/bacnet/ids/"
16
+ bacnetid = args .id
22
17
if bacnetid :
23
- response = get (path + bacnetid , ok404 = True )
18
+ response = get (path + bacnetid , ok404 = True )
24
19
if response :
25
20
j = response .json ()
26
- cli_error ('BACnet ID {} is already in use by {}' .format (j ['id' ], j ['hostname' ]))
27
- postdata ['id' ] = bacnetid
28
- history .record_post (path , '' , postdata )
21
+ cli_error (
22
+ "BACnet ID {} is already in use by {}" .format (j ["id" ], j ["hostname" ])
23
+ )
24
+ postdata ["id" ] = bacnetid
25
+ history .record_post (path , "" , postdata )
29
26
post (path , ** postdata )
30
27
info = host_info_by_name (args .name )
31
- if 'bacnetid' in info and info ['bacnetid' ] is not None :
32
- b = info ['bacnetid' ]
33
- cli_info ("Assigned BACnet ID {} to {}" .format (b ['id' ], info ['name' ]), print_msg = True )
28
+ if "bacnetid" in info and info ["bacnetid" ] is not None :
29
+ b = info ["bacnetid" ]
30
+ cli_info (
31
+ "Assigned BACnet ID {} to {}" .format (b ["id" ], info ["name" ]), print_msg = True
32
+ )
34
33
35
34
36
35
host .add_command (
37
- prog = ' bacnetid_add' ,
38
- description = ' Assign a BACnet ID to the host.' ,
39
- short_desc = ' Add BACnet ID' ,
36
+ prog = " bacnetid_add" ,
37
+ description = " Assign a BACnet ID to the host." ,
38
+ short_desc = " Add BACnet ID" ,
40
39
callback = bacnetid_add ,
41
40
flags = [
42
- Flag ('name' ,
43
- description = 'Name of host.' ,
44
- metavar = 'NAME' ),
45
- Flag ('-id' ,
46
- description = 'ID value (0-4194302)' ,
47
- metavar = 'ID' ),
41
+ Flag ("name" , description = "Name of host." , metavar = "NAME" ),
42
+ Flag ("-id" , description = "ID value (0-4194302)" , metavar = "ID" ),
48
43
],
49
44
)
50
45
46
+
51
47
def bacnetid_remove (args ):
52
48
info = host_info_by_name (args .name )
53
- if ' bacnetid' not in info or info ["bacnetid" ] is None :
54
- cli_error ("{} does not have a BACnet ID assigned." .format (info [' name' ]))
55
- path = ' /api/v1/bacnet/ids/{}' .format (info [' bacnetid' ][ 'id' ])
56
- history .record_delete (path , info [' bacnetid' ])
49
+ if " bacnetid" not in info or info ["bacnetid" ] is None :
50
+ cli_error ("{} does not have a BACnet ID assigned." .format (info [" name" ]))
51
+ path = " /api/v1/bacnet/ids/{}" .format (info [" bacnetid" ][ "id" ])
52
+ history .record_delete (path , info [" bacnetid" ])
57
53
delete (path )
58
- cli_info ("Unassigned BACnet ID {} from {}" .format (info ['bacnetid' ]['id' ], info ['name' ]), print_msg = True )
54
+ cli_info (
55
+ "Unassigned BACnet ID {} from {}" .format (info ["bacnetid" ]["id" ], info ["name" ]),
56
+ print_msg = True ,
57
+ )
58
+
59
59
60
60
host .add_command (
61
- prog = ' bacnetid_remove' ,
62
- description = ' Unassign the BACnet ID from the host.' ,
63
- short_desc = ' Remove BACnet ID' ,
61
+ prog = " bacnetid_remove" ,
62
+ description = " Unassign the BACnet ID from the host." ,
63
+ short_desc = " Remove BACnet ID" ,
64
64
callback = bacnetid_remove ,
65
65
flags = [
66
- Flag ('name' ,
67
- description = 'Name of host.' ,
68
- metavar = 'NAME' ),
66
+ Flag ("name" , description = "Name of host." , metavar = "NAME" ),
69
67
],
70
68
)
71
69
@@ -81,22 +79,27 @@ def bacnetid_list(args):
81
79
maxval = args .max
82
80
if maxval > 4194302 :
83
81
cli_error ("The maximum ID value is 4194302." )
84
- r = get_list ("/api/v1/bacnet/ids/" ,{'id__range' :'{},{}' .format (minval ,maxval )})
85
- print_table (('ID' ,'Hostname' ), ('id' ,'hostname' ), r )
82
+ r = get_list ("/api/v1/bacnet/ids/" , {"id__range" : "{},{}" .format (minval , maxval )})
83
+ print_table (("ID" , "Hostname" ), ("id" , "hostname" ), r )
84
+
86
85
87
86
host .add_command (
88
- prog = ' bacnetid_list' ,
89
- description = ' Find/list BACnet IDs and hostnames' ,
90
- short_desc = ' List used BACnet IDs' ,
87
+ prog = " bacnetid_list" ,
88
+ description = " Find/list BACnet IDs and hostnames" ,
89
+ short_desc = " List used BACnet IDs" ,
91
90
callback = bacnetid_list ,
92
91
flags = [
93
- Flag ('-min' ,
94
- description = 'Minimum ID value (0-4194302)' ,
95
- type = int ,
96
- metavar = 'MIN' ),
97
- Flag ('-max' ,
98
- description = 'Maximum ID value (0-4194302)' ,
99
- type = int ,
100
- metavar = 'MAX' ),
92
+ Flag (
93
+ "-min" ,
94
+ description = "Minimum ID value (0-4194302)" ,
95
+ flag_type = int ,
96
+ metavar = "MIN" ,
97
+ ),
98
+ Flag (
99
+ "-max" ,
100
+ description = "Maximum ID value (0-4194302)" ,
101
+ flag_type = int ,
102
+ metavar = "MAX" ,
103
+ ),
101
104
],
102
105
)
0 commit comments