Skip to content

Commit

Permalink
Merge branch 'master' into pr95
Browse files Browse the repository at this point in the history
  • Loading branch information
cereal2nd committed Apr 1, 2024
2 parents e597d85 + 53db453 commit 09be59e
Show file tree
Hide file tree
Showing 24 changed files with 10,242 additions and 126 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
with:
submodules: recursive
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- uses: pre-commit/[email protected]
Expand Down
4 changes: 0 additions & 4 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,4 +0,0 @@
[submodule "velbusaio/moduleprotocol"]
path = velbusaio/moduleprotocol
url = https://github.com/StefCoene/moduleprotocol.git
branch = master
2 changes: 1 addition & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ include LICENSE
include README.md
include requirements.txt
include velbusaio/py.typed
include velbusaio/moduleprotocol/protocol.json
include velbusaio/protocol.json
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
![CI](https://github.com/Cereal2nd/velbus-aio/actions/workflows/main.yml/badge.svg)
[![pre-commit.ci status](https://results.pre-commit.ci/badge/github/Cereal2nd/velbus-aio/master.svg)](https://results.pre-commit.ci/latest/github/Cereal2nd/velbus-aio/master)

# velbus-aio

Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ requires = ["setuptools", "wheel"]
[project]
name = "velbus-aio"
license = {text = "MIT"}
version = "2023.12.0"
version = "2024.4.0"
description = "Open-source home automation platform running on Python 3."
readme = "README.md"
authors = [
Expand Down Expand Up @@ -51,7 +51,7 @@ exclude_dirs = ["tests"]
skips = ["B301", "B403", "B323", "B104", "B110"]

[tool.bumpver]
current_version = "2023.12.0"
current_version = "2024.4.0"
version_pattern = "YYYY.MM.INC0"
commit_message = "bump version {old_version} -> {new_version}"
commit = true
Expand Down
2 changes: 2 additions & 0 deletions velbusaio/command_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
0x01: "VMB8PB",
0x02: "VMB1RY",
0x03: "VMB1BL",
0x04: "VMB4LEDPWM-20",
0x05: "VMB6IN",
0x07: "VMB1DM",
0x08: "VMB4RY",
Expand Down Expand Up @@ -69,6 +70,7 @@
0x48: "VMB4RYLD-10",
0x49: "VMB4RYNO-10",
0x4A: "VMB2BLE-10",
0x4B: "VMB8DC-20",
0x4C: "VMB6PB-20",
0x4F: "VMBEL1-20",
0x50: "VMBEL2-20",
Expand Down
113 changes: 29 additions & 84 deletions velbusaio/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import logging
import re
from typing import TYPE_CHECKING, Awaitable, Callable

import pkg_resources

from velbusaio.command_registry import commandRegistry
Expand All @@ -37,32 +36,32 @@ def __init__(
self._log = logging.getLogger("velbus-packet")
self._writer = writer
self._velbus = velbus
self._active_modulescan_address = 0 #lgor
self._moduletyperesponsemsg = None #lgor received type response message
self._active_modulescan_address = 0 # lgor
self._moduletyperesponsemsg = None # lgor received type response message
self.scan_complete = False
# lgor self._scan_complete_event = asyncio.Event()
with open(
pkg_resources.resource_filename(__name__, "moduleprotocol/protocol.json")
pkg_resources.resource_filename(__name__, "protocol.json")
) as protocol_file:
self.pdata = json.load(protocol_file)

#lgor added for initiating single module type scan
def set_module_type_request(self, address : byte) -> None: #lgor
_moduletyperesponsemsg = None #lgor
self._active_modulescan_address = address #lgor
# lgor added for initiating single module type scan
def set_module_type_request(self, address: int) -> None: # lgor
self._moduletyperesponsemsg = None # lgor
self._active_modulescan_address = address # lgor

#lgor added for test received module type message
def is_module_typerespons_ok(self) -> bool: #lgor
return is self._moduletyperesponsemsg not None #lgor
# lgor added for test received module type message
def is_module_typerespons_ok(self) -> bool: # lgor
return self._moduletyperesponsemsg is not None # lgor

#lgor removed: no global scan start / completion required
#def scan_finished(self) -> None:
# lgor removed: no global scan start / completion required
# def scan_finished(self) -> None:
# self._scan_complete = True
# self._scan_complete_event.set()
# self._log.debug("Scan complete")

#lgor removed: no global scan start / completion required
#def scan_started(self) -> None:
# lgor removed: no global scan start / completion required
# def scan_started(self) -> None:
# self._scan_complete = False
# self._scan_complete_event.clear()

Expand All @@ -81,12 +80,16 @@ async def handle(self, rawmsg: RawMessage) -> None:
command_value = rawmsg.command
data = rawmsg.data_only

#lgor handle config related messages
if command_value in (0xxFF, 0xB0, 0xA7, 0xA6): #lgor
if active_modulescan_address == address: #lgor only respond to requested module (VelbusLink might interfere otherwise)
if command_value == 0xFF: #lgor type response message
_moduletyperesponsemsg = ModuleTypeMessage() #lgor
_moduletyperesponsemsg.populate(priority, address, rtr, data) #lgor
# lgor handle config related messages
if command_value in (0xFF, 0xB0, 0xA7, 0xA6): # lgor
if (
self.active_modulescan_address == address
): # lgor only respond to requested module (VelbusLink might interfere otherwise)
if command_value == 0xFF: # lgor type response message
self._moduletyperesponsemsg = ModuleTypeMessage() # lgor
self._moduletyperesponsemsg.populate(
priority, address, rtr, data
) # lgor
else:
msg = ModuleSubTypeMessage()
msg.populate(priority, address, rtr, data)
Expand All @@ -99,7 +102,7 @@ async def handle(self, rawmsg: RawMessage) -> None:
msg.sub_address_offset = 8
else:
raise RuntimeError("Unreachable code reached => bug here")

self._log.debug(f"Received {msg}")
await self._handle_module_subtype(msg)
elif command_value in self.pdata["MessagesBroadCast"]:
Expand Down Expand Up @@ -133,70 +136,12 @@ async def handle(self, rawmsg: RawMessage) -> None:
)
)

# def _handle_message(self, rawMsg: RawMessage) -> None:
# module_type = self._velbus.get_module(rawMsg.address).get_type()
# this_msg = keys_exists(
# self.pdata, "ModuleTypes", h2(module_type), "Messages", h2(rawMsg.command), "Data"
# )
# if this_msg and "PerByte" in this_msg:
# self._per_byte(this_msg["PerByte"], rawMsg)

# def _per_byte(self, cmsg, rawMsg: RawMessage) -> dict:
# result = {}
# byte_index = 0
# for byte in rawMsg.data:
# num = str(byte_index)
# # only do something if its defined
# if num not in cmsg:
# continue
# # check if we can do a binary match
# for mat in cmsg[num]["Match"]:
# if (
# (mat.startswith("%") and re.match(mat[1:], f"{byte:08b}"))
# or mat == f"{byte:08b}"
# or mat == f"{byte:02x}"
# ):
# result = self._per_byte_handle(
# result, cmsg[num]["Match"][mat], byte
# )
# byte_index += 1
# return result

# def _per_byte_handle(self, result: dict, todo: dict, byte: int) -> dict:
# if "Channel" in todo:
# result["Channel"] = todo["Channel"]
# if "Value" in todo:
# result["Value"] = todo["Value"]
# if "Convert" in todo:
# result["ValueList"] = []
# if todo["Convert"] == "Decimal":
# result["ValueList"].append(int(byte))
# elif todo["Convert"] == "Counter":
# result["ValueList"].append(f"{byte:02x}")
# elif todo["Convert"] == "Temperature":
# print("CONVERT temperature")
# elif todo["Convert"] == "Divider":
# bin_str = f"{byte:08b}"
# chan = bin_str[6:]
# val = bin_str[:5]
# print(f"CONVERT Divider {chan} {val}")
# elif todo["Convert"] == "Channel":
# print("CONVERT Channel")
# elif todo["Convert"] == "ChannelBit":
# print("CONVERT ChannelBit")
# elif todo["Convert"].startswith("ChannelBitStatus"):
# print("CONVERT ChannelBitStatus")
# else:
# self._log.error("UNKNOWN convert requested: {}".format(todo["Convert"]))
# return result

#lgor: _ removed from name (function is not local anymore)
async def handle_module_type(self) -> None: #lgor (signature changed)
async def _handle_module_type(self, msg: Message) -> None:
"""
load the module data
"""
msg = _moduletyperesponsemsg #lgor
if msg is not None : #lgor
msg = self._moduletyperesponsemsg # lgor
if msg is not None: # lgor
data = keys_exists(self.pdata, "ModuleTypes", h2(msg.module_type))
if not data:
self._log.warning(f"Module not recognized: {msg.module_type}")
Expand All @@ -210,7 +155,7 @@ async def handle_module_type(self) -> None: #lgor (signature changed)
build_year=msg.build_year,
build_week=msg.build_week,
serial=msg.serial,
)
)

async def _handle_module_subtype(self, msg: Message) -> None:
if msg.address not in self._velbus.get_modules():
Expand Down
13 changes: 13 additions & 0 deletions velbusaio/messages/channel_name_part1.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,19 @@ def data_to_binary(self):
"VMBDALI",
"VMB4AN",
"VMB6PB-20",
"VMBEL1-20",
"VMBEL2-20",
"VMBEL4-20",
"VMBELO-20",
"VMBGP1-20",
"VMBGP2-20",
"VMBGP4-20",
"VMBGPO-20",
"VMBDALI-20",
"VMBEL4PIR-20",
"VMBGP4PIR-20",
"VMB4LEDPWM-20",
"VMB8DC-20",
],
)
class ChannelNamePart1Message2(ChannelNamePart1Message):
Expand Down
12 changes: 12 additions & 0 deletions velbusaio/messages/channel_name_part2.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,18 @@ def data_to_binary(self):
"VMBDALI",
"VMB4AN",
"VMB6PB-20",
"VMBEL1-20",
"VMBEL2-20",
"VMBEL4-20",
"VMBELO-20",
"VMBGP1-20",
"VMBGP2-20",
"VMBGP4-20",
"VMBGPO-20",
"VMBDALI-20",
"VMBEL4PIR-20",
"VMBGP4PIR-20",
"VMB8DC-20",
],
)
class ChannelNamePart2Message2(ChannelNamePart2Message):
Expand Down
12 changes: 12 additions & 0 deletions velbusaio/messages/channel_name_part3.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,18 @@ def data_to_binary(self):
"VMBDALI",
"VMB4AN",
"VMB6PB-20",
"VMBEL1-20",
"VMBEL2-20",
"VMBEL4-20",
"VMBELO-20",
"VMBGP1-20",
"VMBGP2-20",
"VMBGP4-20",
"VMBGPO-20",
"VMBDALI-20",
"VMBEL4PIR-20",
"VMBGP4PIR-20",
"VMB8DC-20",
],
)
class ChannelNamePart3Message2(ChannelNamePart3Message):
Expand Down
2 changes: 1 addition & 1 deletion velbusaio/messages/channel_name_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def data_to_binary(self):
return bytes([COMMAND_CODE, tmp])


@register(COMMAND_CODE, ["VMBDALI"])
@register(COMMAND_CODE, ["VMBDALI", "VMBDALI-20"])
class ChannelNameRequestMessage3(ChannelNameRequestMessage):
"""
send by:
Expand Down
2 changes: 1 addition & 1 deletion velbusaio/messages/dali_device_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
COMMAND_CODE = 0xE8


@register(COMMAND_CODE, ["VMBDALI"])
@register(COMMAND_CODE, ["VMBDALI", "VMBDALI-20"])
class DaliDeviceSettingMsg(Message):
"""
send by: VMBDALI
Expand Down
2 changes: 1 addition & 1 deletion velbusaio/messages/dali_device_settings_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class DataSource(enum.Enum):
FromDaliDevice = 1


@register(COMMAND_CODE, ["VMBDALI"])
@register(COMMAND_CODE, ["VMBDALI", "VMBDALI-20"])
class DaliDeviceSettingsRequest(Message):
"""
send by:
Expand Down
2 changes: 1 addition & 1 deletion velbusaio/messages/dali_dim_value_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
COMMAND_CODE = 0xA5


@register(COMMAND_CODE, ["VMBDALI"])
@register(COMMAND_CODE, ["VMBDALI", "VMBDALI-20"])
class DimValueStatus(Message):
"""
send by: VMBDALI
Expand Down
2 changes: 1 addition & 1 deletion velbusaio/messages/dimmer_channel_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
LED_VERY_FAST_BLINKING = 1 << 4


@register(COMMAND_CODE, ["VMB4DC", "VMBDMI", "VMBDMI-R"])
@register(COMMAND_CODE, ["VMB4DC", "VMBDMI", "VMBDMI-R", "VMB8DC-20"])
class DimmerChannelStatusMessage(Message):
"""
sent by: VMB4DC
Expand Down
11 changes: 11 additions & 0 deletions velbusaio/messages/module_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,17 @@ def data_to_binary(self):
"VMBGPOD-2",
"VMBELO",
"VMB7IN",
"VMB6PB-20",
"VMBEL1-20",
"VMBEL2-20",
"VMBEL4-20",
"VMBELO-20",
"VMBGP1-20",
"VMBGP2-20",
"VMBGP4-20",
"VMBGPO-20",
"VMBEL4PIR-20",
"VMBGP4PIR-20",
],
)
class ModuleStatusMessage2(Message):
Expand Down
7 changes: 5 additions & 2 deletions velbusaio/messages/restore_dimmer.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@
COMMAND_CODE = 0x11


@register(COMMAND_CODE, ["VMB1DM", "VMBDME", "VMBDMI-R", "VMBDMI", "VMB1LED", "VMB4DC"])
@register(
COMMAND_CODE,
["VMB1DM", "VMBDME", "VMBDMI-R", "VMBDMI", "VMB1LED", "VMB4DC", "VMB8DC-20"],
)
class RestoreDimmerMessage(Message):
"""
send by:
Expand Down Expand Up @@ -54,7 +57,7 @@ def data_to_binary(self):
) + self.dimmer_transitiontime.to_bytes(2, byteorder="big", signed=False)


@register(COMMAND_CODE, ["VMBDALI"])
@register(COMMAND_CODE, ["VMBDALI", "VMBDALI-20"])
class RestoreDimmerMessage2(RestoreDimmerMessage):
def byte_to_channels(self, byte: int) -> list[int]:
return [byte]
Expand Down
7 changes: 5 additions & 2 deletions velbusaio/messages/set_dimmer.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@
COMMAND_CODE = 0x07


@register(COMMAND_CODE, ["VMB1DM", "VMBDME", "VMB4DC", "VMBDMI", "VMBDMI-R", "VMB1LED"])
@register(
COMMAND_CODE,
["VMB1DM", "VMBDME", "VMB4DC", "VMBDMI", "VMBDMI-R", "VMB1LED", "VMB8DC-20"],
)
class SetDimmerMessage(Message):
"""
send by:
Expand Down Expand Up @@ -57,7 +60,7 @@ def data_to_binary(self):
) + self.dimmer_transitiontime.to_bytes(2, byteorder="big", signed=False)


@register(COMMAND_CODE, ["VMBDALI"])
@register(COMMAND_CODE, ["VMBDALI", "VMBDALI-20"])
class SetDimmerMessage2(SetDimmerMessage):
"""
send by:
Expand Down
Loading

0 comments on commit 09be59e

Please sign in to comment.