pypurelinkmatrix 0.1.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.
- pypurelinkmatrix/__init__.py +42 -0
- pypurelinkmatrix/api/__init__.py +25 -0
- pypurelinkmatrix/api/audio.py +133 -0
- pypurelinkmatrix/api/data_structures.py +114 -0
- pypurelinkmatrix/api/edid.py +242 -0
- pypurelinkmatrix/api/network.py +195 -0
- pypurelinkmatrix/api/status.py +560 -0
- pypurelinkmatrix/api/status_update_manager.py +341 -0
- pypurelinkmatrix/api/system.py +209 -0
- pypurelinkmatrix/api/video.py +293 -0
- pypurelinkmatrix/auth.py +111 -0
- pypurelinkmatrix/client.py +155 -0
- pypurelinkmatrix/exceptions.py +31 -0
- pypurelinkmatrix/models.py +185 -0
- pypurelinkmatrix/simulator/__init__.py +6 -0
- pypurelinkmatrix/simulator/cli.py +29 -0
- pypurelinkmatrix/simulator/core.py +403 -0
- pypurelinkmatrix/simulator/server.py +111 -0
- pypurelinkmatrix/simulator/tui.py +98 -0
- pypurelinkmatrix-0.1.0.dist-info/METADATA +268 -0
- pypurelinkmatrix-0.1.0.dist-info/RECORD +24 -0
- pypurelinkmatrix-0.1.0.dist-info/WHEEL +4 -0
- pypurelinkmatrix-0.1.0.dist-info/entry_points.txt +2 -0
- pypurelinkmatrix-0.1.0.dist-info/licenses/LICENSE +674 -0
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"""PyPureLink Matrix - Python library for PureLink matrix device management."""
|
|
2
|
+
|
|
3
|
+
import importlib.metadata
|
|
4
|
+
|
|
5
|
+
try:
|
|
6
|
+
__version__ = importlib.metadata.version("pypurelinkmatrix")
|
|
7
|
+
except importlib.metadata.PackageNotFoundError:
|
|
8
|
+
__version__ = "0.0.1"
|
|
9
|
+
|
|
10
|
+
from .auth import PureLinkAuth
|
|
11
|
+
from .client import PureLinkClient
|
|
12
|
+
from .exceptions import (
|
|
13
|
+
AuthenticationError,
|
|
14
|
+
DeviceError,
|
|
15
|
+
PureLinkConnectionError,
|
|
16
|
+
PureLinkError,
|
|
17
|
+
ValidationError,
|
|
18
|
+
)
|
|
19
|
+
from .models import (
|
|
20
|
+
AudioState,
|
|
21
|
+
DeviceState,
|
|
22
|
+
EDIDState,
|
|
23
|
+
NetworkState,
|
|
24
|
+
PortNames,
|
|
25
|
+
VideoMatrixState,
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
__all__ = [
|
|
29
|
+
"PureLinkAuth",
|
|
30
|
+
"PureLinkClient",
|
|
31
|
+
"DeviceState",
|
|
32
|
+
"VideoMatrixState",
|
|
33
|
+
"AudioState",
|
|
34
|
+
"EDIDState",
|
|
35
|
+
"NetworkState",
|
|
36
|
+
"PortNames",
|
|
37
|
+
"PureLinkError",
|
|
38
|
+
"PureLinkConnectionError",
|
|
39
|
+
"AuthenticationError",
|
|
40
|
+
"ValidationError",
|
|
41
|
+
"DeviceError",
|
|
42
|
+
]
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"""API modules for PureLink matrix device control."""
|
|
2
|
+
|
|
3
|
+
from .audio import AudioAPI
|
|
4
|
+
from .data_structures import IPInfo, RunInfo, StringInfo, WebInfo
|
|
5
|
+
from .edid import EDIDAPI, EDIDProfile
|
|
6
|
+
from .network import NetworkAPI
|
|
7
|
+
from .status import StatusAPI
|
|
8
|
+
from .status_update_manager import StatusUpdateManager
|
|
9
|
+
from .system import SystemAPI
|
|
10
|
+
from .video import VideoAPI
|
|
11
|
+
|
|
12
|
+
__all__ = [
|
|
13
|
+
"VideoAPI",
|
|
14
|
+
"AudioAPI",
|
|
15
|
+
"EDIDAPI",
|
|
16
|
+
"EDIDProfile",
|
|
17
|
+
"NetworkAPI",
|
|
18
|
+
"SystemAPI",
|
|
19
|
+
"StatusAPI",
|
|
20
|
+
"StatusUpdateManager",
|
|
21
|
+
"IPInfo",
|
|
22
|
+
"RunInfo",
|
|
23
|
+
"StringInfo",
|
|
24
|
+
"WebInfo",
|
|
25
|
+
]
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
"""Audio output control API."""
|
|
2
|
+
|
|
3
|
+
import logging
|
|
4
|
+
from typing import TYPE_CHECKING, Optional
|
|
5
|
+
|
|
6
|
+
from ..exceptions import DeviceError
|
|
7
|
+
|
|
8
|
+
if TYPE_CHECKING:
|
|
9
|
+
from ..auth import PureLinkAuth
|
|
10
|
+
from ..models import DeviceState
|
|
11
|
+
|
|
12
|
+
logger = logging.getLogger(__name__)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class AudioAPI:
|
|
16
|
+
"""API for audio output control operations."""
|
|
17
|
+
|
|
18
|
+
def __init__(self, auth: "PureLinkAuth", state: Optional["DeviceState"] = None):
|
|
19
|
+
"""Initialize audio API.
|
|
20
|
+
|
|
21
|
+
Args:
|
|
22
|
+
auth: PureLinkAuth instance for HTTP communication
|
|
23
|
+
state: Optional reference to DeviceState for updating local state
|
|
24
|
+
"""
|
|
25
|
+
self.auth = auth
|
|
26
|
+
self.endpoint = "audio_set"
|
|
27
|
+
self.state = state
|
|
28
|
+
|
|
29
|
+
async def async_set_hdmi_output(self, output: int, enabled: bool) -> bool:
|
|
30
|
+
"""Enable/disable HDMI audio output.
|
|
31
|
+
|
|
32
|
+
Args:
|
|
33
|
+
output: Output number (1-4 for specific, 0 for all)
|
|
34
|
+
enabled: True to enable, False to disable
|
|
35
|
+
|
|
36
|
+
Returns:
|
|
37
|
+
True if successful
|
|
38
|
+
|
|
39
|
+
Raises:
|
|
40
|
+
ValueError: If output number is invalid
|
|
41
|
+
DeviceError: If operation fails
|
|
42
|
+
|
|
43
|
+
Example:
|
|
44
|
+
>>> await api.async_set_hdmi_output(1, True) # Enable HDMI on Output 1
|
|
45
|
+
>>> await api.async_set_hdmi_output(0, False) # Disable HDMI on all outputs
|
|
46
|
+
"""
|
|
47
|
+
if not 0 <= output <= 4:
|
|
48
|
+
raise ValueError("Output must be 0 (all) or 1-4")
|
|
49
|
+
|
|
50
|
+
return await self._async_send_audio_command(output, 0, enabled)
|
|
51
|
+
|
|
52
|
+
async def async_set_de_embed_output(self, output: int, enabled: bool) -> bool:
|
|
53
|
+
"""Enable/disable de-embedded audio output.
|
|
54
|
+
|
|
55
|
+
Args:
|
|
56
|
+
output: Output number (1-4 for specific, 0 for all)
|
|
57
|
+
enabled: True to enable, False to disable
|
|
58
|
+
|
|
59
|
+
Returns:
|
|
60
|
+
True if successful
|
|
61
|
+
|
|
62
|
+
Raises:
|
|
63
|
+
ValueError: If output number is invalid
|
|
64
|
+
DeviceError: If operation fails
|
|
65
|
+
|
|
66
|
+
Example:
|
|
67
|
+
>>> await api.async_set_de_embed_output(2, True) # Enable de-embed on Output 2
|
|
68
|
+
"""
|
|
69
|
+
if not 0 <= output <= 4:
|
|
70
|
+
raise ValueError("Output must be 0 (all) or 1-4")
|
|
71
|
+
|
|
72
|
+
return await self._async_send_audio_command(output, 1, enabled)
|
|
73
|
+
|
|
74
|
+
async def _async_send_audio_command(self, output: int, mode: int, enabled: bool) -> bool:
|
|
75
|
+
"""Send audio control command to device.
|
|
76
|
+
|
|
77
|
+
Args:
|
|
78
|
+
output: Output number (0 = all, 1-4 = specific)
|
|
79
|
+
mode: 0 = HDMI, 1 = De-Embed
|
|
80
|
+
enabled: True to enable, False to disable
|
|
81
|
+
|
|
82
|
+
Returns:
|
|
83
|
+
True if successful
|
|
84
|
+
|
|
85
|
+
Raises:
|
|
86
|
+
DeviceError: If operation fails
|
|
87
|
+
"""
|
|
88
|
+
try:
|
|
89
|
+
# Convert boolean to device value (1 = enable, 0 = disable)
|
|
90
|
+
onoff = 1 if enabled else 0
|
|
91
|
+
mode_str = "hdmi" if mode == 0 else "dec"
|
|
92
|
+
|
|
93
|
+
# For all outputs, use output 0
|
|
94
|
+
device_output = output
|
|
95
|
+
|
|
96
|
+
cmd = f"#audio_d out{device_output} {mode_str}={onoff}"
|
|
97
|
+
logger.debug(f"Sending audio command: {cmd}")
|
|
98
|
+
|
|
99
|
+
async with await self.auth.request(
|
|
100
|
+
"POST",
|
|
101
|
+
self.endpoint,
|
|
102
|
+
data=cmd,
|
|
103
|
+
) as response:
|
|
104
|
+
response.raise_for_status()
|
|
105
|
+
|
|
106
|
+
output_label = f"Output {output}" if output != 0 else "All outputs"
|
|
107
|
+
mode_label = "HDMI" if mode == 0 else "De-Embed"
|
|
108
|
+
status = "enabled" if enabled else "disabled"
|
|
109
|
+
logger.info(f"{mode_label} {status} on {output_label}")
|
|
110
|
+
|
|
111
|
+
# Update local state if available
|
|
112
|
+
if self.state and output != 0:
|
|
113
|
+
audio_output = self.state.audio.get_output(output)
|
|
114
|
+
if audio_output:
|
|
115
|
+
if mode == 0:
|
|
116
|
+
audio_output.hdmi_enabled = enabled
|
|
117
|
+
else:
|
|
118
|
+
audio_output.de_embed_enabled = enabled
|
|
119
|
+
elif self.state and output == 0:
|
|
120
|
+
# Update all outputs
|
|
121
|
+
for out in range(1, 5):
|
|
122
|
+
audio_output = self.state.audio.get_output(out)
|
|
123
|
+
if audio_output:
|
|
124
|
+
if mode == 0:
|
|
125
|
+
audio_output.hdmi_enabled = enabled
|
|
126
|
+
else:
|
|
127
|
+
audio_output.de_embed_enabled = enabled
|
|
128
|
+
|
|
129
|
+
return True
|
|
130
|
+
|
|
131
|
+
except Exception as e:
|
|
132
|
+
logger.error(f"Failed to set audio output: {e}")
|
|
133
|
+
raise DeviceError(f"Audio output control failed: {e}") from e
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
"""Data structures for device status following the JavaScript pattern.
|
|
2
|
+
|
|
3
|
+
This module mirrors the JS data structures from the original implementation:
|
|
4
|
+
- IP_INFO_T: Network configuration data
|
|
5
|
+
- RUN_INF_T: Device runtime state
|
|
6
|
+
- STRING_INF_T: String data (names)
|
|
7
|
+
- Web_Info: Complete device information container
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
from dataclasses import dataclass, field
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
@dataclass
|
|
14
|
+
class IPInfo:
|
|
15
|
+
"""Network configuration data (IP_INFO_T equivalent).
|
|
16
|
+
|
|
17
|
+
Mirrors the JS structure:
|
|
18
|
+
function IP_INFO_T() {
|
|
19
|
+
this.dhcp=0;
|
|
20
|
+
this.ip=0;
|
|
21
|
+
this.mask=0;
|
|
22
|
+
this.gw=0;
|
|
23
|
+
this.dns=0;
|
|
24
|
+
this.mac=0;
|
|
25
|
+
this.port=0;
|
|
26
|
+
this.device_id=0;
|
|
27
|
+
this.netbios=0;
|
|
28
|
+
}
|
|
29
|
+
"""
|
|
30
|
+
|
|
31
|
+
dhcp: int = 0
|
|
32
|
+
ip: str = "0.0.0.0"
|
|
33
|
+
mask: str = "0.0.0.0"
|
|
34
|
+
gw: str = "0.0.0.0"
|
|
35
|
+
dns: str = "0.0.0.0"
|
|
36
|
+
mac: str = "00:00:00:00:00:00"
|
|
37
|
+
port: int = 0
|
|
38
|
+
device_id: str = ""
|
|
39
|
+
netbios: str = ""
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
@dataclass
|
|
43
|
+
class RunInfo:
|
|
44
|
+
"""Device runtime state (RUN_INF_T equivalent).
|
|
45
|
+
|
|
46
|
+
Mirrors the JS structure containing all runtime state data.
|
|
47
|
+
"""
|
|
48
|
+
|
|
49
|
+
# Video matrix state: which input is connected to each output
|
|
50
|
+
video_mx: list[int] = field(default_factory=lambda: [0] * 4)
|
|
51
|
+
|
|
52
|
+
# Video on/off state for each output
|
|
53
|
+
video_nf: list[int] = field(default_factory=lambda: [0] * 4)
|
|
54
|
+
|
|
55
|
+
# Audio HDMI state for each output
|
|
56
|
+
audio_hdmi: list[int] = field(default_factory=lambda: [0] * 4)
|
|
57
|
+
|
|
58
|
+
# Audio de-embedded state for each output
|
|
59
|
+
audio_dec: list[int] = field(default_factory=lambda: [0] * 4)
|
|
60
|
+
|
|
61
|
+
# EDID modification flags
|
|
62
|
+
edid_mdf: list[int] = field(default_factory=lambda: [0] * 4)
|
|
63
|
+
|
|
64
|
+
# EDID configuration data
|
|
65
|
+
edid_cfg: list[int] = field(default_factory=lambda: [0] * (4 * (4 + 16 + 1)))
|
|
66
|
+
|
|
67
|
+
# Active EDID index for each input
|
|
68
|
+
edid_inf: list[int] = field(default_factory=lambda: [0] * 4)
|
|
69
|
+
|
|
70
|
+
# Input port status (connection status)
|
|
71
|
+
in_port_status: list[int] = field(default_factory=lambda: [0] * 4)
|
|
72
|
+
|
|
73
|
+
# Output port status (connection status)
|
|
74
|
+
out_port_status: list[int] = field(default_factory=lambda: [0] * 4)
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
@dataclass
|
|
78
|
+
class StringInfo:
|
|
79
|
+
"""String data for naming and labels (STRING_INF_T equivalent).
|
|
80
|
+
|
|
81
|
+
Mirrors the JS structure containing all string/label data.
|
|
82
|
+
"""
|
|
83
|
+
|
|
84
|
+
# EDID information/descriptions (21 EDID profiles)
|
|
85
|
+
edid_info: list[str] = field(default_factory=lambda: [""] * 21)
|
|
86
|
+
|
|
87
|
+
# Port names (8 total: 4 inputs + 4 outputs)
|
|
88
|
+
port_name: list[str] = field(default_factory=lambda: [""] * 8)
|
|
89
|
+
|
|
90
|
+
# Preset names (8 presets)
|
|
91
|
+
preset_name: list[str] = field(default_factory=lambda: [""] * 8)
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
@dataclass
|
|
95
|
+
class WebInfo:
|
|
96
|
+
"""Complete device information (Web_Info equivalent).
|
|
97
|
+
|
|
98
|
+
Container for all device data following the JS pattern:
|
|
99
|
+
function Web_Info() {
|
|
100
|
+
this.ip=new IP_INFO_T();
|
|
101
|
+
this.run=new RUN_INF_T();
|
|
102
|
+
this.name=new STRING_INF_T();
|
|
103
|
+
}
|
|
104
|
+
"""
|
|
105
|
+
|
|
106
|
+
ip: IPInfo = field(default_factory=IPInfo)
|
|
107
|
+
run: RunInfo = field(default_factory=RunInfo)
|
|
108
|
+
name: StringInfo = field(default_factory=StringInfo)
|
|
109
|
+
|
|
110
|
+
def reset(self) -> None: # pragma: no cover
|
|
111
|
+
"""Reset all data to default values."""
|
|
112
|
+
self.ip = IPInfo()
|
|
113
|
+
self.run = RunInfo()
|
|
114
|
+
self.name = StringInfo()
|
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
"""EDID control API."""
|
|
2
|
+
|
|
3
|
+
import logging
|
|
4
|
+
from typing import TYPE_CHECKING, Optional
|
|
5
|
+
|
|
6
|
+
from ..exceptions import DeviceError
|
|
7
|
+
|
|
8
|
+
if TYPE_CHECKING:
|
|
9
|
+
from ..auth import PureLinkAuth
|
|
10
|
+
from ..models import DeviceState
|
|
11
|
+
|
|
12
|
+
logger = logging.getLogger(__name__)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class EDIDProfile:
|
|
16
|
+
"""EDID profile definitions."""
|
|
17
|
+
|
|
18
|
+
PROFILES = {
|
|
19
|
+
1: "Default1:4K60 444-LPCM: 2.0, HDR:HLG",
|
|
20
|
+
2: "Default2:4K60 420-LPCM: 2.0, HDR:None",
|
|
21
|
+
3: "Default3:4K30 444-LPCM: 2.0, HDR:None",
|
|
22
|
+
4: "Default4:1080P60 444-LPCM: 2.0, HDR:None",
|
|
23
|
+
5: "Default5:4K60 444-DTS: 5.1, HDR:HLG",
|
|
24
|
+
6: "Default6:4K60 420-DTS: 5.1, HDR:None",
|
|
25
|
+
7: "Default7:4K30 444-DTS: 5.1, HDR:None",
|
|
26
|
+
8: "Default8:1080P60 444-DTS: 5.1, HDR:None",
|
|
27
|
+
9: "User1",
|
|
28
|
+
10: "User2",
|
|
29
|
+
11: "User3",
|
|
30
|
+
12: "User4",
|
|
31
|
+
13: "Output1",
|
|
32
|
+
14: "Output2",
|
|
33
|
+
15: "Output3",
|
|
34
|
+
16: "Output4",
|
|
35
|
+
17: "Temp1",
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
class EDIDAPI:
|
|
40
|
+
"""API for EDID control operations."""
|
|
41
|
+
|
|
42
|
+
def __init__(self, auth: "PureLinkAuth", state: Optional["DeviceState"] = None):
|
|
43
|
+
"""Initialize EDID API.
|
|
44
|
+
|
|
45
|
+
Args:
|
|
46
|
+
auth: PureLinkAuth instance for HTTP communication
|
|
47
|
+
state: Optional reference to DeviceState for updating local state
|
|
48
|
+
"""
|
|
49
|
+
self.auth = auth
|
|
50
|
+
self.endpoint = "input.set"
|
|
51
|
+
self.state = state
|
|
52
|
+
|
|
53
|
+
async def async_set_input_edid(self, input_num: int, edid_source: int) -> bool:
|
|
54
|
+
"""Set EDID profile for an input.
|
|
55
|
+
|
|
56
|
+
Available EDID sources:
|
|
57
|
+
- 1-8: Default profiles (various resolutions/audio/HDR combinations)
|
|
58
|
+
- 9-12: User-defined EDID profiles
|
|
59
|
+
- 13-16: Copy from output
|
|
60
|
+
- 17: Temp storage
|
|
61
|
+
|
|
62
|
+
Args:
|
|
63
|
+
input_num: Input number (1-4, 0 for all)
|
|
64
|
+
edid_source: EDID profile number (1-17)
|
|
65
|
+
|
|
66
|
+
Returns:
|
|
67
|
+
True if successful
|
|
68
|
+
|
|
69
|
+
Raises:
|
|
70
|
+
ValueError: If input number or EDID source is invalid
|
|
71
|
+
DeviceError: If operation fails
|
|
72
|
+
|
|
73
|
+
Example:
|
|
74
|
+
>>> await api.async_set_input_edid(1, 1) # Set Default1 profile on Input 1
|
|
75
|
+
>>> await api.async_set_input_edid(0, 4) # Set Default4 on all inputs
|
|
76
|
+
"""
|
|
77
|
+
if not 0 <= input_num <= 4:
|
|
78
|
+
raise ValueError("Input number must be 0 (all) or 1-4")
|
|
79
|
+
if not 1 <= edid_source <= 17:
|
|
80
|
+
raise ValueError("EDID source must be 1-17")
|
|
81
|
+
|
|
82
|
+
try:
|
|
83
|
+
edid_type, edid_index = self._get_edid_type_and_index(edid_source)
|
|
84
|
+
|
|
85
|
+
cmd = f"#edid in{input_num} cfg={edid_type}/{edid_index}"
|
|
86
|
+
logger.debug(f"Setting input EDID: {cmd}")
|
|
87
|
+
|
|
88
|
+
async with await self.auth.request(
|
|
89
|
+
"POST",
|
|
90
|
+
self.endpoint,
|
|
91
|
+
data=cmd,
|
|
92
|
+
) as response:
|
|
93
|
+
response.raise_for_status()
|
|
94
|
+
|
|
95
|
+
input_label = f"Input {input_num}" if input_num != 0 else "All inputs"
|
|
96
|
+
profile_name = EDIDProfile.PROFILES.get(edid_source, f"Profile {edid_source}")
|
|
97
|
+
logger.info(f"Set {input_label} EDID to {profile_name}")
|
|
98
|
+
|
|
99
|
+
# Update local state if available
|
|
100
|
+
if self.state and input_num != 0:
|
|
101
|
+
self.state.edid._set_input_edid(input_num, edid_source)
|
|
102
|
+
elif self.state and input_num == 0:
|
|
103
|
+
# Update all inputs
|
|
104
|
+
for inp in range(1, 5):
|
|
105
|
+
self.state.edid._set_input_edid(inp, edid_source)
|
|
106
|
+
|
|
107
|
+
return True
|
|
108
|
+
|
|
109
|
+
except Exception as e:
|
|
110
|
+
logger.error(f"Failed to set input EDID: {e}")
|
|
111
|
+
raise DeviceError(f"Input EDID configuration failed: {e}") from e
|
|
112
|
+
|
|
113
|
+
async def async_set_user_edid(self, source_profile: int, destination: int) -> bool:
|
|
114
|
+
"""Copy EDID profile to user storage.
|
|
115
|
+
|
|
116
|
+
Copy a source EDID profile (default, user, output, or temp) to a
|
|
117
|
+
user storage location (User1-User4).
|
|
118
|
+
|
|
119
|
+
Args:
|
|
120
|
+
source_profile: Source EDID profile number (1-17)
|
|
121
|
+
destination: Destination user slot (1-4, 0 for all user slots)
|
|
122
|
+
|
|
123
|
+
Returns:
|
|
124
|
+
True if successful
|
|
125
|
+
|
|
126
|
+
Raises:
|
|
127
|
+
ValueError: If parameters are invalid
|
|
128
|
+
DeviceError: If operation fails
|
|
129
|
+
|
|
130
|
+
Example:
|
|
131
|
+
>>> await api.async_set_user_edid(1, 1) # Copy Default1 to User1
|
|
132
|
+
>>> await api.async_set_user_edid(2, 0) # Copy Default2 to all user slots
|
|
133
|
+
"""
|
|
134
|
+
if not 1 <= source_profile <= 17:
|
|
135
|
+
raise ValueError("Source profile must be 1-17")
|
|
136
|
+
if not 0 <= destination <= 4:
|
|
137
|
+
raise ValueError("Destination must be 0 (all) or 1-4")
|
|
138
|
+
|
|
139
|
+
try:
|
|
140
|
+
edid_type, edid_index = self._get_edid_type_and_index(source_profile)
|
|
141
|
+
|
|
142
|
+
cmd = f"#edid user{destination} cfg={edid_type}/{edid_index}"
|
|
143
|
+
logger.debug(f"Setting user EDID: {cmd}")
|
|
144
|
+
|
|
145
|
+
async with await self.auth.request(
|
|
146
|
+
"POST",
|
|
147
|
+
self.endpoint,
|
|
148
|
+
data=cmd,
|
|
149
|
+
) as response:
|
|
150
|
+
response.raise_for_status()
|
|
151
|
+
|
|
152
|
+
source_name = EDIDProfile.PROFILES.get(source_profile, f"Profile {source_profile}")
|
|
153
|
+
dest_label = f"User{destination}" if destination != 0 else "All user slots"
|
|
154
|
+
logger.info(f"Copied {source_name} to {dest_label}")
|
|
155
|
+
|
|
156
|
+
return True
|
|
157
|
+
|
|
158
|
+
except Exception as e:
|
|
159
|
+
logger.error(f"Failed to set user EDID: {e}")
|
|
160
|
+
raise DeviceError(f"User EDID configuration failed: {e}") from e
|
|
161
|
+
|
|
162
|
+
@staticmethod
|
|
163
|
+
def _get_edid_type_and_index(edid_source: int) -> tuple[int, int]:
|
|
164
|
+
"""Convert EDID source to type and index for device command.
|
|
165
|
+
|
|
166
|
+
Args:
|
|
167
|
+
edid_source: EDID profile number (1-17)
|
|
168
|
+
|
|
169
|
+
Returns:
|
|
170
|
+
Tuple of (edid_type, edid_index)
|
|
171
|
+
"""
|
|
172
|
+
if edid_source <= 8:
|
|
173
|
+
# Default profiles (type 0)
|
|
174
|
+
return 0, edid_source
|
|
175
|
+
elif edid_source <= 12:
|
|
176
|
+
# User profiles (type 1)
|
|
177
|
+
return 1, edid_source - 8
|
|
178
|
+
elif edid_source <= 16:
|
|
179
|
+
# Output profiles (type 2)
|
|
180
|
+
return 2, edid_source - 12
|
|
181
|
+
else:
|
|
182
|
+
# Temp profile (type 4)
|
|
183
|
+
return 4, 1
|
|
184
|
+
|
|
185
|
+
async def async_rename_input_port(self, input_num: int, name: str) -> bool:
|
|
186
|
+
"""Rename an input port in EDID section.
|
|
187
|
+
|
|
188
|
+
Args:
|
|
189
|
+
input_num: Input number (1-4)
|
|
190
|
+
name: New name (max 15 characters)
|
|
191
|
+
|
|
192
|
+
Returns:
|
|
193
|
+
True if successful
|
|
194
|
+
|
|
195
|
+
Raises:
|
|
196
|
+
ValueError: If parameters are invalid
|
|
197
|
+
DeviceError: If operation fails
|
|
198
|
+
"""
|
|
199
|
+
if not 1 <= input_num <= 4:
|
|
200
|
+
raise ValueError("Input number must be 1-4")
|
|
201
|
+
|
|
202
|
+
self._validate_name(name)
|
|
203
|
+
|
|
204
|
+
try:
|
|
205
|
+
cmd = f"#name{input_num - 1} str={name}"
|
|
206
|
+
logger.debug(f"Renaming input port: {cmd}")
|
|
207
|
+
|
|
208
|
+
async with await self.auth.request(
|
|
209
|
+
"POST",
|
|
210
|
+
self.endpoint,
|
|
211
|
+
data=cmd,
|
|
212
|
+
) as response:
|
|
213
|
+
response.raise_for_status()
|
|
214
|
+
logger.info(f"Renamed Input {input_num} to '{name}'")
|
|
215
|
+
|
|
216
|
+
return True
|
|
217
|
+
|
|
218
|
+
except Exception as e:
|
|
219
|
+
logger.error(f"Failed to rename input port: {e}")
|
|
220
|
+
raise DeviceError(f"Input port rename failed: {e}") from e
|
|
221
|
+
|
|
222
|
+
@staticmethod
|
|
223
|
+
def _validate_name(name: str) -> None:
|
|
224
|
+
"""Validate name format.
|
|
225
|
+
|
|
226
|
+
Args:
|
|
227
|
+
name: Name to validate
|
|
228
|
+
|
|
229
|
+
Raises:
|
|
230
|
+
ValueError: If name format is invalid
|
|
231
|
+
"""
|
|
232
|
+
if not name or not isinstance(name, str):
|
|
233
|
+
raise ValueError("Name must be a non-empty string")
|
|
234
|
+
|
|
235
|
+
if len(name) > 15:
|
|
236
|
+
raise ValueError("Name must be 15 characters or less")
|
|
237
|
+
|
|
238
|
+
import re
|
|
239
|
+
|
|
240
|
+
pattern = re.compile(r"^[a-zA-Z0-9_\-]{1,15}$")
|
|
241
|
+
if not pattern.match(name):
|
|
242
|
+
raise ValueError("Name must contain only letters, numbers, underscores, and hyphens")
|