mirror of
https://github.com/meshcore-dev/meshcore_py.git
synced 2026-04-20 22:13:49 +00:00
auto channels support
This commit is contained in:
parent
7034e1da3b
commit
83a0e2938f
2 changed files with 6 additions and 2 deletions
|
|
@ -4,7 +4,7 @@ build-backend = "hatchling.build"
|
|||
|
||||
[project]
|
||||
name = "meshcore"
|
||||
version = "2.1.6"
|
||||
version = "2.1.7"
|
||||
authors = [
|
||||
{ name="Florent de Lamotte", email="florent@frizoncorrea.fr" },
|
||||
{ name="Alex Wolden", email="awolden@gmail.com" },
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
import logging
|
||||
from hashlib import sha256
|
||||
from typing import Optional
|
||||
|
||||
from ..events import Event, EventType
|
||||
|
|
@ -184,7 +185,7 @@ class DeviceCommands(CommandHandlerBase):
|
|||
return await self.send(data, [EventType.CHANNEL_INFO, EventType.ERROR])
|
||||
|
||||
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:
|
||||
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 = 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
|
||||
if len(channel_secret) != 16:
|
||||
raise ValueError("Channel secret must be exactly 16 bytes")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue