Debian Codegraph @

README.md

raw
1 # Govee Local API
2
3 [![Upload Python Package](https://github.com/Galorhallen/govee-local-api/actions/workflows/deploy.yml/badge.svg?event=release)](https://github.com/Galorhallen/govee-local-api/actions/workflows/deploy.yml)
4
5 Please note that scene and segment support is still **very** experimental.
6
7 See [SUPPORTED_DEVICES.md](SUPPORTED_DEVICES.md) for the full list of known device models and their capabilities.
8
9 # Requirements
10
11 - Python >= 3.11
12 - Govee Local API enabled. Refer to https://app-h5.govee.com/user-manual/wlan-guide
13
14 # Installation
15
16 From your terminal, run
17
18 pip install govee-local-api
19
20 or
21
22 python3 -m pip install govee-local-api
23
24 # Usage
25
26 ## Basic Usage
27
28 ```python
29 import asyncio
30 from govee_local_api import GoveeController
31
32 async def main():
33 # Simple single-interface setup
34 controller = GoveeController()
35
36 # Discover devices
37 devices = await controller.scan_devices()
38
39 # Control a device
40 if devices:
41 device = devices[0]
42 await device.turn_on()
43 await device.set_brightness(80)
44 await device.set_color(255, 0, 0) # Red
45
46 asyncio.run(main())
47 ```
48
49 ## Multi-Interface Setup
50
51 For complex network environments with multiple interfaces:
52
53 ```python
54 # Multiple listening addresses (basic)
55 controller = GoveeController(
56 listening_addresses=["192.168.1.100", "10.0.0.100", "172.16.1.100"]
57 )
58 ```
59
60 ### Tolerating a failed bind (`require_all=False`)
61
62 By default `start()` requires every configured address to bind; a single failure
63 (`EADDRNOTAVAIL` for a stale address, `EADDRINUSE`, an interface that went down)
64 closes any endpoint already opened and re-raises, so the controller is left unbound.
65
66 Since 3.1.0 you can opt in to keeping whatever binds successfully:
67
68 ```python
69 controller = GoveeController(
70 listening_addresses=["192.168.1.100/24", "10.0.0.100/8", "172.16.1.100/16"]
71 )
72 await controller.start(require_all=False)
73
74 for address, error in controller.bind_failures:
75 logging.warning("Not listening on %s: %s", address, error)
76 print("Live on", controller.listening_addresses)
77 ```
78
79 - `start()` raises only if **no** address binds. The raised exception is the original
80 `OSError` (errno preserved; an `EADDRINUSE` is preferred when several differ), never a
81 wrapper type, so `errno`-based handling keeps working.
82 - `bind_failures` lists `(address, OSError)` pairs for the most recent `start()` only and is
83 reset on every call. Partial success is also logged at `warning` level.
84 - The configured address set is never pruned: a later `start()` retries every address, so a
85 caller can recover an adapter that has come back by simply calling `start()` again.
86
87 ## Network Mask Configuration
88
89 For precise subnet-aware device routing (recommended for enterprise/VLAN environments), embed the network mask directly in the address using CIDR or netmask notation:
90
91 ```python
92 # Precise subnet matching with embedded network masks
93 controller = GoveeController(
94 listening_addresses=[
95 "192.168.1.100/24", # Main LAN (CIDR)
96 "192.168.10.100/255.255.255.0", # IoT VLAN (dotted netmask)
97 "10.0.0.100/8" # Management network
98 ]
99 )
100 ```
101
102 ### Supported Network Mask Formats
103
104 - **CIDR Notation**: `192.168.1.100/24`, `10.0.0.100/8`, etc.
105 - **Dotted Decimal**: `192.168.1.100/255.255.255.0`, etc.
106 - **No mask**: `192.168.1.100` (uses heuristic subnet matching)
107 - **Wildcard**: `0.0.0.0` (listens on all interfaces, no subnet matching)
108
109 ## Advanced Features
110
111 ### Device Discovery and Control
112
113 ```python
114 async def discover_and_control():
115 controller = GoveeController(
116 listening_addresses=["192.168.1.100/24", "192.168.10.100/24"]
117 )
118
119 # Scan for devices across all networks
120 devices = await controller.scan_devices()
121
122 # Filter devices by network
123 main_lan_devices = [d for d in devices if d.ip.startswith("192.168.1.")]
124 iot_vlan_devices = [d for d in devices if d.ip.startswith("192.168.10.")]
125
126 # Control devices on specific networks
127 for device in main_lan_devices:
128 await device.turn_on()
129 await device.set_brightness(50)
130
131 for device in iot_vlan_devices:
132 await device.turn_off()
133 ```
134
135 ### Direct Device Control
136
137 ```python
138 # Control device by IP address (uses intelligent transport selection)
139 await controller.control_device("192.168.1.100", turn_on=True)
140 await controller.control_device("192.168.1.100", brightness=75)
141 await controller.control_device("192.168.1.100", color_rgb=(0, 255, 0))
142 ```
143
144 ## Documentation
145
146 - **[Supported Devices](SUPPORTED_DEVICES.md)** - Auto-generated list of known device models and their capabilities
147 - **[Network Mask Configuration Guide](NETWORK_MASKS.md)** - Comprehensive guide for multi-network setups
148 - **[API Reference](https://github.com/Galorhallen/govee-local-api)** - Full API documentation
149
150 ## Use Cases
151
152 - **Home Networks**: Simple single-interface setup
153 - **Small Office**: Multi-interface with heuristic matching
154 - **Enterprise/VLAN**: Network mask configuration for precise routing
155 - **IoT Deployments**: Isolated network segments with dedicated interfaces
156 - **Multi-Building**: Physically separated networks with same IP ranges