conson-xp 1.1.0__py3-none-any.whl → 1.2.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.
- {conson_xp-1.1.0.dist-info → conson_xp-1.2.0.dist-info}/METADATA +1 -1
- conson_xp-1.2.0.dist-info/RECORD +181 -0
- xp/__init__.py +4 -3
- xp/api/main.py +18 -3
- xp/api/models/api.py +13 -2
- xp/api/models/discover.py +12 -2
- xp/api/routers/conbus_blink.py +18 -6
- xp/api/routers/conbus_custom.py +11 -3
- xp/api/routers/conbus_datapoint.py +10 -3
- xp/api/routers/conbus_output.py +29 -9
- xp/api/routers/errors.py +6 -5
- xp/cli/__init__.py +1 -1
- xp/cli/commands/__init__.py +1 -0
- xp/cli/commands/api.py +1 -5
- xp/cli/commands/api_start_commands.py +14 -8
- xp/cli/commands/conbus/conbus.py +9 -37
- xp/cli/commands/conbus/conbus_actiontable_commands.py +21 -1
- xp/cli/commands/conbus/conbus_autoreport_commands.py +21 -11
- xp/cli/commands/conbus/conbus_blink_commands.py +53 -21
- xp/cli/commands/conbus/conbus_config_commands.py +7 -4
- xp/cli/commands/conbus/conbus_custom_commands.py +13 -4
- xp/cli/commands/conbus/conbus_datapoint_commands.py +28 -8
- xp/cli/commands/conbus/conbus_discover_commands.py +15 -4
- xp/cli/commands/conbus/conbus_lightlevel_commands.py +50 -11
- xp/cli/commands/conbus/conbus_linknumber_commands.py +21 -11
- xp/cli/commands/conbus/conbus_msactiontable_commands.py +25 -1
- xp/cli/commands/conbus/conbus_output_commands.py +46 -12
- xp/cli/commands/conbus/conbus_raw_commands.py +17 -6
- xp/cli/commands/conbus/conbus_receive_commands.py +15 -7
- xp/cli/commands/conbus/conbus_scan_commands.py +17 -4
- xp/cli/commands/file_commands.py +26 -15
- xp/cli/commands/homekit/homekit.py +14 -8
- xp/cli/commands/homekit/homekit_start_commands.py +5 -5
- xp/cli/commands/module_commands.py +26 -19
- xp/cli/commands/reverse_proxy_commands.py +24 -18
- xp/cli/commands/server/server_commands.py +18 -18
- xp/cli/commands/telegram/telegram.py +4 -12
- xp/cli/commands/telegram/telegram_blink_commands.py +10 -8
- xp/cli/commands/telegram/telegram_checksum_commands.py +19 -8
- xp/cli/commands/telegram/telegram_discover_commands.py +2 -4
- xp/cli/commands/telegram/telegram_linknumber_commands.py +11 -8
- xp/cli/commands/telegram/telegram_parse_commands.py +10 -9
- xp/cli/commands/telegram/telegram_version_commands.py +8 -4
- xp/cli/main.py +5 -1
- xp/cli/utils/click_tree.py +23 -3
- xp/cli/utils/datapoint_type_choice.py +20 -0
- xp/cli/utils/decorators.py +165 -14
- xp/cli/utils/error_handlers.py +49 -18
- xp/cli/utils/formatters.py +95 -10
- xp/cli/utils/serial_number_type.py +18 -0
- xp/cli/utils/system_function_choice.py +20 -0
- xp/cli/utils/xp_module_type.py +20 -0
- xp/connection/__init__.py +1 -1
- xp/connection/exceptions.py +5 -5
- xp/models/__init__.py +1 -1
- xp/models/actiontable/__init__.py +1 -0
- xp/models/actiontable/actiontable.py +17 -1
- xp/models/actiontable/msactiontable_xp20.py +10 -0
- xp/models/actiontable/msactiontable_xp24.py +20 -3
- xp/models/actiontable/msactiontable_xp33.py +27 -4
- xp/models/conbus/__init__.py +1 -0
- xp/models/conbus/conbus.py +34 -4
- xp/models/conbus/conbus_autoreport.py +20 -2
- xp/models/conbus/conbus_blink.py +22 -2
- xp/models/conbus/conbus_client_config.py +22 -1
- xp/models/conbus/conbus_connection_status.py +16 -2
- xp/models/conbus/conbus_custom.py +21 -2
- xp/models/conbus/conbus_datapoint.py +22 -2
- xp/models/conbus/conbus_discover.py +18 -2
- xp/models/conbus/conbus_lightlevel.py +20 -2
- xp/models/conbus/conbus_linknumber.py +20 -2
- xp/models/conbus/conbus_output.py +22 -2
- xp/models/conbus/conbus_raw.py +17 -2
- xp/models/conbus/conbus_receive.py +16 -2
- xp/models/homekit/__init__.py +1 -0
- xp/models/homekit/homekit_accessory.py +15 -1
- xp/models/homekit/homekit_config.py +52 -0
- xp/models/homekit/homekit_conson_config.py +32 -0
- xp/models/log_entry.py +49 -9
- xp/models/protocol/__init__.py +1 -0
- xp/models/protocol/conbus_protocol.py +130 -21
- xp/models/telegram/__init__.py +1 -0
- xp/models/telegram/action_type.py +16 -2
- xp/models/telegram/datapoint_type.py +36 -2
- xp/models/telegram/event_telegram.py +46 -10
- xp/models/telegram/event_type.py +8 -1
- xp/models/telegram/input_action_type.py +34 -2
- xp/models/telegram/input_type.py +9 -1
- xp/models/telegram/module_type.py +69 -19
- xp/models/telegram/module_type_code.py +43 -1
- xp/models/telegram/output_telegram.py +30 -6
- xp/models/telegram/reply_telegram.py +56 -11
- xp/models/telegram/system_function.py +35 -3
- xp/models/telegram/system_telegram.py +18 -4
- xp/models/telegram/telegram.py +12 -3
- xp/models/telegram/telegram_type.py +8 -1
- xp/models/telegram/timeparam_type.py +27 -0
- xp/models/write_config_type.py +17 -2
- xp/services/__init__.py +1 -1
- xp/services/conbus/__init__.py +1 -0
- xp/services/conbus/actiontable/__init__.py +1 -0
- xp/services/conbus/actiontable/actiontable_service.py +33 -2
- xp/services/conbus/actiontable/msactiontable_service.py +40 -3
- xp/services/conbus/actiontable/msactiontable_xp24_serializer.py +36 -4
- xp/services/conbus/actiontable/msactiontable_xp33_serializer.py +45 -5
- xp/services/conbus/conbus_autoreport_get_service.py +17 -8
- xp/services/conbus/conbus_autoreport_set_service.py +29 -16
- xp/services/conbus/conbus_blink_all_service.py +40 -21
- xp/services/conbus/conbus_blink_service.py +37 -13
- xp/services/conbus/conbus_custom_service.py +29 -13
- xp/services/conbus/conbus_datapoint_queryall_service.py +40 -16
- xp/services/conbus/conbus_datapoint_service.py +33 -12
- xp/services/conbus/conbus_discover_service.py +43 -7
- xp/services/conbus/conbus_lightlevel_get_service.py +22 -14
- xp/services/conbus/conbus_lightlevel_set_service.py +40 -20
- xp/services/conbus/conbus_linknumber_get_service.py +18 -10
- xp/services/conbus/conbus_linknumber_set_service.py +34 -8
- xp/services/conbus/conbus_output_service.py +33 -13
- xp/services/conbus/conbus_raw_service.py +36 -16
- xp/services/conbus/conbus_receive_service.py +38 -6
- xp/services/conbus/conbus_scan_service.py +44 -18
- xp/services/homekit/__init__.py +1 -0
- xp/services/homekit/homekit_cache_service.py +31 -6
- xp/services/homekit/homekit_conbus_service.py +33 -2
- xp/services/homekit/homekit_config_validator.py +97 -15
- xp/services/homekit/homekit_conson_validator.py +51 -7
- xp/services/homekit/homekit_dimminglight.py +47 -1
- xp/services/homekit/homekit_dimminglight_service.py +35 -1
- xp/services/homekit/homekit_hap_service.py +71 -18
- xp/services/homekit/homekit_lightbulb.py +35 -1
- xp/services/homekit/homekit_lightbulb_service.py +30 -2
- xp/services/homekit/homekit_module_service.py +23 -1
- xp/services/homekit/homekit_outlet.py +47 -1
- xp/services/homekit/homekit_outlet_service.py +44 -2
- xp/services/homekit/homekit_service.py +113 -19
- xp/services/log_file_service.py +37 -41
- xp/services/module_type_service.py +26 -5
- xp/services/protocol/__init__.py +1 -1
- xp/services/protocol/conbus_protocol.py +110 -16
- xp/services/protocol/protocol_factory.py +40 -0
- xp/services/protocol/telegram_protocol.py +38 -7
- xp/services/reverse_proxy_service.py +79 -14
- xp/services/server/__init__.py +1 -0
- xp/services/server/base_server_service.py +102 -14
- xp/services/server/cp20_server_service.py +12 -4
- xp/services/server/server_service.py +26 -11
- xp/services/server/xp130_server_service.py +11 -3
- xp/services/server/xp20_server_service.py +11 -3
- xp/services/server/xp230_server_service.py +11 -3
- xp/services/server/xp24_server_service.py +33 -6
- xp/services/server/xp33_server_service.py +41 -8
- xp/services/telegram/__init__.py +1 -0
- xp/services/telegram/telegram_blink_service.py +19 -31
- xp/services/telegram/telegram_checksum_service.py +10 -10
- xp/services/telegram/telegram_discover_service.py +58 -29
- xp/services/telegram/telegram_link_number_service.py +27 -40
- xp/services/telegram/telegram_output_service.py +46 -49
- xp/services/telegram/telegram_service.py +41 -41
- xp/services/telegram/telegram_version_service.py +4 -2
- xp/utils/__init__.py +1 -1
- xp/utils/dependencies.py +0 -1
- xp/utils/serialization.py +6 -0
- xp/utils/time_utils.py +6 -11
- conson_xp-1.1.0.dist-info/RECORD +0 -181
- {conson_xp-1.1.0.dist-info → conson_xp-1.2.0.dist-info}/WHEEL +0 -0
- {conson_xp-1.1.0.dist-info → conson_xp-1.2.0.dist-info}/entry_points.txt +0 -0
- {conson_xp-1.1.0.dist-info → conson_xp-1.2.0.dist-info}/licenses/LICENSE +0 -0
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
"""HomeKit Dimming Light Accessory.
|
|
2
|
+
|
|
3
|
+
This module provides a dimming light accessory for HomeKit integration.
|
|
4
|
+
"""
|
|
5
|
+
|
|
1
6
|
import logging
|
|
2
7
|
|
|
3
8
|
from bubus import EventBus
|
|
@@ -16,7 +21,20 @@ from xp.models.protocol.conbus_protocol import (
|
|
|
16
21
|
|
|
17
22
|
|
|
18
23
|
class DimmingLight(Accessory):
|
|
19
|
-
"""
|
|
24
|
+
"""HomeKit dimming light accessory.
|
|
25
|
+
|
|
26
|
+
Attributes:
|
|
27
|
+
category: HomeKit category (CATEGORY_LIGHTBULB).
|
|
28
|
+
event_bus: Event bus for inter-service communication.
|
|
29
|
+
logger: Logger instance.
|
|
30
|
+
identifier: Unique identifier for the accessory.
|
|
31
|
+
accessory: Accessory configuration.
|
|
32
|
+
module: Module configuration.
|
|
33
|
+
is_on: Current on/off state.
|
|
34
|
+
brightness: Current brightness level (0-100).
|
|
35
|
+
char_on: On characteristic.
|
|
36
|
+
char_brightness: Brightness characteristic.
|
|
37
|
+
"""
|
|
20
38
|
|
|
21
39
|
category = CATEGORY_LIGHTBULB
|
|
22
40
|
event_bus: EventBus
|
|
@@ -28,6 +46,14 @@ class DimmingLight(Accessory):
|
|
|
28
46
|
accessory: HomekitAccessoryConfig,
|
|
29
47
|
event_bus: EventBus,
|
|
30
48
|
):
|
|
49
|
+
"""Initialize the dimming light accessory.
|
|
50
|
+
|
|
51
|
+
Args:
|
|
52
|
+
driver: HAP accessory driver.
|
|
53
|
+
module: Module configuration.
|
|
54
|
+
accessory: Accessory configuration.
|
|
55
|
+
event_bus: Event bus for inter-service communication.
|
|
56
|
+
"""
|
|
31
57
|
super().__init__(driver, accessory.description)
|
|
32
58
|
|
|
33
59
|
self.logger = logging.getLogger(__name__)
|
|
@@ -76,6 +102,11 @@ class DimmingLight(Accessory):
|
|
|
76
102
|
)
|
|
77
103
|
|
|
78
104
|
def set_on(self, value: bool) -> None:
|
|
105
|
+
"""Set the on/off state of the dimming light.
|
|
106
|
+
|
|
107
|
+
Args:
|
|
108
|
+
value: True to turn on, False to turn off.
|
|
109
|
+
"""
|
|
79
110
|
# Emit set event
|
|
80
111
|
self.logger.debug(f"set_on {value}")
|
|
81
112
|
|
|
@@ -93,6 +124,11 @@ class DimmingLight(Accessory):
|
|
|
93
124
|
)
|
|
94
125
|
|
|
95
126
|
def get_on(self) -> bool:
|
|
127
|
+
"""Get the on/off state of the dimming light.
|
|
128
|
+
|
|
129
|
+
Returns:
|
|
130
|
+
True if on, False if off.
|
|
131
|
+
"""
|
|
96
132
|
# Emit event and get response
|
|
97
133
|
self.logger.debug("get_on")
|
|
98
134
|
|
|
@@ -108,6 +144,11 @@ class DimmingLight(Accessory):
|
|
|
108
144
|
return self.is_on
|
|
109
145
|
|
|
110
146
|
def set_brightness(self, value: int) -> None:
|
|
147
|
+
"""Set the brightness level of the dimming light.
|
|
148
|
+
|
|
149
|
+
Args:
|
|
150
|
+
value: Brightness level (0-100).
|
|
151
|
+
"""
|
|
111
152
|
self.logger.debug(f"set_brightness {value}")
|
|
112
153
|
self.brightness = value
|
|
113
154
|
|
|
@@ -122,6 +163,11 @@ class DimmingLight(Accessory):
|
|
|
122
163
|
)
|
|
123
164
|
|
|
124
165
|
def get_brightness(self) -> int:
|
|
166
|
+
"""Get the brightness level of the dimming light.
|
|
167
|
+
|
|
168
|
+
Returns:
|
|
169
|
+
Current brightness level (0-100).
|
|
170
|
+
"""
|
|
125
171
|
self.logger.debug("get_brightness")
|
|
126
172
|
|
|
127
173
|
# Dispatch event from HAP thread (thread-safe)
|
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
"""HomeKit Dimming Light Service.
|
|
2
|
+
|
|
3
|
+
This module provides service implementation for dimming light accessories.
|
|
4
|
+
"""
|
|
5
|
+
|
|
1
6
|
import logging
|
|
2
7
|
|
|
3
8
|
from bubus import EventBus
|
|
@@ -14,12 +19,21 @@ from xp.models.telegram.datapoint_type import DataPointType
|
|
|
14
19
|
|
|
15
20
|
|
|
16
21
|
class HomeKitDimmingLightService:
|
|
17
|
-
"""Dimming light service for HomeKit
|
|
22
|
+
"""Dimming light service for HomeKit.
|
|
23
|
+
|
|
24
|
+
Attributes:
|
|
25
|
+
event_bus: Event bus for inter-service communication.
|
|
26
|
+
logger: Logger instance.
|
|
27
|
+
"""
|
|
18
28
|
|
|
19
29
|
event_bus: EventBus
|
|
20
30
|
|
|
21
31
|
def __init__(self, event_bus: EventBus) -> None:
|
|
32
|
+
"""Initialize the dimming light service.
|
|
22
33
|
|
|
34
|
+
Args:
|
|
35
|
+
event_bus: Event bus instance.
|
|
36
|
+
"""
|
|
23
37
|
self.logger = logging.getLogger(__name__)
|
|
24
38
|
self.event_bus = event_bus
|
|
25
39
|
|
|
@@ -34,6 +48,11 @@ class HomeKitDimmingLightService:
|
|
|
34
48
|
)
|
|
35
49
|
|
|
36
50
|
def handle_dimminglight_get_on(self, event: DimmingLightGetOnEvent) -> None:
|
|
51
|
+
"""Handle dimming light get on event.
|
|
52
|
+
|
|
53
|
+
Args:
|
|
54
|
+
event: Dimming light get on event.
|
|
55
|
+
"""
|
|
37
56
|
self.logger.info(
|
|
38
57
|
f"Getting dimming light state for serial {event.serial_number}, output {event.output_number}"
|
|
39
58
|
)
|
|
@@ -48,6 +67,11 @@ class HomeKitDimmingLightService:
|
|
|
48
67
|
self.logger.debug(f"Dispatched ReadDatapointEvent for {event.serial_number}")
|
|
49
68
|
|
|
50
69
|
def handle_dimminglight_set_on(self, event: DimmingLightSetOnEvent) -> None:
|
|
70
|
+
"""Handle dimming light set on event.
|
|
71
|
+
|
|
72
|
+
Args:
|
|
73
|
+
event: Dimming light set on event.
|
|
74
|
+
"""
|
|
51
75
|
brightness = event.brightness if event.value else 0
|
|
52
76
|
self.logger.debug(
|
|
53
77
|
f"Setting on light for "
|
|
@@ -74,6 +98,11 @@ class HomeKitDimmingLightService:
|
|
|
74
98
|
def handle_dimminglight_set_brightness(
|
|
75
99
|
self, event: DimmingLightSetBrightnessEvent
|
|
76
100
|
) -> None:
|
|
101
|
+
"""Handle dimming light set brightness event.
|
|
102
|
+
|
|
103
|
+
Args:
|
|
104
|
+
event: Dimming light set brightness event.
|
|
105
|
+
"""
|
|
77
106
|
self.logger.info(
|
|
78
107
|
f"Setting dimming light brightness"
|
|
79
108
|
f"serial {event.serial_number}, "
|
|
@@ -97,6 +126,11 @@ class HomeKitDimmingLightService:
|
|
|
97
126
|
def handle_dimminglight_get_brightness(
|
|
98
127
|
self, event: DimmingLightGetBrightnessEvent
|
|
99
128
|
) -> None:
|
|
129
|
+
"""Handle dimming light get brightness event.
|
|
130
|
+
|
|
131
|
+
Args:
|
|
132
|
+
event: Dimming light get brightness event.
|
|
133
|
+
"""
|
|
100
134
|
self.logger.info(
|
|
101
135
|
f"Getting dimming light brightness "
|
|
102
136
|
f"for serial {event.serial_number}, "
|
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
"""HomeKit HAP Service for Apple HomeKit integration.
|
|
2
|
+
|
|
3
|
+
This module provides the main HAP (HomeKit Accessory Protocol) service.
|
|
4
|
+
"""
|
|
5
|
+
|
|
1
6
|
import logging
|
|
2
7
|
import signal
|
|
3
8
|
import threading
|
|
@@ -30,11 +35,20 @@ from xp.services.homekit.homekit_outlet import Outlet
|
|
|
30
35
|
|
|
31
36
|
|
|
32
37
|
class HomekitHapService:
|
|
33
|
-
"""
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
+
"""HomeKit HAP service.
|
|
39
|
+
|
|
40
|
+
Manages HAP accessory protocol, handles bridge and accessory setup,
|
|
41
|
+
and processes HomeKit events for device state synchronization.
|
|
42
|
+
|
|
43
|
+
Attributes:
|
|
44
|
+
event_bus: Event bus for inter-service communication.
|
|
45
|
+
last_activity: Timestamp of last service activity.
|
|
46
|
+
logger: Logger instance.
|
|
47
|
+
config: HomeKit configuration.
|
|
48
|
+
accessory_registry: Registry of accessories by identifier.
|
|
49
|
+
module_registry: Registry of accessories by module key.
|
|
50
|
+
modules: Module service for module lookup.
|
|
51
|
+
driver: HAP accessory driver.
|
|
38
52
|
"""
|
|
39
53
|
|
|
40
54
|
event_bus: EventBus
|
|
@@ -45,12 +59,12 @@ class HomekitHapService:
|
|
|
45
59
|
module_service: HomekitModuleService,
|
|
46
60
|
event_bus: EventBus,
|
|
47
61
|
):
|
|
48
|
-
"""Initialize the
|
|
62
|
+
"""Initialize the HomeKit HAP service.
|
|
49
63
|
|
|
50
64
|
Args:
|
|
51
|
-
homekit_config:
|
|
52
|
-
module_service:
|
|
53
|
-
event_bus:
|
|
65
|
+
homekit_config: HomeKit configuration.
|
|
66
|
+
module_service: Module service for dependency injection.
|
|
67
|
+
event_bus: Event bus for dependency injection.
|
|
54
68
|
"""
|
|
55
69
|
self.last_activity: Optional[datetime] = None
|
|
56
70
|
|
|
@@ -82,13 +96,13 @@ class HomekitHapService:
|
|
|
82
96
|
self.driver: AccessoryDriver = driver
|
|
83
97
|
|
|
84
98
|
async def async_start(self) -> None:
|
|
85
|
-
"""
|
|
86
|
-
self.logger.info("Loading accessories
|
|
99
|
+
"""Start the HAP service asynchronously."""
|
|
100
|
+
self.logger.info("Loading accessories.")
|
|
87
101
|
self.build_bridge()
|
|
88
102
|
self.logger.info("Accessories loaded successfully")
|
|
89
103
|
|
|
90
104
|
# Start HAP-python in a separate thread to avoid event loop conflicts
|
|
91
|
-
self.logger.info("Starting HAP-python driver in separate thread
|
|
105
|
+
self.logger.info("Starting HAP-python driver in separate thread.")
|
|
92
106
|
hap_thread = threading.Thread(
|
|
93
107
|
target=self._run_driver_in_thread, daemon=True, name="HAP-Python"
|
|
94
108
|
)
|
|
@@ -96,19 +110,26 @@ class HomekitHapService:
|
|
|
96
110
|
self.logger.info("HAP-python driver thread started")
|
|
97
111
|
|
|
98
112
|
def _run_driver_in_thread(self) -> None:
|
|
99
|
-
"""Run the HAP-python driver in a separate thread with its own event loop"""
|
|
113
|
+
"""Run the HAP-python driver in a separate thread with its own event loop."""
|
|
100
114
|
try:
|
|
101
|
-
self.logger.info("HAP-python thread starting, creating new event loop
|
|
115
|
+
self.logger.info("HAP-python thread starting, creating new event loop.")
|
|
102
116
|
# Create a new event loop for this thread
|
|
103
117
|
|
|
104
|
-
self.logger.info("Starting HAP-python driver
|
|
118
|
+
self.logger.info("Starting HAP-python driver.")
|
|
105
119
|
self.driver.start()
|
|
106
120
|
self.logger.info("HAP-python driver started successfully")
|
|
107
121
|
except Exception as e:
|
|
108
122
|
self.logger.error(f"HAP-python driver error: {e}", exc_info=True)
|
|
109
123
|
|
|
110
124
|
def handle_output_state_received(self, event: OutputStateReceivedEvent) -> str:
|
|
125
|
+
"""Handle output state received event.
|
|
126
|
+
|
|
127
|
+
Args:
|
|
128
|
+
event: Output state received event.
|
|
111
129
|
|
|
130
|
+
Returns:
|
|
131
|
+
Data value from the event.
|
|
132
|
+
"""
|
|
112
133
|
self.logger.debug(f"Received OutputStateReceivedEvent {event}")
|
|
113
134
|
output_number = 0
|
|
114
135
|
for output in event.data_value[::-1]:
|
|
@@ -131,7 +152,14 @@ class HomekitHapService:
|
|
|
131
152
|
return event.data_value
|
|
132
153
|
|
|
133
154
|
def handle_light_level_received(self, event: LightLevelReceivedEvent) -> str:
|
|
155
|
+
"""Handle light level received event.
|
|
156
|
+
|
|
157
|
+
Args:
|
|
158
|
+
event: Light level received event.
|
|
134
159
|
|
|
160
|
+
Returns:
|
|
161
|
+
Data value from the event.
|
|
162
|
+
"""
|
|
135
163
|
# Parse response format like "00:050,01:025,02:100"
|
|
136
164
|
self.logger.debug("Received LightLevelReceivedEvent", extra={"event": event})
|
|
137
165
|
output_number = 0
|
|
@@ -165,6 +193,7 @@ class HomekitHapService:
|
|
|
165
193
|
return event.data_value
|
|
166
194
|
|
|
167
195
|
def build_bridge(self) -> None:
|
|
196
|
+
"""Build the HomeKit bridge with all configured accessories."""
|
|
168
197
|
bridge_config = self.config.bridge
|
|
169
198
|
bridge = Bridge(self.driver, bridge_config.name)
|
|
170
199
|
bridge.set_info_service(
|
|
@@ -177,7 +206,12 @@ class HomekitHapService:
|
|
|
177
206
|
self.driver.add_accessory(accessory=bridge)
|
|
178
207
|
|
|
179
208
|
def add_room(self, bridge: Bridge, room: RoomConfig) -> None:
|
|
180
|
-
"""
|
|
209
|
+
"""Add a room with its accessories to the bridge.
|
|
210
|
+
|
|
211
|
+
Args:
|
|
212
|
+
bridge: HAP bridge instance.
|
|
213
|
+
room: Room configuration.
|
|
214
|
+
"""
|
|
181
215
|
temperature = TemperatureSensor(self.driver, room.name)
|
|
182
216
|
bridge.add_accessory(temperature)
|
|
183
217
|
|
|
@@ -205,7 +239,14 @@ class HomekitHapService:
|
|
|
205
239
|
def get_accessory(
|
|
206
240
|
self, homekit_accessory: HomekitAccessoryConfig
|
|
207
241
|
) -> Union[LightBulb, Outlet, DimmingLight, None]:
|
|
208
|
-
"""
|
|
242
|
+
"""Get an accessory instance from configuration.
|
|
243
|
+
|
|
244
|
+
Args:
|
|
245
|
+
homekit_accessory: HomeKit accessory configuration.
|
|
246
|
+
|
|
247
|
+
Returns:
|
|
248
|
+
Accessory instance or None if not found or invalid service type.
|
|
249
|
+
"""
|
|
209
250
|
module_config = self.modules.get_module_by_serial(
|
|
210
251
|
homekit_accessory.serial_number
|
|
211
252
|
)
|
|
@@ -241,12 +282,24 @@ class HomekitHapService:
|
|
|
241
282
|
return None
|
|
242
283
|
|
|
243
284
|
def get_accessory_by_name(self, name: str) -> Optional[HomekitAccessoryConfig]:
|
|
285
|
+
"""Get an accessory configuration by name.
|
|
286
|
+
|
|
287
|
+
Args:
|
|
288
|
+
name: Name of the accessory to find.
|
|
289
|
+
|
|
290
|
+
Returns:
|
|
291
|
+
Accessory configuration if found, None otherwise.
|
|
292
|
+
"""
|
|
244
293
|
return next(
|
|
245
294
|
(module for module in self.config.accessories if module.name == name), None
|
|
246
295
|
)
|
|
247
296
|
|
|
248
297
|
def handle_module_state_changed(self, event: ModuleStateChangedEvent) -> None:
|
|
249
|
-
"""Handle module state change by refreshing affected accessories
|
|
298
|
+
"""Handle module state change by refreshing affected accessories.
|
|
299
|
+
|
|
300
|
+
Args:
|
|
301
|
+
event: Module state changed event.
|
|
302
|
+
"""
|
|
250
303
|
self.logger.debug(
|
|
251
304
|
f"Module state changed: module_type={event.module_type_code}, "
|
|
252
305
|
f"link={event.link_number}, input={event.input_number}"
|
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
"""HomeKit Light Bulb Accessory.
|
|
2
|
+
|
|
3
|
+
This module provides a light bulb accessory for HomeKit integration.
|
|
4
|
+
"""
|
|
5
|
+
|
|
1
6
|
import logging
|
|
2
7
|
|
|
3
8
|
from bubus import EventBus
|
|
@@ -14,7 +19,18 @@ from xp.models.protocol.conbus_protocol import (
|
|
|
14
19
|
|
|
15
20
|
|
|
16
21
|
class LightBulb(Accessory):
|
|
17
|
-
"""
|
|
22
|
+
"""HomeKit light bulb accessory.
|
|
23
|
+
|
|
24
|
+
Attributes:
|
|
25
|
+
category: HomeKit category (CATEGORY_LIGHTBULB).
|
|
26
|
+
event_bus: Event bus for inter-service communication.
|
|
27
|
+
logger: Logger instance.
|
|
28
|
+
identifier: Unique identifier for the accessory.
|
|
29
|
+
accessory: Accessory configuration.
|
|
30
|
+
module: Module configuration.
|
|
31
|
+
is_on: Current on/off state.
|
|
32
|
+
char_on: On characteristic.
|
|
33
|
+
"""
|
|
18
34
|
|
|
19
35
|
category = CATEGORY_LIGHTBULB
|
|
20
36
|
event_bus: EventBus
|
|
@@ -26,6 +42,14 @@ class LightBulb(Accessory):
|
|
|
26
42
|
accessory: HomekitAccessoryConfig,
|
|
27
43
|
event_bus: EventBus,
|
|
28
44
|
):
|
|
45
|
+
"""Initialize the light bulb accessory.
|
|
46
|
+
|
|
47
|
+
Args:
|
|
48
|
+
driver: HAP accessory driver.
|
|
49
|
+
module: Module configuration.
|
|
50
|
+
accessory: Accessory configuration.
|
|
51
|
+
event_bus: Event bus for inter-service communication.
|
|
52
|
+
"""
|
|
29
53
|
super().__init__(driver, accessory.description)
|
|
30
54
|
|
|
31
55
|
self.logger = logging.getLogger(__name__)
|
|
@@ -56,6 +80,11 @@ class LightBulb(Accessory):
|
|
|
56
80
|
)
|
|
57
81
|
|
|
58
82
|
def set_on(self, value: bool) -> None:
|
|
83
|
+
"""Set the on/off state of the light bulb.
|
|
84
|
+
|
|
85
|
+
Args:
|
|
86
|
+
value: True to turn on, False to turn off.
|
|
87
|
+
"""
|
|
59
88
|
# Emit set event
|
|
60
89
|
self.logger.debug(f"set_on {value}")
|
|
61
90
|
if self.is_on != value:
|
|
@@ -71,6 +100,11 @@ class LightBulb(Accessory):
|
|
|
71
100
|
)
|
|
72
101
|
|
|
73
102
|
def get_on(self) -> bool:
|
|
103
|
+
"""Get the on/off state of the light bulb.
|
|
104
|
+
|
|
105
|
+
Returns:
|
|
106
|
+
True if on, False if off.
|
|
107
|
+
"""
|
|
74
108
|
# Emit event and get response
|
|
75
109
|
self.logger.debug("get_on")
|
|
76
110
|
self.event_bus.dispatch(
|
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
"""HomeKit Light Bulb Service.
|
|
2
|
+
|
|
3
|
+
This module provides service implementation for light bulb accessories.
|
|
4
|
+
"""
|
|
5
|
+
|
|
1
6
|
import logging
|
|
2
7
|
|
|
3
8
|
from bubus import EventBus
|
|
@@ -12,11 +17,21 @@ from xp.models.telegram.datapoint_type import DataPointType
|
|
|
12
17
|
|
|
13
18
|
|
|
14
19
|
class HomeKitLightbulbService:
|
|
15
|
-
"""Lightbulb service for HomeKit
|
|
20
|
+
"""Lightbulb service for HomeKit.
|
|
21
|
+
|
|
22
|
+
Attributes:
|
|
23
|
+
event_bus: Event bus for inter-service communication.
|
|
24
|
+
logger: Logger instance.
|
|
25
|
+
"""
|
|
16
26
|
|
|
17
27
|
event_bus: EventBus
|
|
18
28
|
|
|
19
29
|
def __init__(self, event_bus: EventBus):
|
|
30
|
+
"""Initialize the lightbulb service.
|
|
31
|
+
|
|
32
|
+
Args:
|
|
33
|
+
event_bus: Event bus instance.
|
|
34
|
+
"""
|
|
20
35
|
self.event_bus = event_bus
|
|
21
36
|
self.logger = logging.getLogger(__name__)
|
|
22
37
|
|
|
@@ -25,6 +40,11 @@ class HomeKitLightbulbService:
|
|
|
25
40
|
self.event_bus.on(LightBulbSetOnEvent, self.handle_lightbulb_set_on)
|
|
26
41
|
|
|
27
42
|
def handle_lightbulb_get_on(self, event: LightBulbGetOnEvent) -> None:
|
|
43
|
+
"""Handle lightbulb get on event.
|
|
44
|
+
|
|
45
|
+
Args:
|
|
46
|
+
event: Lightbulb get on event.
|
|
47
|
+
"""
|
|
28
48
|
self.logger.info(
|
|
29
49
|
f"Getting lightbulb state for serial {event.serial_number}, output {event.output_number}"
|
|
30
50
|
)
|
|
@@ -40,8 +60,16 @@ class HomeKitLightbulbService:
|
|
|
40
60
|
self.logger.debug(f"Dispatched ReadDatapointEvent for {event.serial_number}")
|
|
41
61
|
|
|
42
62
|
def handle_lightbulb_set_on(self, event: LightBulbSetOnEvent) -> None:
|
|
63
|
+
"""Handle lightbulb set on event.
|
|
64
|
+
|
|
65
|
+
Args:
|
|
66
|
+
event: Lightbulb set on event.
|
|
67
|
+
"""
|
|
43
68
|
self.logger.info(
|
|
44
|
-
f"Setting lightbulb
|
|
69
|
+
f"Setting lightbulb "
|
|
70
|
+
f"for serial {event.serial_number}, "
|
|
71
|
+
f"output {event.output_number} "
|
|
72
|
+
f"to {'ON' if event.value else 'OFF'}"
|
|
45
73
|
)
|
|
46
74
|
self.logger.debug(f"lightbulb_set_on {event}")
|
|
47
75
|
|
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
"""HomeKit Module Service.
|
|
2
|
+
|
|
3
|
+
This module provides service implementation for HomeKit module management.
|
|
4
|
+
"""
|
|
5
|
+
|
|
1
6
|
import logging
|
|
2
7
|
from typing import Optional
|
|
3
8
|
|
|
@@ -8,18 +13,35 @@ from xp.models.homekit.homekit_conson_config import (
|
|
|
8
13
|
|
|
9
14
|
|
|
10
15
|
class HomekitModuleService:
|
|
16
|
+
"""Service for managing HomeKit module configurations.
|
|
17
|
+
|
|
18
|
+
Attributes:
|
|
19
|
+
logger: Logger instance.
|
|
20
|
+
conson_modules_config: Conson module list configuration.
|
|
21
|
+
"""
|
|
11
22
|
|
|
12
23
|
def __init__(
|
|
13
24
|
self,
|
|
14
25
|
conson_modules_config: ConsonModuleListConfig,
|
|
15
26
|
):
|
|
27
|
+
"""Initialize the HomeKit module service.
|
|
16
28
|
|
|
29
|
+
Args:
|
|
30
|
+
conson_modules_config: Conson module list configuration.
|
|
31
|
+
"""
|
|
17
32
|
# Set up logging
|
|
18
33
|
self.logger = logging.getLogger(__name__)
|
|
19
34
|
self.conson_modules_config = conson_modules_config
|
|
20
35
|
|
|
21
36
|
def get_module_by_serial(self, serial_number: str) -> Optional[ConsonModuleConfig]:
|
|
22
|
-
"""Get a module by its serial number
|
|
37
|
+
"""Get a module by its serial number.
|
|
38
|
+
|
|
39
|
+
Args:
|
|
40
|
+
serial_number: Serial number of the module to find.
|
|
41
|
+
|
|
42
|
+
Returns:
|
|
43
|
+
Module configuration if found, None otherwise.
|
|
44
|
+
"""
|
|
23
45
|
module = next(
|
|
24
46
|
(
|
|
25
47
|
module
|
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
"""HomeKit Outlet Accessory.
|
|
2
|
+
|
|
3
|
+
This module provides an outlet accessory for HomeKit integration.
|
|
4
|
+
"""
|
|
5
|
+
|
|
1
6
|
import logging
|
|
2
7
|
|
|
3
8
|
from bubus import EventBus
|
|
@@ -16,7 +21,20 @@ from xp.models.protocol.conbus_protocol import (
|
|
|
16
21
|
|
|
17
22
|
|
|
18
23
|
class Outlet(Accessory):
|
|
19
|
-
"""
|
|
24
|
+
"""HomeKit outlet accessory.
|
|
25
|
+
|
|
26
|
+
Attributes:
|
|
27
|
+
category: HomeKit category (CATEGORY_OUTLET).
|
|
28
|
+
event_bus: Event bus for inter-service communication.
|
|
29
|
+
logger: Logger instance.
|
|
30
|
+
identifier: Unique identifier for the accessory.
|
|
31
|
+
accessory: Accessory configuration.
|
|
32
|
+
module: Module configuration.
|
|
33
|
+
is_on: Current on/off state.
|
|
34
|
+
is_in_use: Current in-use state.
|
|
35
|
+
char_on: On characteristic.
|
|
36
|
+
char_outlet_in_use: Outlet in-use characteristic.
|
|
37
|
+
"""
|
|
20
38
|
|
|
21
39
|
category = CATEGORY_OUTLET
|
|
22
40
|
event_bus: EventBus
|
|
@@ -28,6 +46,14 @@ class Outlet(Accessory):
|
|
|
28
46
|
accessory: HomekitAccessoryConfig,
|
|
29
47
|
event_bus: EventBus,
|
|
30
48
|
):
|
|
49
|
+
"""Initialize the outlet accessory.
|
|
50
|
+
|
|
51
|
+
Args:
|
|
52
|
+
driver: HAP accessory driver.
|
|
53
|
+
module: Module configuration.
|
|
54
|
+
accessory: Accessory configuration.
|
|
55
|
+
event_bus: Event bus for inter-service communication.
|
|
56
|
+
"""
|
|
31
57
|
super().__init__(driver=driver, display_name=accessory.description)
|
|
32
58
|
|
|
33
59
|
self.logger = logging.getLogger(__name__)
|
|
@@ -62,6 +88,11 @@ class Outlet(Accessory):
|
|
|
62
88
|
)
|
|
63
89
|
|
|
64
90
|
def set_outlet_in_use(self, value: bool) -> None:
|
|
91
|
+
"""Set the in-use state of the outlet.
|
|
92
|
+
|
|
93
|
+
Args:
|
|
94
|
+
value: True if in use, False otherwise.
|
|
95
|
+
"""
|
|
65
96
|
self.logger.debug(f"set_outlet_in_use {value}")
|
|
66
97
|
|
|
67
98
|
self.is_in_use = value
|
|
@@ -77,6 +108,11 @@ class Outlet(Accessory):
|
|
|
77
108
|
self.logger.debug(f"set_outlet_in_use {value} end")
|
|
78
109
|
|
|
79
110
|
def get_outlet_in_use(self) -> bool:
|
|
111
|
+
"""Get the in-use state of the outlet.
|
|
112
|
+
|
|
113
|
+
Returns:
|
|
114
|
+
True if in use, False otherwise.
|
|
115
|
+
"""
|
|
80
116
|
# Emit event and get response
|
|
81
117
|
self.logger.debug("get_outlet_in_use")
|
|
82
118
|
|
|
@@ -92,6 +128,11 @@ class Outlet(Accessory):
|
|
|
92
128
|
return self.is_in_use
|
|
93
129
|
|
|
94
130
|
def set_on(self, value: bool) -> None:
|
|
131
|
+
"""Set the on/off state of the outlet.
|
|
132
|
+
|
|
133
|
+
Args:
|
|
134
|
+
value: True to turn on, False to turn off.
|
|
135
|
+
"""
|
|
95
136
|
# Emit set event
|
|
96
137
|
self.logger.debug(f"set_on {value}")
|
|
97
138
|
|
|
@@ -108,6 +149,11 @@ class Outlet(Accessory):
|
|
|
108
149
|
)
|
|
109
150
|
|
|
110
151
|
def get_on(self) -> bool:
|
|
152
|
+
"""Get the on/off state of the outlet.
|
|
153
|
+
|
|
154
|
+
Returns:
|
|
155
|
+
True if on, False if off.
|
|
156
|
+
"""
|
|
111
157
|
# Emit event and get response
|
|
112
158
|
self.logger.debug("get_on")
|
|
113
159
|
|
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
"""HomeKit Outlet Service.
|
|
2
|
+
|
|
3
|
+
This module provides service implementation for outlet accessories.
|
|
4
|
+
"""
|
|
5
|
+
|
|
1
6
|
import logging
|
|
2
7
|
|
|
3
8
|
from bubus import EventBus
|
|
@@ -13,11 +18,21 @@ from xp.models.telegram.datapoint_type import DataPointType
|
|
|
13
18
|
|
|
14
19
|
|
|
15
20
|
class HomeKitOutletService:
|
|
16
|
-
"""Outlet service for HomeKit
|
|
21
|
+
"""Outlet service for HomeKit.
|
|
22
|
+
|
|
23
|
+
Attributes:
|
|
24
|
+
event_bus: Event bus for inter-service communication.
|
|
25
|
+
logger: Logger instance.
|
|
26
|
+
"""
|
|
17
27
|
|
|
18
28
|
event_bus: EventBus
|
|
19
29
|
|
|
20
30
|
def __init__(self, event_bus: EventBus):
|
|
31
|
+
"""Initialize the outlet service.
|
|
32
|
+
|
|
33
|
+
Args:
|
|
34
|
+
event_bus: Event bus instance.
|
|
35
|
+
"""
|
|
21
36
|
self.event_bus = event_bus
|
|
22
37
|
self.logger = logging.getLogger(__name__)
|
|
23
38
|
|
|
@@ -27,6 +42,14 @@ class HomeKitOutletService:
|
|
|
27
42
|
self.event_bus.on(OutletGetInUseEvent, self.handle_outlet_get_in_use)
|
|
28
43
|
|
|
29
44
|
def handle_outlet_get_on(self, event: OutletGetOnEvent) -> bool:
|
|
45
|
+
"""Handle outlet get on event.
|
|
46
|
+
|
|
47
|
+
Args:
|
|
48
|
+
event: Outlet get on event.
|
|
49
|
+
|
|
50
|
+
Returns:
|
|
51
|
+
True if request was dispatched successfully.
|
|
52
|
+
"""
|
|
30
53
|
self.logger.debug(
|
|
31
54
|
f"Getting outlet state for serial {event.serial_number}, output {event.output_number}"
|
|
32
55
|
)
|
|
@@ -42,8 +65,19 @@ class HomeKitOutletService:
|
|
|
42
65
|
return True
|
|
43
66
|
|
|
44
67
|
def handle_outlet_set_on(self, event: OutletSetOnEvent) -> bool:
|
|
68
|
+
"""Handle outlet set on event.
|
|
69
|
+
|
|
70
|
+
Args:
|
|
71
|
+
event: Outlet set on event.
|
|
72
|
+
|
|
73
|
+
Returns:
|
|
74
|
+
True if command was sent successfully.
|
|
75
|
+
"""
|
|
45
76
|
self.logger.info(
|
|
46
|
-
f"Setting outlet
|
|
77
|
+
f"Setting outlet "
|
|
78
|
+
f"for serial {event.serial_number}, "
|
|
79
|
+
f"output {event.output_number} "
|
|
80
|
+
f"to {'ON' if event.value else 'OFF'}"
|
|
47
81
|
)
|
|
48
82
|
self.logger.debug(f"outlet_set_on {event}")
|
|
49
83
|
|
|
@@ -61,6 +95,14 @@ class HomeKitOutletService:
|
|
|
61
95
|
return True
|
|
62
96
|
|
|
63
97
|
def handle_outlet_get_in_use(self, event: OutletGetInUseEvent) -> bool:
|
|
98
|
+
"""Handle outlet get in-use event.
|
|
99
|
+
|
|
100
|
+
Args:
|
|
101
|
+
event: Outlet get in-use event.
|
|
102
|
+
|
|
103
|
+
Returns:
|
|
104
|
+
True if request was dispatched successfully.
|
|
105
|
+
"""
|
|
64
106
|
self.logger.info(
|
|
65
107
|
f"Getting outlet in-use status for serial {event.serial_number}"
|
|
66
108
|
)
|