Skip to content

Commit

Permalink
Bugfix vmbdali (#115)
Browse files Browse the repository at this point in the history
* Add failing test for VMBDALI

* Fix VMBDALI

Fixes #114
  • Loading branch information
niobos authored Jul 22, 2024
1 parent c1c42fd commit d7e7b5f
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
31 changes: 31 additions & 0 deletions tests/vmbdali_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import pytest
from unittest.mock import MagicMock

from velbusaio.module import Module, VmbDali
from velbusaio.handler import PacketHandler
from velbusaio.helpers import h2


class MockWriter:
async def __call__(self, data):
pass


@pytest.mark.asyncio
async def test_vmbdali_loads_and_has_channels():
ph = PacketHandler(None)
await ph.read_protocol_data()

module_address = 0x12
dali_type = 69
module = VmbDali(
module_address,
dali_type,
ph.pdata["ModuleTypes"][h2(dali_type)],
)
writer = MockWriter()
module.initialize(writer)

await module.load()

assert len(module._channels) > 0
5 changes: 2 additions & 3 deletions velbusaio/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,7 @@ async def load(self, from_cache: bool = False) -> None:
except OSError:
cache = {}
# load default channels
await self.__load_default_channels()
await self._load_default_channels()

# load the data from memory ( the stuff that we need)
if "name" in cache and cache["name"] != "":
Expand Down Expand Up @@ -722,7 +722,7 @@ async def __load_memory(self) -> None:
msg.low_address = addr[1]
await self._writer(msg)

async def __load_default_channels(self) -> None:
async def _load_default_channels(self) -> None:
if "Channels" not in self._data:
return

Expand Down Expand Up @@ -771,7 +771,6 @@ def __init__(
self.group_members: dict[int, set[int]] = {}

async def _load_default_channels(self) -> None:
await super().load()
for chan in range(1, 64 + 1):
self._channels[chan] = Channel(
self, chan, "placeholder", True, self._writer, self._address
Expand Down

0 comments on commit d7e7b5f

Please sign in to comment.