Skip to content
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
3 changes: 2 additions & 1 deletion src/dzcb/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,8 @@ def short_name(self):

@property
def transmit_frequency(self):
return round_frequency(self.frequency + self.offset)
offset = self.offset if self.offset else 0
return round_frequency(self.frequency + offset)


def _tone_validator(instance, attribute, value):
Expand Down
23 changes: 12 additions & 11 deletions src/dzcb/output/dmrconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,8 @@ class CodeplugIndexLookup:

@contact.default
def _contact(self):
return items_by_index(self.codeplug.contacts, offset=self.offset)
# contact index keys on contact name
return items_by_index(self.codeplug.contacts, key=lambda ct: ct.name, offset=self.offset)

@grouplist_id.default
def _grouplist_id(self):
Expand Down Expand Up @@ -540,10 +541,10 @@ def grouplist_ix(self, ch):

def tx_contact(self, ch):
if ch.talkgroup:
ct_index = self.index.contact[ch.talkgroup]
ct_index = self.index.contact[ch.talkgroup.name]
if ct_index <= self.radio.value.ncontacts:
return "{index:5} # {name}".format(
index=self.index.contact[ch.talkgroup],
index=ct_index,
name=ch.talkgroup.name,
)
logger.debug(
Expand Down Expand Up @@ -735,6 +736,7 @@ def contacts(self, grouplist):
contact_ranges = items_to_range_tuples(
self.index.contact,
grouplist.contacts,
key=lambda ct: ct.name,
max_index=ct_index_limit,
max_count=ct_max,
)
Expand Down Expand Up @@ -977,19 +979,18 @@ class Dmrconfig_Codeplug:
grouplist = attr.ib(default=evolve_from_factory(GrouplistTable))

def render_template(self):
if not self.template:
raise RuntimeError("no template is defined")
return "\n".join(
tuple(self.template.header) + self.render() + tuple(self.template.footer),
tuple(self.template.header)
+ (("", self.template.version_comment_line) if self.template.include_version is not False else tuple())
+ self.render()
+ tuple(self.template.footer)
)

def render(self):
preamble = (
("", self.template.version_comment_line)
if self.template.include_version is not False
else tuple()
)
return (
preamble
+ self.analog.render()
self.analog.render()
+ self.digital.render()
+ self.contact.render()
+ self.grouplist.render()
Expand Down
57 changes: 55 additions & 2 deletions tests/test_dmrconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import pytest

import dzcb.model
import dzcb.output.dmrconfig
import dzcb.data

Expand All @@ -11,8 +12,60 @@

@pytest.mark.parametrize(
"template",
(pytest.param(tf.read_text(), id=tf.name) for tf in default_dmrconfig_path.glob("*.conf")),
(
pytest.param(tf.read_text(), id=tf.name)
for tf in default_dmrconfig_path.glob("*.conf")
),
)
def test_dmrconfig_templates(complex_codeplug, template):
table = dzcb.output.dmrconfig.Table(complex_codeplug)
assert dzcb.output.dmrconfig.Dmrconfig_Codeplug(table, template).render_template()
assert dzcb.output.dmrconfig.Dmrconfig_Codeplug(table, template).render_template()


@pytest.fixture
def same_contact_both_timeslots_codeplug():
"""
regression test for #65

1 contact used on 2 different timeslots will result in arbitrary missing channels
"""

ct = dzcb.model.Contact(
name="CT",
dmrid=1,
)
tg_1 = dzcb.model.Talkgroup.from_contact(ct, timeslot=dzcb.model.Timeslot.ONE)
tg_2 = dzcb.model.Talkgroup.from_contact(ct, timeslot=dzcb.model.Timeslot.TWO)

ch = dzcb.model.DigitalChannel(
name="RP", frequency="444.444", static_talkgroups=[tg_1, tg_2]
)

zn = dzcb.model.Zone(
name="ZN",
channels_a=[ch],
channels_b=[ch],
)

return dzcb.model.Codeplug(
contacts=[tg_1, tg_2],
channels=[ch],
zones=[zn],
)


def test_dmrconfig_contact_integrity(same_contact_both_timeslots_codeplug):
cp = same_contact_both_timeslots_codeplug
assert len(cp.channels) == 1

exp_cp = cp.expand_static_talkgroups()
exp_channel_names = ("CT 1 RP", "CT 2 RP")
assert tuple(ch.name for ch in exp_cp.channels) == exp_channel_names

dmrconfig_cp = dzcb.output.dmrconfig.Dmrconfig_Codeplug(
table=dzcb.output.dmrconfig.Table(codeplug=exp_cp),
)

dmrconfig_conf = "\n".join(dmrconfig_cp.render())
for ch_name in exp_channel_names:
assert ch_name.replace(" ", "_") in dmrconfig_conf