matter-web-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.
- matter_web_controller-0.1.0/LICENSE +21 -0
- matter_web_controller-0.1.0/PKG-INFO +47 -0
- matter_web_controller-0.1.0/README.md +32 -0
- matter_web_controller-0.1.0/cli/__init__.py +0 -0
- matter_web_controller-0.1.0/cli/server.py +92 -0
- matter_web_controller-0.1.0/matter_web_controller.egg-info/PKG-INFO +47 -0
- matter_web_controller-0.1.0/matter_web_controller.egg-info/SOURCES.txt +11 -0
- matter_web_controller-0.1.0/matter_web_controller.egg-info/dependency_links.txt +1 -0
- matter_web_controller-0.1.0/matter_web_controller.egg-info/entry_points.txt +2 -0
- matter_web_controller-0.1.0/matter_web_controller.egg-info/requires.txt +6 -0
- matter_web_controller-0.1.0/matter_web_controller.egg-info/top_level.txt +1 -0
- matter_web_controller-0.1.0/pyproject.toml +36 -0
- matter_web_controller-0.1.0/setup.cfg +4 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Nguyen Ha Dong
|
|
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 all
|
|
13
|
+
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 THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: matter-web-controller
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Using websocket matter server to query/control matter-enabled lights/sensors via a HTTP GET interface.
|
|
5
|
+
Requires-Python: >=3.12
|
|
6
|
+
Description-Content-Type: text/markdown
|
|
7
|
+
License-File: LICENSE
|
|
8
|
+
Requires-Dist: aiohttp
|
|
9
|
+
Requires-Dist: home-assistant-chip-core
|
|
10
|
+
Requires-Dist: home-assistant-chip-clusters
|
|
11
|
+
Requires-Dist: cryptography
|
|
12
|
+
Requires-Dist: python-matter-server
|
|
13
|
+
Requires-Dist: zeroconf
|
|
14
|
+
Dynamic: license-file
|
|
15
|
+
|
|
16
|
+
# Matter Web Controller
|
|
17
|
+
|
|
18
|
+
This document explains how the local Matter device management system works using a web interface.
|
|
19
|
+
|
|
20
|
+
## System Architecture
|
|
21
|
+
|
|
22
|
+
The system separates background tasks and simplifies network rules to make it easier to use:
|
|
23
|
+
|
|
24
|
+
1. **Background Process:** The app runs the standard `python-matter-server` as a separate background task. This keeps the heavy work away from the web server.
|
|
25
|
+
2. **WebSockets Connection:** The web server keeps a constant connection to the background task. This updates the network data in real time without slowing things down.
|
|
26
|
+
3. **HTTP Setup:** The web server acts as a middleman. It changes complex WebSocket data into a simple HTTP GET link. Users only need to visit a simple web address to get JSON data.
|
|
27
|
+
|
|
28
|
+
## Requirements
|
|
29
|
+
|
|
30
|
+
You need Python 3.10 or newer.
|
|
31
|
+
|
|
32
|
+
## Installation
|
|
33
|
+
|
|
34
|
+
Create a virtual environment and install the package using your package manager. This will automatically install required tools like `aiohttp` and `home-assistant-chip-core`.
|
|
35
|
+
|
|
36
|
+
## How to Run
|
|
37
|
+
|
|
38
|
+
Start the system by typing the executable command `matter-server-start`. You can use the `--port` parameter to set the web server port. The default is 8080. The background Matter server will automatically use the next port number.
|
|
39
|
+
|
|
40
|
+
## API Endpoints
|
|
41
|
+
|
|
42
|
+
### Get lighting device status
|
|
43
|
+
|
|
44
|
+
* **URL:** `/api/lights`
|
|
45
|
+
* **Method:** `GET`
|
|
46
|
+
* **Description:** Gets a list of all devices that have lighting features on the local Matter network. The data includes the Node ID, Endpoint ID, power state, and current brightness level.
|
|
47
|
+
* **Example:** `http://localhost:8080/api/lights`
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# Matter Web Controller
|
|
2
|
+
|
|
3
|
+
This document explains how the local Matter device management system works using a web interface.
|
|
4
|
+
|
|
5
|
+
## System Architecture
|
|
6
|
+
|
|
7
|
+
The system separates background tasks and simplifies network rules to make it easier to use:
|
|
8
|
+
|
|
9
|
+
1. **Background Process:** The app runs the standard `python-matter-server` as a separate background task. This keeps the heavy work away from the web server.
|
|
10
|
+
2. **WebSockets Connection:** The web server keeps a constant connection to the background task. This updates the network data in real time without slowing things down.
|
|
11
|
+
3. **HTTP Setup:** The web server acts as a middleman. It changes complex WebSocket data into a simple HTTP GET link. Users only need to visit a simple web address to get JSON data.
|
|
12
|
+
|
|
13
|
+
## Requirements
|
|
14
|
+
|
|
15
|
+
You need Python 3.10 or newer.
|
|
16
|
+
|
|
17
|
+
## Installation
|
|
18
|
+
|
|
19
|
+
Create a virtual environment and install the package using your package manager. This will automatically install required tools like `aiohttp` and `home-assistant-chip-core`.
|
|
20
|
+
|
|
21
|
+
## How to Run
|
|
22
|
+
|
|
23
|
+
Start the system by typing the executable command `matter-server-start`. You can use the `--port` parameter to set the web server port. The default is 8080. The background Matter server will automatically use the next port number.
|
|
24
|
+
|
|
25
|
+
## API Endpoints
|
|
26
|
+
|
|
27
|
+
### Get lighting device status
|
|
28
|
+
|
|
29
|
+
* **URL:** `/api/lights`
|
|
30
|
+
* **Method:** `GET`
|
|
31
|
+
* **Description:** Gets a list of all devices that have lighting features on the local Matter network. The data includes the Node ID, Endpoint ID, power state, and current brightness level.
|
|
32
|
+
* **Example:** `http://localhost:8080/api/lights`
|
|
File without changes
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import argparse
|
|
2
|
+
import asyncio
|
|
3
|
+
import logging
|
|
4
|
+
from aiohttp import web, ClientSession
|
|
5
|
+
from matter_server.client.client import MatterClient
|
|
6
|
+
|
|
7
|
+
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
|
|
8
|
+
|
|
9
|
+
global_session = None
|
|
10
|
+
global_client = None
|
|
11
|
+
global_matter_process = None
|
|
12
|
+
global_listen_task = None
|
|
13
|
+
|
|
14
|
+
MATTER_PORT = 5580
|
|
15
|
+
MATTER_SERVER_URL = ""
|
|
16
|
+
|
|
17
|
+
async def init_servers(app):
|
|
18
|
+
global global_session, global_client, global_matter_process, global_listen_task
|
|
19
|
+
|
|
20
|
+
logging.info(f"1. Launching internal Matter Server subprocess on port {MATTER_PORT}...")
|
|
21
|
+
global_matter_process = await asyncio.create_subprocess_exec(
|
|
22
|
+
"python3", "-m", "matter_server.server", "--storage-path", "./matter_storage", "--port", str(MATTER_PORT),
|
|
23
|
+
stdout=asyncio.subprocess.DEVNULL,
|
|
24
|
+
stderr=asyncio.subprocess.DEVNULL
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
await asyncio.sleep(4.0)
|
|
28
|
+
|
|
29
|
+
logging.info("2. Establishing client connection (ClientSession)...")
|
|
30
|
+
global_session = ClientSession()
|
|
31
|
+
global_client = MatterClient(MATTER_SERVER_URL, global_session)
|
|
32
|
+
|
|
33
|
+
logging.info("3. Activating background listening task...")
|
|
34
|
+
global_listen_task = asyncio.create_task(global_client.start_listening())
|
|
35
|
+
|
|
36
|
+
await asyncio.sleep(2.0)
|
|
37
|
+
logging.info("4. DONE: Web server is ready to accept HTTP requests!")
|
|
38
|
+
|
|
39
|
+
async def close_servers(app):
|
|
40
|
+
logging.info("Executing resource cleanup procedures...")
|
|
41
|
+
if global_listen_task:
|
|
42
|
+
global_listen_task.cancel()
|
|
43
|
+
if global_session:
|
|
44
|
+
await global_session.close()
|
|
45
|
+
if global_matter_process:
|
|
46
|
+
logging.info("Terminating internal Matter Server subprocess...")
|
|
47
|
+
global_matter_process.terminate()
|
|
48
|
+
await global_matter_process.wait()
|
|
49
|
+
|
|
50
|
+
async def serve_lighting_api(request):
|
|
51
|
+
logging.info("--- Received HTTP GET request at /api/lights ---")
|
|
52
|
+
if not global_client:
|
|
53
|
+
return web.json_response({"error": "Server not ready"}, status=503)
|
|
54
|
+
|
|
55
|
+
nodes = global_client.get_nodes()
|
|
56
|
+
logging.info(f"DONE: Retrieved data for {len(nodes)} network nodes.")
|
|
57
|
+
|
|
58
|
+
lighting_devices = []
|
|
59
|
+
for node in nodes:
|
|
60
|
+
for endpoint_id, endpoint in node.endpoints.items():
|
|
61
|
+
if 6 in endpoint.clusters:
|
|
62
|
+
power_state = node.get_attribute_value(endpoint_id, 6, 0)
|
|
63
|
+
brightness_level = node.get_attribute_value(endpoint_id, 8, 0) if 8 in endpoint.clusters else None
|
|
64
|
+
|
|
65
|
+
lighting_devices.append({
|
|
66
|
+
"id": f"Node {node.node_id} - EP {endpoint_id}",
|
|
67
|
+
"state": power_state,
|
|
68
|
+
"brightness": brightness_level
|
|
69
|
+
})
|
|
70
|
+
|
|
71
|
+
return web.json_response(lighting_devices)
|
|
72
|
+
|
|
73
|
+
def main():
|
|
74
|
+
parser = argparse.ArgumentParser(description="Matter API Web Server")
|
|
75
|
+
parser.add_argument("--port", type=int, default=8080, help="Web server port (Matter port will be port + 1)")
|
|
76
|
+
args = parser.parse_args()
|
|
77
|
+
|
|
78
|
+
web_port = args.port
|
|
79
|
+
global MATTER_PORT, MATTER_SERVER_URL
|
|
80
|
+
MATTER_PORT = web_port + 1
|
|
81
|
+
MATTER_SERVER_URL = f"ws://localhost:{MATTER_PORT}/ws"
|
|
82
|
+
|
|
83
|
+
app = web.Application()
|
|
84
|
+
app.on_startup.append(init_servers)
|
|
85
|
+
app.on_cleanup.append(close_servers)
|
|
86
|
+
app.router.add_get('/api/lights', serve_lighting_api)
|
|
87
|
+
|
|
88
|
+
logging.info(f"Bootstrapping Web server on port {web_port}, Matter server on port {MATTER_PORT}...")
|
|
89
|
+
web.run_app(app, host='0.0.0.0', port=web_port)
|
|
90
|
+
|
|
91
|
+
if __name__ == '__main__':
|
|
92
|
+
main()
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: matter-web-controller
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Using websocket matter server to query/control matter-enabled lights/sensors via a HTTP GET interface.
|
|
5
|
+
Requires-Python: >=3.12
|
|
6
|
+
Description-Content-Type: text/markdown
|
|
7
|
+
License-File: LICENSE
|
|
8
|
+
Requires-Dist: aiohttp
|
|
9
|
+
Requires-Dist: home-assistant-chip-core
|
|
10
|
+
Requires-Dist: home-assistant-chip-clusters
|
|
11
|
+
Requires-Dist: cryptography
|
|
12
|
+
Requires-Dist: python-matter-server
|
|
13
|
+
Requires-Dist: zeroconf
|
|
14
|
+
Dynamic: license-file
|
|
15
|
+
|
|
16
|
+
# Matter Web Controller
|
|
17
|
+
|
|
18
|
+
This document explains how the local Matter device management system works using a web interface.
|
|
19
|
+
|
|
20
|
+
## System Architecture
|
|
21
|
+
|
|
22
|
+
The system separates background tasks and simplifies network rules to make it easier to use:
|
|
23
|
+
|
|
24
|
+
1. **Background Process:** The app runs the standard `python-matter-server` as a separate background task. This keeps the heavy work away from the web server.
|
|
25
|
+
2. **WebSockets Connection:** The web server keeps a constant connection to the background task. This updates the network data in real time without slowing things down.
|
|
26
|
+
3. **HTTP Setup:** The web server acts as a middleman. It changes complex WebSocket data into a simple HTTP GET link. Users only need to visit a simple web address to get JSON data.
|
|
27
|
+
|
|
28
|
+
## Requirements
|
|
29
|
+
|
|
30
|
+
You need Python 3.10 or newer.
|
|
31
|
+
|
|
32
|
+
## Installation
|
|
33
|
+
|
|
34
|
+
Create a virtual environment and install the package using your package manager. This will automatically install required tools like `aiohttp` and `home-assistant-chip-core`.
|
|
35
|
+
|
|
36
|
+
## How to Run
|
|
37
|
+
|
|
38
|
+
Start the system by typing the executable command `matter-server-start`. You can use the `--port` parameter to set the web server port. The default is 8080. The background Matter server will automatically use the next port number.
|
|
39
|
+
|
|
40
|
+
## API Endpoints
|
|
41
|
+
|
|
42
|
+
### Get lighting device status
|
|
43
|
+
|
|
44
|
+
* **URL:** `/api/lights`
|
|
45
|
+
* **Method:** `GET`
|
|
46
|
+
* **Description:** Gets a list of all devices that have lighting features on the local Matter network. The data includes the Node ID, Endpoint ID, power state, and current brightness level.
|
|
47
|
+
* **Example:** `http://localhost:8080/api/lights`
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
pyproject.toml
|
|
4
|
+
cli/__init__.py
|
|
5
|
+
cli/server.py
|
|
6
|
+
matter_web_controller.egg-info/PKG-INFO
|
|
7
|
+
matter_web_controller.egg-info/SOURCES.txt
|
|
8
|
+
matter_web_controller.egg-info/dependency_links.txt
|
|
9
|
+
matter_web_controller.egg-info/entry_points.txt
|
|
10
|
+
matter_web_controller.egg-info/requires.txt
|
|
11
|
+
matter_web_controller.egg-info/top_level.txt
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
cli
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61.0"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "matter-web-controller"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Using websocket matter server to query/control matter-enabled lights/sensors via a HTTP GET interface."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.12"
|
|
11
|
+
dependencies = [
|
|
12
|
+
"aiohttp",
|
|
13
|
+
"home-assistant-chip-core",
|
|
14
|
+
"home-assistant-chip-clusters",
|
|
15
|
+
"cryptography",
|
|
16
|
+
"python-matter-server",
|
|
17
|
+
"zeroconf"
|
|
18
|
+
]
|
|
19
|
+
|
|
20
|
+
[project.scripts]
|
|
21
|
+
yeelight-srv = "cli.server:main"
|
|
22
|
+
|
|
23
|
+
[tool.isort]
|
|
24
|
+
profile = "black"
|
|
25
|
+
|
|
26
|
+
[tool.black]
|
|
27
|
+
line-length = 88
|
|
28
|
+
target-version = ["py312"]
|
|
29
|
+
|
|
30
|
+
[tool.ruff]
|
|
31
|
+
line-length = 88
|
|
32
|
+
target-version = "py312"
|
|
33
|
+
|
|
34
|
+
[tool.mypy]
|
|
35
|
+
python_version = "3.12"
|
|
36
|
+
strict = true
|