pymidi-controller 0.1.0__tar.gz

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 (29) hide show
  1. pymidi_controller-0.1.0/LICENSE +21 -0
  2. pymidi_controller-0.1.0/MANIFEST.in +3 -0
  3. pymidi_controller-0.1.0/PKG-INFO +240 -0
  4. pymidi_controller-0.1.0/README.md +216 -0
  5. pymidi_controller-0.1.0/pymidi_controller/__init__.py +1 -0
  6. pymidi_controller-0.1.0/pymidi_controller/actions/__init__.py +0 -0
  7. pymidi_controller-0.1.0/pymidi_controller/actions/elgato.py +55 -0
  8. pymidi_controller-0.1.0/pymidi_controller/actions/elgato_discovery.py +50 -0
  9. pymidi_controller-0.1.0/pymidi_controller/actions/hue.py +224 -0
  10. pymidi_controller-0.1.0/pymidi_controller/actions/hue_discovery.py +81 -0
  11. pymidi_controller-0.1.0/pymidi_controller/cli.py +146 -0
  12. pymidi_controller-0.1.0/pymidi_controller/config.py +17 -0
  13. pymidi_controller-0.1.0/pymidi_controller/core.py +83 -0
  14. pymidi_controller-0.1.0/pymidi_controller/data/default_config.yaml +31 -0
  15. pymidi_controller-0.1.0/pymidi_controller/data/systemd/pymidi-controller.service +15 -0
  16. pymidi_controller-0.1.0/pymidi_controller/utils/__init__.py +0 -0
  17. pymidi_controller-0.1.0/pymidi_controller/utils/color_cycle.py +13 -0
  18. pymidi_controller-0.1.0/pymidi_controller/utils/config_manager.py +39 -0
  19. pymidi_controller-0.1.0/pymidi_controller/utils/midi_utils.py +60 -0
  20. pymidi_controller-0.1.0/pymidi_controller/utils/service_manager.py +136 -0
  21. pymidi_controller-0.1.0/pymidi_controller/utils/state_manager.py +50 -0
  22. pymidi_controller-0.1.0/pymidi_controller.egg-info/PKG-INFO +240 -0
  23. pymidi_controller-0.1.0/pymidi_controller.egg-info/SOURCES.txt +27 -0
  24. pymidi_controller-0.1.0/pymidi_controller.egg-info/dependency_links.txt +1 -0
  25. pymidi_controller-0.1.0/pymidi_controller.egg-info/entry_points.txt +3 -0
  26. pymidi_controller-0.1.0/pymidi_controller.egg-info/requires.txt +5 -0
  27. pymidi_controller-0.1.0/pymidi_controller.egg-info/top_level.txt +1 -0
  28. pymidi_controller-0.1.0/pyproject.toml +45 -0
  29. pymidi_controller-0.1.0/setup.cfg +4 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Alex Sandilands
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,3 @@
1
+ # MANIFEST.in
2
+ include README.md LICENSE
3
+ recursive-include pymidi_controller/data *
@@ -0,0 +1,240 @@
1
+ Metadata-Version: 2.4
2
+ Name: pymidi-controller
3
+ Version: 0.1.0
4
+ Summary: Daemon that maps MIDI events to system actions (Elgato, Hue, etc.)
5
+ Author-email: Alex Sandilands <sandilands.alex@gmail.com>
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/AlexSandilands/pymidi-controller
8
+ Project-URL: Bug Tracker, https://github.com/AlexSandilands/pymidi-controller/issues
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: Operating System :: POSIX :: Linux
11
+ Classifier: Topic :: Multimedia :: Sound/Audio :: MIDI
12
+ Classifier: Topic :: Home Automation
13
+ Classifier: Topic :: System :: Hardware :: Hardware Drivers
14
+ Classifier: Topic :: Utilities
15
+ Requires-Python: >=3.7
16
+ Description-Content-Type: text/markdown
17
+ License-File: LICENSE
18
+ Requires-Dist: mido>=1.2.10
19
+ Requires-Dist: python-rtmidi>=1.4.10
20
+ Requires-Dist: requests>=2.0
21
+ Requires-Dist: zeroconf>=0.40
22
+ Requires-Dist: PyYAML>=6.0
23
+ Dynamic: license-file
24
+
25
+ # ๐ŸŽน PyMIDI Controller
26
+
27
+ [![Python](https://img.shields.io/badge/python-3.7%2B-blue)](https://www.python.org/downloads/)
28
+ [![License](https://img.shields.io/github/license/AlexSandilands/pymidi-controller)](https://github.com/AlexSandilands/pymidi-controller/blob/main/LICENSE)
29
+ [![Last Commit](https://img.shields.io/github/last-commit/AlexSandilands/pymidi-controller)](https://github.com/AlexSandilands/pymidi-controller/commits/main)
30
+
31
+ A lightweight Python CLI and background MIDI listener for controlling Philips Hue and Elgato Ring Lights via a MIDI device.
32
+
33
+ ---
34
+
35
+ ## ๐Ÿ“š Table of Contents
36
+
37
+ - [๐Ÿš€ Installation](#-installation)
38
+ - [โšก Quickstart](#-quickstart)
39
+ - [โš™๏ธ Configuration](#๏ธ-configuration)
40
+ - [๐ŸŽ›๏ธ Commands](#๏ธ-commands)
41
+ - [Global](#global)
42
+ - [Service](#service)
43
+ - [Hue Commands](#hue-commands)
44
+ - [Elgato Commands](#elgato-commands)
45
+ - [MIDI Commands](#midi-commands)
46
+ - [๐ŸŽน MIDI Binding Guide](#-midi-binding-guide)
47
+ - [โš™๏ธ Service (Optional)](#๏ธ-service-optional)
48
+
49
+ ## ๐Ÿš€ Installation
50
+
51
+ **Requirements:**
52
+
53
+ - Pythonย 3.7ย or higher
54
+ - A modern Linux distro (systemd)
55
+
56
+ ### Via pip
57
+
58
+ ```bash
59
+ pip install pymidi-controller
60
+ ```
61
+
62
+ ### Via pipx (isolated install)
63
+
64
+ ```bash
65
+ pipx install pymidi-controller
66
+ ```
67
+
68
+ > If you use `pipx`, make sure `~/.local/bin` is on your `PATH` (`pipx ensurepath`).
69
+
70
+ ---
71
+
72
+ ## โšก Quickstart
73
+
74
+ 1. **Initialize your config** (creates `~/.config/pymidi-controller/config.yaml`):
75
+ ```bash
76
+ pymidi init
77
+ ```
78
+ 2. **Discover your Hue Bridge** (press the link button when prompted):
79
+ ```bash
80
+ pymidi hue discover
81
+ ```
82
+ 3. **Discover your Elgato Ring Light**:
83
+ ```bash
84
+ pymidi elgato discover
85
+ ```
86
+ 4. **Map MIDI inputs** (listen to your controller to grab event keys):
87
+ ```bash
88
+ pymidi midi listen
89
+ ```
90
+ Press buttons/knobs to print strings like `control_change:0:12:127` for use in your config.
91
+ 5. **Edit your config** (see [Configuration](#๏ธ-configuration)) to add your device IPs, API keys, MIDI bindings, and color cycles.
92
+ 6. **Start the listener to test configuration**:
93
+ ```bash
94
+ pymidi run --mode blocking
95
+ ```
96
+ 7. **(Optional) Background Service**:
97
+ You can also install as a background service: see [Service](#๏ธ-service-optional).
98
+
99
+ ---
100
+
101
+ ## โš™๏ธ Configuration
102
+
103
+ All settings live in a single YAML file:
104
+
105
+ ```
106
+ ~/.config/pymidi-controller/config.yaml
107
+ ```
108
+
109
+ This file will contain potentially sensitive data like your Hue API key or your IP address,
110
+ so it will be flagged as senstive and set so only your user can read it.
111
+
112
+ ### Example `config.yaml`
113
+
114
+ ```yaml
115
+ hue:
116
+ bridge_ip: 192.168.1.42 # your Hue Bridge address
117
+ api_key: YOUR_HUE_API_KEY # obtained via `pymidi hue discover`
118
+
119
+ elgato:
120
+ host: 192.168.1.43 # your Elgato Ring Light address
121
+
122
+ midi:
123
+ devices:
124
+ - "Streamer X"
125
+ - "nanoPAD"
126
+
127
+ # Map MIDI event keys โ†’ pymidi commands
128
+ bindings:
129
+ control_change:0:12:127:
130
+ - hue
131
+ - toggle-group
132
+ - "Living Room"
133
+ control_change:0:14:127:
134
+ - elgato
135
+ - toggle
136
+
137
+ # Optional: define color cycles per group
138
+ color_cycles:
139
+ Living Room:
140
+ - red
141
+ - blue
142
+ - green
143
+ ```
144
+ ---
145
+
146
+ ## ๐ŸŽ›๏ธ Commands
147
+
148
+ Use `pymidi <group> --help` for details on each context.
149
+
150
+ ### Global
151
+
152
+ | Command | Description |
153
+ | ------------- | ------------------------------------------- |
154
+ | `pymidi init` | Create default config file |
155
+ | `pymidi run` | Start the MIDI listener (`--mode blocking`) |
156
+
157
+ ### Service
158
+
159
+ | Command | Description |
160
+ | ----------------------------------- | ----------------------------------- |
161
+ | `pymidi service install --user` | Install & start as a user service |
162
+ | `pymidi service install --system` | Install & start system-wide service |
163
+ | `pymidi service uninstall --user` | Stop & remove user service |
164
+ | `pymidi service uninstall --system` | Stop & remove system service |
165
+ | `pymidi service stop` | Stop the running service |
166
+ | `pymidi service enable` | Enable service (user scope) |
167
+ | `pymidi service log` | Tail service logs |
168
+
169
+ ### Hue Commands
170
+
171
+ | Command | Description |
172
+ | ---------------------------------------------------------- | ---------------------------------------- |
173
+ | `pymidi hue discover` | Find bridge & generate API key |
174
+ | `pymidi hue list-groups` | List all groups and on/off states |
175
+ | `pymidi hue list-lights` | List all lights and their state/effect |
176
+ | `pymidi hue list-schedules` | List all schedules |
177
+ | `pymidi hue toggle-group <group>` | Toggle a group on/off |
178
+ | `pymidi hue set-color <group> <color> [--sat N] [--bri N]` | Set group color |
179
+ | `pymidi hue toggle-schedule <name>` | Enable/disable a schedule |
180
+ | `pymidi hue loop [--effect colorloop \| none]` | Toggle colorloop effect |
181
+ | `pymidi hue cycle-color <group>` | Cycle group color through `color_cycles` |
182
+
183
+ ### Elgato Commands
184
+
185
+ | Command | Description |
186
+ | ------------------------ | ------------------------------ |
187
+ | `pymidi elgato discover` | Discover Ring Light via mDNS |
188
+ | `pymidi elgato toggle` | Toggle Ring Light on/off |
189
+ | `pymidi elgato info` | Show current Ring Light status |
190
+
191
+ ### MIDI Commands
192
+
193
+ | Command | Description |
194
+ | -------------------- | ------------------------------------------ |
195
+ | `pymidi midi listen` | Print incoming MIDI event keys for mapping |
196
+
197
+ ---
198
+
199
+ ## ๐ŸŽน MIDI Binding Guide
200
+
201
+ 1. Run:
202
+ ```bash
203
+ pymidi midi listen
204
+ ```
205
+ 2. Press a control (button/knob) to see its event key, e.g. `control_change:0:12:127`.
206
+ 3. Open `~/.config/pymidi-controller/config.yaml` and under `midi.bindings`, add:
207
+ ```yaml
208
+ bindings:
209
+ control_change:0:12:127:
210
+ - hue
211
+ - toggle-group
212
+ - "Living Room"
213
+ ```
214
+ Each value under the event key should be one part in order of the [Commands](#๏ธ-commands)
215
+ 4. Save and test:
216
+ ```bash
217
+ pymidi run --mode interactive
218
+ ```
219
+
220
+ ---
221
+
222
+ ## โš™๏ธ Service (Optional)
223
+
224
+ To run automatically at login:
225
+
226
+ ```bash
227
+ pymidi service install --user
228
+ ```
229
+
230
+ Logs:
231
+
232
+ ```bash
233
+ pymidi service log
234
+ ```
235
+
236
+ ---
237
+
238
+ ## ๐Ÿ“œ License
239
+
240
+ MIT ยฉ Alex Sandilands
@@ -0,0 +1,216 @@
1
+ # ๐ŸŽน PyMIDI Controller
2
+
3
+ [![Python](https://img.shields.io/badge/python-3.7%2B-blue)](https://www.python.org/downloads/)
4
+ [![License](https://img.shields.io/github/license/AlexSandilands/pymidi-controller)](https://github.com/AlexSandilands/pymidi-controller/blob/main/LICENSE)
5
+ [![Last Commit](https://img.shields.io/github/last-commit/AlexSandilands/pymidi-controller)](https://github.com/AlexSandilands/pymidi-controller/commits/main)
6
+
7
+ A lightweight Python CLI and background MIDI listener for controlling Philips Hue and Elgato Ring Lights via a MIDI device.
8
+
9
+ ---
10
+
11
+ ## ๐Ÿ“š Table of Contents
12
+
13
+ - [๐Ÿš€ Installation](#-installation)
14
+ - [โšก Quickstart](#-quickstart)
15
+ - [โš™๏ธ Configuration](#๏ธ-configuration)
16
+ - [๐ŸŽ›๏ธ Commands](#๏ธ-commands)
17
+ - [Global](#global)
18
+ - [Service](#service)
19
+ - [Hue Commands](#hue-commands)
20
+ - [Elgato Commands](#elgato-commands)
21
+ - [MIDI Commands](#midi-commands)
22
+ - [๐ŸŽน MIDI Binding Guide](#-midi-binding-guide)
23
+ - [โš™๏ธ Service (Optional)](#๏ธ-service-optional)
24
+
25
+ ## ๐Ÿš€ Installation
26
+
27
+ **Requirements:**
28
+
29
+ - Pythonย 3.7ย or higher
30
+ - A modern Linux distro (systemd)
31
+
32
+ ### Via pip
33
+
34
+ ```bash
35
+ pip install pymidi-controller
36
+ ```
37
+
38
+ ### Via pipx (isolated install)
39
+
40
+ ```bash
41
+ pipx install pymidi-controller
42
+ ```
43
+
44
+ > If you use `pipx`, make sure `~/.local/bin` is on your `PATH` (`pipx ensurepath`).
45
+
46
+ ---
47
+
48
+ ## โšก Quickstart
49
+
50
+ 1. **Initialize your config** (creates `~/.config/pymidi-controller/config.yaml`):
51
+ ```bash
52
+ pymidi init
53
+ ```
54
+ 2. **Discover your Hue Bridge** (press the link button when prompted):
55
+ ```bash
56
+ pymidi hue discover
57
+ ```
58
+ 3. **Discover your Elgato Ring Light**:
59
+ ```bash
60
+ pymidi elgato discover
61
+ ```
62
+ 4. **Map MIDI inputs** (listen to your controller to grab event keys):
63
+ ```bash
64
+ pymidi midi listen
65
+ ```
66
+ Press buttons/knobs to print strings like `control_change:0:12:127` for use in your config.
67
+ 5. **Edit your config** (see [Configuration](#๏ธ-configuration)) to add your device IPs, API keys, MIDI bindings, and color cycles.
68
+ 6. **Start the listener to test configuration**:
69
+ ```bash
70
+ pymidi run --mode blocking
71
+ ```
72
+ 7. **(Optional) Background Service**:
73
+ You can also install as a background service: see [Service](#๏ธ-service-optional).
74
+
75
+ ---
76
+
77
+ ## โš™๏ธ Configuration
78
+
79
+ All settings live in a single YAML file:
80
+
81
+ ```
82
+ ~/.config/pymidi-controller/config.yaml
83
+ ```
84
+
85
+ This file will contain potentially sensitive data like your Hue API key or your IP address,
86
+ so it will be flagged as senstive and set so only your user can read it.
87
+
88
+ ### Example `config.yaml`
89
+
90
+ ```yaml
91
+ hue:
92
+ bridge_ip: 192.168.1.42 # your Hue Bridge address
93
+ api_key: YOUR_HUE_API_KEY # obtained via `pymidi hue discover`
94
+
95
+ elgato:
96
+ host: 192.168.1.43 # your Elgato Ring Light address
97
+
98
+ midi:
99
+ devices:
100
+ - "Streamer X"
101
+ - "nanoPAD"
102
+
103
+ # Map MIDI event keys โ†’ pymidi commands
104
+ bindings:
105
+ control_change:0:12:127:
106
+ - hue
107
+ - toggle-group
108
+ - "Living Room"
109
+ control_change:0:14:127:
110
+ - elgato
111
+ - toggle
112
+
113
+ # Optional: define color cycles per group
114
+ color_cycles:
115
+ Living Room:
116
+ - red
117
+ - blue
118
+ - green
119
+ ```
120
+ ---
121
+
122
+ ## ๐ŸŽ›๏ธ Commands
123
+
124
+ Use `pymidi <group> --help` for details on each context.
125
+
126
+ ### Global
127
+
128
+ | Command | Description |
129
+ | ------------- | ------------------------------------------- |
130
+ | `pymidi init` | Create default config file |
131
+ | `pymidi run` | Start the MIDI listener (`--mode blocking`) |
132
+
133
+ ### Service
134
+
135
+ | Command | Description |
136
+ | ----------------------------------- | ----------------------------------- |
137
+ | `pymidi service install --user` | Install & start as a user service |
138
+ | `pymidi service install --system` | Install & start system-wide service |
139
+ | `pymidi service uninstall --user` | Stop & remove user service |
140
+ | `pymidi service uninstall --system` | Stop & remove system service |
141
+ | `pymidi service stop` | Stop the running service |
142
+ | `pymidi service enable` | Enable service (user scope) |
143
+ | `pymidi service log` | Tail service logs |
144
+
145
+ ### Hue Commands
146
+
147
+ | Command | Description |
148
+ | ---------------------------------------------------------- | ---------------------------------------- |
149
+ | `pymidi hue discover` | Find bridge & generate API key |
150
+ | `pymidi hue list-groups` | List all groups and on/off states |
151
+ | `pymidi hue list-lights` | List all lights and their state/effect |
152
+ | `pymidi hue list-schedules` | List all schedules |
153
+ | `pymidi hue toggle-group <group>` | Toggle a group on/off |
154
+ | `pymidi hue set-color <group> <color> [--sat N] [--bri N]` | Set group color |
155
+ | `pymidi hue toggle-schedule <name>` | Enable/disable a schedule |
156
+ | `pymidi hue loop [--effect colorloop \| none]` | Toggle colorloop effect |
157
+ | `pymidi hue cycle-color <group>` | Cycle group color through `color_cycles` |
158
+
159
+ ### Elgato Commands
160
+
161
+ | Command | Description |
162
+ | ------------------------ | ------------------------------ |
163
+ | `pymidi elgato discover` | Discover Ring Light via mDNS |
164
+ | `pymidi elgato toggle` | Toggle Ring Light on/off |
165
+ | `pymidi elgato info` | Show current Ring Light status |
166
+
167
+ ### MIDI Commands
168
+
169
+ | Command | Description |
170
+ | -------------------- | ------------------------------------------ |
171
+ | `pymidi midi listen` | Print incoming MIDI event keys for mapping |
172
+
173
+ ---
174
+
175
+ ## ๐ŸŽน MIDI Binding Guide
176
+
177
+ 1. Run:
178
+ ```bash
179
+ pymidi midi listen
180
+ ```
181
+ 2. Press a control (button/knob) to see its event key, e.g. `control_change:0:12:127`.
182
+ 3. Open `~/.config/pymidi-controller/config.yaml` and under `midi.bindings`, add:
183
+ ```yaml
184
+ bindings:
185
+ control_change:0:12:127:
186
+ - hue
187
+ - toggle-group
188
+ - "Living Room"
189
+ ```
190
+ Each value under the event key should be one part in order of the [Commands](#๏ธ-commands)
191
+ 4. Save and test:
192
+ ```bash
193
+ pymidi run --mode interactive
194
+ ```
195
+
196
+ ---
197
+
198
+ ## โš™๏ธ Service (Optional)
199
+
200
+ To run automatically at login:
201
+
202
+ ```bash
203
+ pymidi service install --user
204
+ ```
205
+
206
+ Logs:
207
+
208
+ ```bash
209
+ pymidi service log
210
+ ```
211
+
212
+ ---
213
+
214
+ ## ๐Ÿ“œ License
215
+
216
+ MIT ยฉ Alex Sandilands
@@ -0,0 +1 @@
1
+ __version__ = "0.1.0"
@@ -0,0 +1,55 @@
1
+ import requests
2
+ from pymidi_controller.config import ELGATO_LIGHT_IP
3
+
4
+ # -------------------------------------------------------------------
5
+ # ๐Ÿ’ก Elgato Ring Light Controls
6
+ # -------------------------------------------------------------------
7
+
8
+ def get_ring_info():
9
+ """
10
+ Fetch and display full status info for the Elgato Ring Light.
11
+ Includes power state, brightness, and temperature.
12
+ """
13
+ url = f"http://{ELGATO_LIGHT_IP}:9123/elgato/lights"
14
+ try:
15
+ response = requests.get(url, timeout=2)
16
+ response.raise_for_status()
17
+ data = response.json()
18
+ light = data["lights"][0]
19
+
20
+ print("Elgato Ring Light Info:")
21
+ print(f" Power: {'ON' if light['on'] else 'OFF'}")
22
+ print(f" Brightness: {light['brightness']}%")
23
+ print(f" Temperature: {light['temperature']}K")
24
+ return light
25
+
26
+ except Exception as e:
27
+ print(f"โŒ Failed to reach Elgato light at {ELGATO_LIGHT_IP}: {e}")
28
+
29
+
30
+ def get_light_state():
31
+ """
32
+ Return the current power state of the Elgato Ring Light (on/off).
33
+ """
34
+ url = f"http://{ELGATO_LIGHT_IP}:9123/elgato/lights"
35
+ response = requests.get(url).json()
36
+ light = response.get("lights", [{}])[0]
37
+ on = light.get("on", 0)
38
+ print(f"Elgato light is {'ON' if on else 'OFF'}")
39
+ return on
40
+
41
+
42
+ def toggle_light():
43
+ """
44
+ Toggle the Elgato Ring Light on/off based on current power state.
45
+ """
46
+ current = get_light_state()
47
+ new_state = 0 if current else 1
48
+
49
+ url = f"http://{ELGATO_LIGHT_IP}:9123/elgato/lights"
50
+ response = requests.put(url, json={
51
+ "lights": [{"on": new_state}]
52
+ })
53
+
54
+ print(f"Set Elgato light to {'ON' if new_state else 'OFF'}")
55
+ return response.status_code
@@ -0,0 +1,50 @@
1
+ from zeroconf import Zeroconf, ServiceBrowser, ServiceListener
2
+ from pymidi_controller.utils.config_manager import load_config, save_config
3
+ import time
4
+
5
+ # -------------------------------------------------------------------
6
+ # ๐Ÿ”Ž Elgato Device Discovery via mDNS
7
+ # -------------------------------------------------------------------
8
+
9
+ class ElgatoListener(ServiceListener):
10
+ """
11
+ Zeroconf listener that prints and optionally saves discovered Elgato devices.
12
+ """
13
+ def add_service(self, zeroconf, type_, name):
14
+ info = zeroconf.get_service_info(type_, name)
15
+ if info:
16
+ ip = ".".join(str(b) for b in info.addresses[0])
17
+ model = info.properties.get(b'md').decode("utf-8") if b'md' in info.properties else "Unknown"
18
+
19
+ print(f"Found Elgato Device: {model} @ {ip}")
20
+
21
+ save = input("๐Ÿ’พ Save this IP to config as elgato ip? [y/N] ").strip().lower()
22
+ if save == "y":
23
+ config = load_config()
24
+ config.setdefault("elgato", {})
25
+ config["elgato"]["ip"] = ip
26
+ save_config(config)
27
+ print(f"โœ… Saved elgato ip={ip} to config")
28
+ else:
29
+ print("โš ๏ธ Skipped saving IP to config")
30
+
31
+
32
+ def main(timeout=5):
33
+ """
34
+ Discover Elgato devices via Zeroconf (Bonjour/mDNS) and optionally save IP.
35
+ """
36
+ print("๐Ÿ” Searching for Elgato lights on the network...")
37
+
38
+ zeroconf = Zeroconf()
39
+ listener = ElgatoListener()
40
+
41
+ # Some devices use _elgato._tcp.local., others use _elg._tcp.local.
42
+ browser1 = ServiceBrowser(zeroconf, "_elgato._tcp.local.", listener)
43
+ browser2 = ServiceBrowser(zeroconf, "_elg._tcp.local.", listener)
44
+
45
+ time.sleep(timeout)
46
+ zeroconf.close()
47
+
48
+
49
+ if __name__ == "__main__":
50
+ main()