conson-xp 1.51.1__py3-none-any.whl → 2.0.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. {conson_xp-1.51.1.dist-info → conson_xp-2.0.0.dist-info}/METADATA +1 -11
  2. {conson_xp-1.51.1.dist-info → conson_xp-2.0.0.dist-info}/RECORD +20 -38
  3. xp/__init__.py +1 -1
  4. xp/cli/commands/__init__.py +0 -4
  5. xp/cli/commands/term/term_commands.py +1 -1
  6. xp/cli/main.py +0 -3
  7. xp/models/homekit/homekit_config.py +4 -0
  8. xp/models/protocol/conbus_protocol.py +30 -25
  9. xp/models/term/accessory_state.py +1 -1
  10. xp/services/protocol/__init__.py +2 -3
  11. xp/services/protocol/conbus_event_protocol.py +5 -5
  12. xp/services/term/homekit_accessory_driver.py +171 -0
  13. xp/services/term/homekit_service.py +187 -10
  14. xp/term/homekit.py +146 -14
  15. xp/term/homekit.tcss +4 -4
  16. xp/term/widgets/room_list.py +61 -3
  17. xp/utils/dependencies.py +34 -154
  18. xp/cli/commands/homekit/__init__.py +0 -3
  19. xp/cli/commands/homekit/homekit.py +0 -120
  20. xp/cli/commands/homekit/homekit_start_commands.py +0 -44
  21. xp/services/homekit/__init__.py +0 -1
  22. xp/services/homekit/homekit_cache_service.py +0 -313
  23. xp/services/homekit/homekit_conbus_service.py +0 -99
  24. xp/services/homekit/homekit_config_validator.py +0 -327
  25. xp/services/homekit/homekit_conson_validator.py +0 -130
  26. xp/services/homekit/homekit_dimminglight.py +0 -189
  27. xp/services/homekit/homekit_dimminglight_service.py +0 -155
  28. xp/services/homekit/homekit_hap_service.py +0 -351
  29. xp/services/homekit/homekit_lightbulb.py +0 -125
  30. xp/services/homekit/homekit_lightbulb_service.py +0 -91
  31. xp/services/homekit/homekit_module_service.py +0 -60
  32. xp/services/homekit/homekit_outlet.py +0 -175
  33. xp/services/homekit/homekit_outlet_service.py +0 -127
  34. xp/services/homekit/homekit_service.py +0 -371
  35. xp/services/protocol/protocol_factory.py +0 -84
  36. xp/services/protocol/telegram_protocol.py +0 -270
  37. {conson_xp-1.51.1.dist-info → conson_xp-2.0.0.dist-info}/WHEEL +0 -0
  38. {conson_xp-1.51.1.dist-info → conson_xp-2.0.0.dist-info}/entry_points.txt +0 -0
  39. {conson_xp-1.51.1.dist-info → conson_xp-2.0.0.dist-info}/licenses/LICENSE +0 -0
xp/utils/dependencies.py CHANGED
@@ -1,9 +1,7 @@
1
1
  """Dependency injection container for XP services."""
2
2
 
3
3
  import punq
4
- from bubus import EventBus
5
4
  from twisted.internet import asyncioreactor
6
- from twisted.internet.interfaces import IConnector
7
5
  from twisted.internet.posixbase import PosixReactorBase
8
6
 
9
7
  from xp.models import ConbusClientConfig
@@ -55,19 +53,9 @@ from xp.services.conbus.conbus_raw_service import ConbusRawService
55
53
  from xp.services.conbus.conbus_receive_service import ConbusReceiveService
56
54
  from xp.services.conbus.conbus_scan_service import ConbusScanService
57
55
  from xp.services.conbus.write_config_service import WriteConfigService
58
- from xp.services.homekit.homekit_cache_service import HomeKitCacheService
59
- from xp.services.homekit.homekit_conbus_service import HomeKitConbusService
60
- from xp.services.homekit.homekit_dimminglight_service import HomeKitDimmingLightService
61
- from xp.services.homekit.homekit_hap_service import HomekitHapService
62
- from xp.services.homekit.homekit_lightbulb_service import HomeKitLightbulbService
63
- from xp.services.homekit.homekit_module_service import HomekitModuleService
64
- from xp.services.homekit.homekit_outlet_service import HomeKitOutletService
65
- from xp.services.homekit.homekit_service import HomeKitService
66
56
  from xp.services.log_file_service import LogFileService
67
57
  from xp.services.module_type_service import ModuleTypeService
68
58
  from xp.services.protocol import ConbusEventProtocol
69
- from xp.services.protocol.protocol_factory import TelegramFactory
70
- from xp.services.protocol.telegram_protocol import TelegramProtocol
71
59
  from xp.services.reverse_proxy_service import ReverseProxyService
72
60
  from xp.services.server.device_service_factory import DeviceServiceFactory
73
61
  from xp.services.server.server_service import ServerService
@@ -77,6 +65,7 @@ from xp.services.telegram.telegram_discover_service import TelegramDiscoverServi
77
65
  from xp.services.telegram.telegram_link_number_service import LinkNumberService
78
66
  from xp.services.telegram.telegram_output_service import TelegramOutputService
79
67
  from xp.services.telegram.telegram_service import TelegramService
68
+ from xp.services.term.homekit_accessory_driver import HomekitAccessoryDriver
80
69
  from xp.services.term.homekit_service import HomekitService
81
70
  from xp.services.term.protocol_monitor_service import ProtocolMonitorService
82
71
  from xp.services.term.state_monitor_service import StateMonitorService
@@ -168,7 +157,24 @@ class ServiceContainer:
168
157
  self.container.register(TelegramDatapointService, scope=punq.Scope.singleton)
169
158
  self.container.register(LinkNumberService, scope=punq.Scope.singleton)
170
159
 
160
+ # Reactor
161
+ self.container.register(
162
+ PosixReactorBase,
163
+ factory=lambda: reactor,
164
+ scope=punq.Scope.singleton,
165
+ )
166
+
171
167
  # Conbus services layer
168
+ self.container.register(
169
+ ConbusEventProtocol,
170
+ factory=lambda: ConbusEventProtocol(
171
+ cli_config=self.container.resolve(ConbusClientConfig),
172
+ reactor=self.container.resolve(PosixReactorBase),
173
+ telegram_service=self.container.resolve(TelegramService),
174
+ ),
175
+ scope=punq.Scope.singleton,
176
+ )
177
+
172
178
  self.container.register(
173
179
  ConbusDatapointService,
174
180
  factory=lambda: ConbusDatapointService(
@@ -195,16 +201,6 @@ class ServiceContainer:
195
201
  scope=punq.Scope.singleton,
196
202
  )
197
203
 
198
- self.container.register(
199
- ConbusEventProtocol,
200
- factory=lambda: ConbusEventProtocol(
201
- cli_config=self.container.resolve(ConbusClientConfig),
202
- reactor=self.container.resolve(PosixReactorBase),
203
- telegram_service=self.container.resolve(TelegramService),
204
- ),
205
- scope=punq.Scope.singleton,
206
- )
207
-
208
204
  self.container.register(
209
205
  ConbusDiscoverService,
210
206
  factory=lambda: ConbusDiscoverService(
@@ -267,6 +263,21 @@ class ServiceContainer:
267
263
  scope=punq.Scope.singleton,
268
264
  )
269
265
 
266
+ # HomeKit config
267
+ self.container.register(
268
+ HomekitConfig,
269
+ factory=lambda: HomekitConfig.from_yaml(self._homekit_config_path),
270
+ scope=punq.Scope.singleton,
271
+ )
272
+
273
+ self.container.register(
274
+ HomekitAccessoryDriver,
275
+ factory=lambda: HomekitAccessoryDriver(
276
+ homekit_config=self.container.resolve(HomekitConfig),
277
+ ),
278
+ scope=punq.Scope.singleton,
279
+ )
280
+
270
281
  self.container.register(
271
282
  HomekitService,
272
283
  factory=lambda: HomekitService(
@@ -274,6 +285,7 @@ class ServiceContainer:
274
285
  homekit_config=self.container.resolve(HomekitConfig),
275
286
  conson_config=self.container.resolve(ConsonModuleListConfig),
276
287
  telegram_service=self.container.resolve(TelegramService),
288
+ accessory_driver=self.container.resolve(HomekitAccessoryDriver),
277
289
  ),
278
290
  scope=punq.Scope.singleton,
279
291
  )
@@ -431,39 +443,6 @@ class ServiceContainer:
431
443
  scope=punq.Scope.singleton,
432
444
  )
433
445
 
434
- # HomeKit services layer
435
- self.container.register(
436
- HomekitModuleService,
437
- factory=lambda: HomekitModuleService(
438
- conson_modules_config=self.container.resolve(ConsonModuleListConfig),
439
- ),
440
- scope=punq.Scope.singleton,
441
- )
442
-
443
- # Create event bus
444
- self.container.register(
445
- EventBus,
446
- factory=lambda: EventBus(max_history_size=500),
447
- scope=punq.Scope.singleton,
448
- )
449
-
450
- # HomeKit conson config
451
- self.container.register(
452
- HomekitConfig,
453
- factory=lambda: HomekitConfig.from_yaml(self._homekit_config_path),
454
- scope=punq.Scope.singleton,
455
- )
456
-
457
- self.container.register(
458
- HomekitHapService,
459
- factory=lambda: HomekitHapService(
460
- homekit_config=self.container.resolve(HomekitConfig),
461
- module_service=self.container.resolve(HomekitModuleService),
462
- event_bus=self.container.resolve(EventBus),
463
- ),
464
- scope=punq.Scope.singleton,
465
- )
466
-
467
446
  # Log file services layer
468
447
  self.container.register(
469
448
  LogFileService,
@@ -526,105 +505,6 @@ class ServiceContainer:
526
505
  scope=punq.Scope.singleton,
527
506
  )
528
507
 
529
- # Create protocol with built-in debouncing
530
- self.container.register(
531
- TelegramProtocol,
532
- factory=lambda: TelegramProtocol(
533
- event_bus=self.container.resolve(EventBus),
534
- debounce_ms=50,
535
- ),
536
- scope=punq.Scope.singleton,
537
- )
538
-
539
- self.container.register(
540
- IConnector,
541
- factory=lambda: reactor,
542
- scope=punq.Scope.singleton,
543
- )
544
-
545
- self.container.register(
546
- TelegramFactory,
547
- factory=lambda: TelegramFactory(
548
- event_bus=self.container.resolve(EventBus),
549
- telegram_protocol=self.container.resolve(TelegramProtocol),
550
- connector=self.container.resolve(IConnector),
551
- ),
552
- scope=punq.Scope.singleton,
553
- )
554
-
555
- self.container.register(
556
- PosixReactorBase,
557
- factory=lambda: reactor,
558
- scope=punq.Scope.singleton,
559
- )
560
-
561
- self.container.register(
562
- HomeKitLightbulbService,
563
- factory=lambda: HomeKitLightbulbService(
564
- event_bus=self.container.resolve(EventBus),
565
- ),
566
- scope=punq.Scope.singleton,
567
- )
568
-
569
- self.container.register(
570
- HomeKitOutletService,
571
- factory=lambda: HomeKitOutletService(
572
- event_bus=self.container.resolve(EventBus),
573
- ),
574
- scope=punq.Scope.singleton,
575
- )
576
-
577
- self.container.register(
578
- HomeKitDimmingLightService,
579
- factory=lambda: HomeKitDimmingLightService(
580
- event_bus=self.container.resolve(EventBus),
581
- ),
582
- scope=punq.Scope.singleton,
583
- )
584
-
585
- # Cache service must be registered BEFORE HomeKitConbusService
586
- # so it intercepts ReadDatapointEvent first
587
- self.container.register(
588
- HomeKitCacheService,
589
- factory=lambda: HomeKitCacheService(
590
- event_bus=self.container.resolve(EventBus),
591
- ),
592
- scope=punq.Scope.singleton,
593
- )
594
-
595
- self.container.register(
596
- HomeKitConbusService,
597
- factory=lambda: HomeKitConbusService(
598
- event_bus=self.container.resolve(EventBus),
599
- telegram_protocol=self.container.resolve(TelegramProtocol),
600
- ),
601
- scope=punq.Scope.singleton,
602
- )
603
-
604
- self.container.register(
605
- TelegramService,
606
- factory=TelegramService,
607
- scope=punq.Scope.singleton,
608
- )
609
-
610
- self.container.register(
611
- HomeKitService,
612
- factory=lambda: HomeKitService(
613
- cli_config=self.container.resolve(ConbusClientConfig),
614
- event_bus=self.container.resolve(EventBus),
615
- telegram_factory=self.container.resolve(TelegramFactory),
616
- reactor=self.container.resolve(PosixReactorBase),
617
- lightbulb_service=self.container.resolve(HomeKitLightbulbService),
618
- outlet_service=self.container.resolve(HomeKitOutletService),
619
- dimminglight_service=self.container.resolve(HomeKitDimmingLightService),
620
- cache_service=self.container.resolve(HomeKitCacheService),
621
- conbus_service=self.container.resolve(HomeKitConbusService),
622
- module_factory=self.container.resolve(HomekitHapService),
623
- telegram_service=self.container.resolve(TelegramService),
624
- ),
625
- scope=punq.Scope.singleton,
626
- )
627
-
628
508
  def _load_protocol_keys(self) -> "ProtocolKeysConfig":
629
509
  """
630
510
  Load protocol keys from YAML config file.
@@ -1,3 +0,0 @@
1
- """HomeKit CLI commands package."""
2
-
3
- __all__ = []
@@ -1,120 +0,0 @@
1
- """HomeKit management CLI commands."""
2
-
3
- import click
4
- from click_help_colors import HelpColorsGroup
5
-
6
- from xp.cli.utils.decorators import service_command
7
-
8
-
9
- @click.group(
10
- cls=HelpColorsGroup, help_headers_color="yellow", help_options_color="green"
11
- )
12
- def homekit() -> None:
13
- """Manage the HomeKit server for XP Protocol operations."""
14
- pass
15
-
16
-
17
- @homekit.group(
18
- cls=HelpColorsGroup, help_headers_color="yellow", help_options_color="green"
19
- )
20
- def config() -> None:
21
- """Manage HomeKit configuration."""
22
- pass
23
-
24
-
25
- @config.command()
26
- @click.option(
27
- "--conson-config",
28
- default="conson.yml",
29
- help="Path to conson.yml configuration file",
30
- )
31
- @click.option(
32
- "--homekit-config",
33
- default="homekit.yml",
34
- help="Path to homekit.yml configuration file",
35
- )
36
- @service_command()
37
- def validate(conson_config: str, homekit_config: str) -> None:
38
- """
39
- Validate homekit.yml and conson.yml coherence.
40
-
41
- Args:
42
- conson_config: Path to conson.yml configuration file.
43
- homekit_config: Path to homekit.yml configuration file.
44
- """
45
- from xp.services.homekit.homekit_config_validator import ConfigValidationService
46
-
47
- try:
48
- validator = ConfigValidationService(conson_config, homekit_config)
49
- results = validator.validate_all()
50
-
51
- if results["is_valid"]:
52
- click.echo(click.style("✓ Configuration validation passed", fg="green"))
53
- else:
54
- click.echo(
55
- click.style(
56
- f"✗ Configuration validation failed with {results['total_errors']} errors",
57
- fg="red",
58
- )
59
- )
60
-
61
- if results["conson_errors"]:
62
- click.echo(
63
- click.style("\nConson Configuration Errors:", fg="red", bold=True)
64
- )
65
- for error in results["conson_errors"]:
66
- click.echo(f" - {error}")
67
-
68
- if results["homekit_errors"]:
69
- click.echo(
70
- click.style("\nHomeKit Configuration Errors:", fg="red", bold=True)
71
- )
72
- for error in results["homekit_errors"]:
73
- click.echo(f" - {error}")
74
-
75
- if results["cross_reference_errors"]:
76
- click.echo(
77
- click.style("\nCross-Reference Errors:", fg="red", bold=True)
78
- )
79
- for error in results["cross_reference_errors"]:
80
- click.echo(f" - {error}")
81
-
82
- exit(1)
83
-
84
- except Exception as e:
85
- click.echo(click.style(f"✗ Validation failed: {e}", fg="red"))
86
- exit(1)
87
-
88
-
89
- @config.command("show")
90
- @click.option(
91
- "--conson-config",
92
- default="conson.yml",
93
- help="Path to conson.yml configuration file",
94
- )
95
- @click.option(
96
- "--homekit-config",
97
- default="homekit.yml",
98
- help="Path to homekit.yml configuration file",
99
- )
100
- @service_command()
101
- def show_config(conson_config: str, homekit_config: str) -> None:
102
- """
103
- Display parsed configuration summary.
104
-
105
- Args:
106
- conson_config: Path to conson.yml configuration file.
107
- homekit_config: Path to homekit.yml configuration file.
108
- """
109
- from xp.services.homekit.homekit_config_validator import ConfigValidationService
110
-
111
- try:
112
- validator = ConfigValidationService(conson_config, homekit_config)
113
- summary = validator.print_config_summary()
114
-
115
- click.echo(click.style("Configuration Summary:", fg="blue", bold=True))
116
- click.echo(summary)
117
-
118
- except Exception as e:
119
- click.echo(click.style(f"✗ Failed to load configuration: {e}", fg="red"))
120
- exit(1)
@@ -1,44 +0,0 @@
1
- """API server start command."""
2
-
3
- import sys
4
-
5
- import click
6
- from click import Context
7
-
8
- from xp.cli.commands.homekit.homekit import homekit
9
- from xp.services.homekit.homekit_service import HomeKitService
10
-
11
-
12
- @homekit.command("start")
13
- @click.pass_context
14
- def homekit_start(ctx: Context) -> None:
15
- r"""
16
- Start the HomeKit server.
17
-
18
- This command starts the XP Protocol HomeKit server using HAP-python.
19
- The server provides HomeKit endpoints for Conbus operations.
20
-
21
- Args:
22
- ctx: Click context object.
23
-
24
- Examples:
25
- \b
26
- # Start server on default host and port
27
- xp homekit start
28
- """
29
- click.echo("Starting XP Protocol HomeKit server...")
30
-
31
- try:
32
- service: HomeKitService = (
33
- ctx.obj.get("container").get_container().resolve(HomeKitService)
34
- )
35
- service.start() # Blocking call - reactor.run() never returns
36
-
37
- except KeyboardInterrupt:
38
- click.echo("\nShutting down server...")
39
- except Exception as e:
40
- click.echo(
41
- click.style(f"Error starting server: {e}", fg="red"),
42
- err=True,
43
- )
44
- sys.exit(1)
@@ -1 +0,0 @@
1
- """HomeKit integration services."""