mirror of
https://github.com/meshcore-dev/meshcore_py.git
synced 2026-06-11 11:56:18 +00:00
auto channels support
This commit is contained in:
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
|
|||||||
|
|
||||||
[project]
|
[project]
|
||||||
name = "meshcore"
|
name = "meshcore"
|
||||||
version = "2.1.6"
|
version = "2.1.7"
|
||||||
authors = [
|
authors = [
|
||||||
{ name="Florent de Lamotte", email="florent@frizoncorrea.fr" },
|
{ name="Florent de Lamotte", email="florent@frizoncorrea.fr" },
|
||||||
{ name="Alex Wolden", email="awolden@gmail.com" },
|
{ name="Alex Wolden", email="awolden@gmail.com" },
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import logging
|
import logging
|
||||||
|
from hashlib import sha256
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
from ..events import Event, EventType
|
from ..events import Event, EventType
|
||||||
@@ -184,7 +185,7 @@ class DeviceCommands(CommandHandlerBase):
|
|||||||
return await self.send(data, [EventType.CHANNEL_INFO, EventType.ERROR])
|
return await self.send(data, [EventType.CHANNEL_INFO, EventType.ERROR])
|
||||||
|
|
||||||
async def set_channel(
|
async def set_channel(
|
||||||
self, channel_idx: int, channel_name: str, channel_secret: bytes
|
self, channel_idx: int, channel_name: str, channel_secret: bytes = None
|
||||||
) -> Event:
|
) -> Event:
|
||||||
logger.debug(f"Setting channel {channel_idx}: name={channel_name}")
|
logger.debug(f"Setting channel {channel_idx}: name={channel_name}")
|
||||||
|
|
||||||
@@ -192,6 +193,9 @@ class DeviceCommands(CommandHandlerBase):
|
|||||||
name_bytes = channel_name.encode("utf-8")[:32]
|
name_bytes = channel_name.encode("utf-8")[:32]
|
||||||
name_bytes = name_bytes.ljust(32, b"\x00")
|
name_bytes = name_bytes.ljust(32, b"\x00")
|
||||||
|
|
||||||
|
if channel_name.startswith("#") or channel_secret is None: # auto name => key calculated from hash
|
||||||
|
channel_secret = sha256(channel_name.encode("utf-8")).digest()[0:16]
|
||||||
|
|
||||||
# Ensure channel secret is exactly 16 bytes
|
# Ensure channel secret is exactly 16 bytes
|
||||||
if len(channel_secret) != 16:
|
if len(channel_secret) != 16:
|
||||||
raise ValueError("Channel secret must be exactly 16 bytes")
|
raise ValueError("Channel secret must be exactly 16 bytes")
|
||||||
|
|||||||
Reference in New Issue
Block a user