Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Split modulespec #122

Merged
merged 7 commits into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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/protocol.json
include velbusaio/module_spec/*
11 changes: 6 additions & 5 deletions velbusaio/command_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
0x01: "VMB8PB",
0x02: "VMB1RY",
0x03: "VMB1BL",
0x04: "VMB4LEDPWM-20",
0x05: "VMB6IN",
0x06: "VMB4LEDPWM-20",
0x07: "VMB1DM",
0x08: "VMB4RY",
0x09: "VMB2BL",
Expand Down Expand Up @@ -73,14 +73,15 @@
0x4A: "VMB2BLE-10",
0x4B: "VMB8DC-20",
0x4C: "VMB6PB-20",
0x4D: "VMBPIR-20",
0x4F: "VMBEL1-20",
0x50: "VMBEL2-20",
0x51: "VMBEL4-20",
0x52: "VMBELO-20",
0x53: "VMBGP1-20",
0x54: "VMBGP2-20",
0x55: "VMBGP4-20",
0x56: "VMBGPO-20",
0x54: "VMBGP1-20",
0x55: "VMBGP2-20",
0x56: "VMBGP4-20",
0x57: "VMBGPO-20",
0x5A: "VMBDALI-20",
0x5C: "VMBEL4PIR-20",
0x5F: "VMBGP4PIR-20",
Expand Down
2 changes: 0 additions & 2 deletions velbusaio/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ def add_module(
self,
addr: int,
typ: int,
data: dict,
serial: int | None = None,
memorymap: int | None = None,
build_year: int | None = None,
Expand All @@ -81,7 +80,6 @@ def add_module(
module = Module.factory(
addr,
typ,
data,
serial=serial,
build_year=build_year,
build_week=build_week,
Expand Down
11 changes: 5 additions & 6 deletions velbusaio/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ def __init__(

async def read_protocol_data(self):
async with async_open(
pkg_resources.resource_filename(__name__, "protocol.json")
pkg_resources.resource_filename(__name__, "module_spec/broadcast.json")
) as protocol_file:
self.pdata = json.loads(await protocol_file.read())
self.broadcast = json.loads(await protocol_file.read())

def empty_cache(self) -> bool:
if (
Expand Down Expand Up @@ -186,10 +186,10 @@ async def handle(self, rawmsg: RawMessage) -> None:
self._handle_module_subtype(msg)

# ignore broadcast
elif command_value in self.pdata["MessagesBroadCast"]:
elif command_value in self.broadcast:
self._log.debug(
"Received broadcast message {} from {}, ignoring".format(
self.pdata["MessageBroadCast"][str(command_value).upper()], address
self.broadcast[str(command_value).upper()], address
)
)

Expand Down Expand Up @@ -229,14 +229,13 @@ def _handle_module_type(self, msg: ModuleTypeMessage | ModuleType2Message) -> No
if msg is not None:
module = self._velbus.get_module(msg.address)
if module is None:
data = keys_exists(self.pdata, "ModuleTypes", h2(msg.module_type))
# data = keys_exists(self.pdata, "ModuleTypes", h2(msg.module_type))
if not data:
self._log.warning(f"Module not recognized: {msg.module_type}")
return
self._velbus.add_module(
msg.address,
msg.module_type,
data,
memorymap=msg.memory_map_version,
build_year=msg.build_year,
build_week=msg.build_week,
Expand Down
15 changes: 8 additions & 7 deletions velbusaio/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ def factory(
cls,
module_address: int,
module_type: int,
module_data: dict,
serial: int | None = None,
memorymap: int | None = None,
build_year: int | None = None,
Expand All @@ -116,7 +115,6 @@ def factory(
return VmbDali(
module_address,
module_type,
module_data,
serial,
memorymap,
build_year,
Expand All @@ -127,7 +125,6 @@ def factory(
return Module(
module_address,
module_type,
module_data,
serial,
memorymap,
build_year,
Expand All @@ -139,7 +136,6 @@ def __init__(
self,
module_address: int,
module_type: int,
module_data: dict,
serial: int | None = None,
memorymap: int | None = None,
build_year: int | None = None,
Expand All @@ -148,7 +144,7 @@ def __init__(
) -> None:
self._address = module_address
self._type = module_type
self._data = module_data
self._data = {}

self._name = {}
self._sub_address = {}
Expand All @@ -163,6 +159,13 @@ def __init__(

def initialize(self, writer: Callable[[Message], Awaitable[None]]) -> None:
self._log = logging.getLogger("velbus-module")
# laod the protocol data
async with async_open(
pkg_resources.resource_filename(__name__, f"module_spec/{self._type}.json")
) as protocol_file:
self._data = json.loads(await protocol_file.read())

# set some params from the velbus controller
self._writer = writer
for chan in self._channels.values():
chan._writer = writer
Expand Down Expand Up @@ -754,7 +757,6 @@ def __init__(
self,
module_address: int,
module_type: int,
module_data: dict,
serial: int | None = None,
memorymap: int | None = None,
build_year: int | None = None,
Expand All @@ -764,7 +766,6 @@ def __init__(
super().__init__(
module_address,
module_type,
module_data,
serial,
memorymap,
build_year,
Expand Down
11 changes: 11 additions & 0 deletions velbusaio/module_spec/02.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"Channels": {
"01": {
"Editable": "yes",
"Name": "Relay",
"Type": "Relay"
}
},
"Info": "Relay Module",
"Type": "VMB1RY"
}
18 changes: 18 additions & 0 deletions velbusaio/module_spec/03.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"ChannelNumbers": {
"Name": {
"Map": {
"03": "01"
}
}
},
"Channels": {
"01": {
"Editable": "yes",
"Name": "Blind",
"Type": "Blind"
}
},
"Info": "Blind Control Module",
"Type": "VMB1BL"
}
36 changes: 36 additions & 0 deletions velbusaio/module_spec/05.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"Channels": {
"01": {
"Editable": "yes",
"Name": "Push button 1",
"Type": "Button"
},
"02": {
"Editable": "yes",
"Name": "Push button 2",
"Type": "Button"
},
"03": {
"Editable": "yes",
"Name": "Push button 3",
"Type": "Button"
},
"04": {
"Editable": "yes",
"Name": "Push button 4",
"Type": "Button"
},
"05": {
"Editable": "yes",
"Name": "Push button 5",
"Type": "Button"
},
"06": {
"Editable": "yes",
"Name": "Push button 6",
"Type": "Button"
}
},
"Info": "6-Channel Input Module",
"Type": "VMB6IN"
}
101 changes: 101 additions & 0 deletions velbusaio/module_spec/06.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
{
"Channels": {
"01": {
"Editable": "yes",
"Name": "Dimmer 1",
"Type": "Dimmer"
},
"02": {
"Editable": "yes",
"Name": "Dimmer 2",
"Type": "Dimmer"
},
"03": {
"Editable": "yes",
"Name": "Dimmer 3",
"Type": "Dimmer"
},
"04": {
"Editable": "yes",
"Name": "Dimmer 4",
"Type": "Dimmer"
},
"96": {
"Name": "SelectedProgram",
"Type": "SelectedProgram"
}
},
"Memory": {
"Address": {
"062C": { "ModuleName": "0:Start" },
"062D": { "ModuleName": "1" },
"062E": { "ModuleName": "2" },
"062F": { "ModuleName": "3" },
"0630": { "ModuleName": "4" },
"0631": { "ModuleName": "5" },
"0632": { "ModuleName": "6" },
"0633": { "ModuleName": "7" },
"0634": { "ModuleName": "8" },
"0635": { "ModuleName": "9" },
"0636": { "ModuleName": "10" },
"0637": { "ModuleName": "11" },
"0638": { "ModuleName": "12" },
"0639": { "ModuleName": "13" },
"063A": { "ModuleName": "14" },
"063B": { "ModuleName": "15" },
"063C": { "ModuleName": "16" },
"063D": { "ModuleName": "17" },
"063E": { "ModuleName": "18" },
"063F": { "ModuleName": "19" },
"0640": { "ModuleName": "20" },
"0641": { "ModuleName": "21" },
"0642": { "ModuleName": "22" },
"0643": { "ModuleName": "23" },
"0644": { "ModuleName": "24" },
"0645": { "ModuleName": "25" },
"0646": { "ModuleName": "26" },
"0647": { "ModuleName": "27" },
"0648": { "ModuleName": "28" },
"0649": { "ModuleName": "29" },
"064A": { "ModuleName": "30" },
"064B": { "ModuleName": "31" },
"064C": { "ModuleName": "32" },
"064D": { "ModuleName": "33" },
"064E": { "ModuleName": "34" },
"064F": { "ModuleName": "35" },
"0650": { "ModuleName": "36" },
"0651": { "ModuleName": "37" },
"0652": { "ModuleName": "38" },
"0653": { "ModuleName": "39" },
"0654": { "ModuleName": "40" },
"0655": { "ModuleName": "41" },
"0656": { "ModuleName": "42" },
"0657": { "ModuleName": "43" },
"0658": { "ModuleName": "44" },
"0659": { "ModuleName": "45" },
"065A": { "ModuleName": "46" },
"065B": { "ModuleName": "47" },
"065C": { "ModuleName": "48" },
"065D": { "ModuleName": "49" },
"065E": { "ModuleName": "50" },
"065F": { "ModuleName": "51" },
"0660": { "ModuleName": "52" },
"0661": { "ModuleName": "53" },
"0662": { "ModuleName": "54" },
"0663": { "ModuleName": "55" },
"0664": { "ModuleName": "55" },
"0665": { "ModuleName": "56" },
"0666": { "ModuleName": "57" },
"0667": { "ModuleName": "58" },
"0668": { "ModuleName": "59" },
"0669": { "ModuleName": "60" },
"066A": { "ModuleName": "61" },
"066B": { "ModuleName": "62" },
"066C": { "ModuleName": "63" },
"066D": { "ModuleName": "64:save" }
},
"ModuleName": "062C-32;064D-32"
},
"Info": "4 channel led PWM dimmer module",
"Type": "VMB4LEDPWM-20"
}
11 changes: 11 additions & 0 deletions velbusaio/module_spec/07.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"Channels": {
"01": {
"Editable": "yes",
"Name": "Dimmer",
"Type": "Dimmer"
}
},
"Info": "Dimmer module",
"Type": "VMB1DM"
}
26 changes: 26 additions & 0 deletions velbusaio/module_spec/08.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"Channels": {
"01": {
"Editable": "yes",
"Name": "Relay 1",
"Type": "Relay"
},
"02": {
"Editable": "yes",
"Name": "Relay 2",
"Type": "Relay"
},
"03": {
"Editable": "yes",
"Name": "Relay 3",
"Type": "Relay"
},
"04": {
"Editable": "yes",
"Name": "Relay 4",
"Type": "Relay"
}
},
"Info": "4 channel relay module",
"Type": "VMB4RY"
}
24 changes: 24 additions & 0 deletions velbusaio/module_spec/09.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"ChannelNumbers": {
"Name": {
"Map": {
"03": "01",
"0C": "02"
}
}
},
"Channels": {
"01": {
"Editable": "yes",
"Name": "Blind 1",
"Type": "Blind"
},
"02": {
"Editable": "yes",
"Name": "Blind 2",
"Type": "Blind"
}
},
"Info": "2-channel Blind Control Module",
"Type": "VMB2BL"
}
Loading
Loading