File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 55from .blueprint_command import BlueprintCommand
66from .command_command import CommandCommand
77from .device_command import DeviceCommand
8+ from .rule_engine_command import RuleEngineCommand
89from .site_command import SiteCommand
910from .telemetry_command import TelemetryCommand
1011
@@ -21,6 +22,7 @@ def register(parent: cli.Subparsers) -> None:
2122 BlueprintCommand ,
2223 CommandCommand ,
2324 DeviceCommand ,
25+ RuleEngineCommand ,
2426 SiteCommand ,
2527 TelemetryCommand ,
2628 ]:
@@ -35,9 +37,11 @@ async def run(args: argparse.Namespace) -> None:
3537 await CommandCommand .run (args )
3638 case "device" :
3739 await DeviceCommand .run (args )
40+ case "rule-engine" :
41+ await RuleEngineCommand .run (args )
3842 case "site" :
3943 await SiteCommand .run (args )
4044 case "telemetry" :
4145 await TelemetryCommand .run (args )
4246 case _:
43- raise NotImplementedError (args .device_command )
47+ raise NotImplementedError (args .api_command )
Original file line number Diff line number Diff line change 1+ """Rule Engine command group."""
2+
3+ import argparse
4+
5+ from enapter import cli
6+
7+ from .rule_engine_get_command import RuleEngineGetCommand
8+ from .rule_engine_resume_command import RuleEngineResumeCommand
9+ from .rule_engine_suspend_command import RuleEngineSuspendCommand
10+
11+
12+ class RuleEngineCommand (cli .Command ):
13+ """Command group for Rule Engine management."""
14+
15+ @staticmethod
16+ def register (parent : cli .Subparsers ) -> None :
17+ """Register the command group in the subparsers."""
18+ parser = parent .add_parser (
19+ "rule-engine" , formatter_class = argparse .ArgumentDefaultsHelpFormatter
20+ )
21+ subparsers = parser .add_subparsers (dest = "rule_engine_command" , required = True )
22+ for command in [
23+ RuleEngineGetCommand ,
24+ RuleEngineSuspendCommand ,
25+ RuleEngineResumeCommand ,
26+ ]:
27+ command .register (subparsers )
28+
29+ @staticmethod
30+ async def run (args : argparse .Namespace ) -> None :
31+ """Run the sub-command."""
32+ match args .rule_engine_command :
33+ case "get" :
34+ await RuleEngineGetCommand .run (args )
35+ case "suspend" :
36+ await RuleEngineSuspendCommand .run (args )
37+ case "resume" :
38+ await RuleEngineResumeCommand .run (args )
39+ case _:
40+ raise NotImplementedError (args .rule_engine_command )
Original file line number Diff line number Diff line change 1+ """Rule Engine get command."""
2+
3+ import argparse
4+ import json
5+
6+ from enapter import cli , http
7+
8+
9+ class RuleEngineGetCommand (cli .Command ):
10+ """Command to get the rule engine state."""
11+
12+ @staticmethod
13+ def register (parent : cli .Subparsers ) -> None :
14+ """Register the command in the subparsers."""
15+ parser = parent .add_parser (
16+ "get" , formatter_class = argparse .ArgumentDefaultsHelpFormatter
17+ )
18+ parser .add_argument ("-s" , "--site-id" , help = "ID of the site to retrieve" )
19+
20+ @staticmethod
21+ async def run (args : argparse .Namespace ) -> None :
22+ """Run the command."""
23+ async with http .api .Client (http .api .Config .from_env ()) as client :
24+ engine = await client .rule_engine .get (site_id = args .site_id )
25+ print (json .dumps (engine .to_dto ()))
Original file line number Diff line number Diff line change 1+ """Rule Engine resume command."""
2+
3+ import argparse
4+ import json
5+
6+ from enapter import cli , http
7+
8+
9+ class RuleEngineResumeCommand (cli .Command ):
10+ """Command to resume the rule engine."""
11+
12+ @staticmethod
13+ def register (parent : cli .Subparsers ) -> None :
14+ """Register the command in the subparsers."""
15+ parser = parent .add_parser (
16+ "resume" , formatter_class = argparse .ArgumentDefaultsHelpFormatter
17+ )
18+ parser .add_argument ("-s" , "--site-id" , help = "ID of the site to resume" )
19+
20+ @staticmethod
21+ async def run (args : argparse .Namespace ) -> None :
22+ """Run the command."""
23+ async with http .api .Client (http .api .Config .from_env ()) as client :
24+ engine = await client .rule_engine .resume (site_id = args .site_id )
25+ print (json .dumps (engine .to_dto ()))
Original file line number Diff line number Diff line change 1+ """Rule Engine suspend command."""
2+
3+ import argparse
4+ import json
5+
6+ from enapter import cli , http
7+
8+
9+ class RuleEngineSuspendCommand (cli .Command ):
10+ """Command to suspend the rule engine."""
11+
12+ @staticmethod
13+ def register (parent : cli .Subparsers ) -> None :
14+ """Register the command in the subparsers."""
15+ parser = parent .add_parser (
16+ "suspend" , formatter_class = argparse .ArgumentDefaultsHelpFormatter
17+ )
18+ parser .add_argument ("-s" , "--site-id" , help = "ID of the site to suspend" )
19+
20+ @staticmethod
21+ async def run (args : argparse .Namespace ) -> None :
22+ """Run the command."""
23+ async with http .api .Client (http .api .Config .from_env ()) as client :
24+ engine = await client .rule_engine .suspend (site_id = args .site_id )
25+ print (json .dumps (engine .to_dto ()))
You can’t perform that action at this time.
0 commit comments