diff --git a/src/dzcb/farnsworth.py b/src/dzcb/farnsworth.py index c9315c9..26f4020 100644 --- a/src/dzcb/farnsworth.py +++ b/src/dzcb/farnsworth.py @@ -5,6 +5,7 @@ import attr from dzcb.model import ( + AdmitCriteria, AnalogChannel, Contact, DigitalChannel, @@ -173,6 +174,11 @@ def AnalogChannel_to_dict(c, codeplug): color_code="ColorCode", ) +AdmitCriteria_map = { + AdmitCriteria.ALWAYS: "Always", + AdmitCriteria.CHANNEL_FREE: "Channel free", + AdmitCriteria.SAME_COLOR: "Color code", +} def DigitalChannel_to_dict(c, codeplug, contacts_by_id): d = DefaultChannel.copy() @@ -180,8 +186,14 @@ def DigitalChannel_to_dict(c, codeplug, contacts_by_id): if c.talkgroup: # get the dedupe'd contact's name for the given ID talkgroup_name = str(contacts_by_id.get(c.talkgroup.dmrid, c.talkgroup).name) + + admit_criteria = AdmitCriteria_map.get(c.admit_criteria, None) + if not admit_criteria: + raise ValueError("editcp does not support AdmitCriteria: {}".format(c.admit_criteria)) + d.update( { + "AdmitCriteria": admit_criteria, "ChannelMode": "Digital", "RepeaterSlot": str(c.talkgroup.timeslot) if c.talkgroup else 1, "ContactName": talkgroup_name, diff --git a/src/dzcb/k7abd.py b/src/dzcb/k7abd.py index 0249459..0cf7824 100644 --- a/src/dzcb/k7abd.py +++ b/src/dzcb/k7abd.py @@ -259,6 +259,7 @@ def DigitalChannels_from_k7abd_csv(digital_others_csv, talkgroups_by_name): color_code = r.pop("Color Code") power = r.pop("Power") tg_name = r.pop("Talk Group") + tx_permit = r.pop("TX Permit") try: talkgroup = Talkgroup.from_contact( talkgroups_by_name[tg_name], @@ -281,6 +282,7 @@ def DigitalChannels_from_k7abd_csv(digital_others_csv, talkgroups_by_name): color_code=color_code, power=power, talkgroup=talkgroup, + admit_criteria=tx_permit, ) ) return zones diff --git a/src/dzcb/model.py b/src/dzcb/model.py index e964a36..779a132 100644 --- a/src/dzcb/model.py +++ b/src/dzcb/model.py @@ -185,6 +185,12 @@ def flattened(self, allowed_bandwidths): ) ) +class AdmitCriteria(ConvertibleEnum): + ALWAYS = "Always" + CHANNEL_FREE = "ChannelFree" + SAME_COLOR = "Same Color Code" + DIFFERENT_COLOR = "Different Color Code" + def round_frequency(freq, ndigits=5): return round(float(freq), ndigits) @@ -312,6 +318,11 @@ class DigitalChannel(Channel): member_validator=attr.validators.instance_of(Talkgroup) ), ) + admit_criteria = attr.ib( + default=AdmitCriteria.SAME_COLOR, + validator=attr.validators.instance_of(AdmitCriteria), + converter=AdmitCriteria.from_any, + ) def from_talkgroups(self, talkgroups, **kwargs): """ diff --git a/src/dzcb/output/dmrconfig.py b/src/dzcb/output/dmrconfig.py index 220461c..1be14e1 100644 --- a/src/dzcb/output/dmrconfig.py +++ b/src/dzcb/output/dmrconfig.py @@ -26,6 +26,7 @@ from dzcb import __version__ import dzcb.munge from dzcb.model import ( + AdmitCriteria, Bandwidth, Codeplug, Power, @@ -529,6 +530,13 @@ def normal_dcs(tone): ) +digital_admit_criteria = { + AdmitCriteria.ALWAYS: "-", + AdmitCriteria.CHANNEL_FREE: "Free", + AdmitCriteria.SAME_COLOR: "Color", + AdmitCriteria.DIFFERENT_COLOR: "NColor", +} + class DigitalChannelTable(ChannelTable): """ # Table of digital channels. @@ -600,7 +608,7 @@ def item_to_dict(self, index, ch): Scan=self.scanlist_ix(ch) or "-", TOT=90, # TODO: how to expose this parameter RO=plus_minus[ch.rx_only], - Admit="Color", + Admit=digital_admit_criteria[ch.admit_criteria], Color=ch.color_code, Slot=ch.talkgroup.timeslot.value if ch.talkgroup else 1, RxGL=self.grouplist_ix(ch) or "-", diff --git a/tests/default-codeplug-expect-output/dmrconfig/d878uv-int.conf b/tests/default-codeplug-expect-output/dmrconfig/d878uv-int.conf index 7c42795..3b4905e 100644 --- a/tests/default-codeplug-expect-output/dmrconfig/d878uv-int.conf +++ b/tests/default-codeplug-expect-output/dmrconfig/d878uv-int.conf @@ -214,16 +214,16 @@ Analog Name Receive Transmit Power Scan TOT RO Admit Squelch RxTon # 12) Receive group list: - or index in Grouplist table # 13) Contact for transmit: - or index in Contacts table Digital Name Receive Transmit Power Scan TOT RO Admit Color Slot RxGL TxContact - 179 SP_V01_145.790 145.79 145.79 High 11 90 - Color 1 1 - 46 # Simplex 99 - 180 SP_V02_145.510 145.51 145.51 High 11 90 - Color 1 1 - 46 # Simplex 99 - 181 SP_U01_441.000 441.0 441.0 High 10 90 - Color 1 1 - 46 # Simplex 99 - 182 SP_U02_446.5 446.5 446.5 High 10 90 - Color 1 1 - 46 # Simplex 99 - 183 SP_U03_446.075 446.075 446.075 High 10 90 - Color 1 1 - 46 # Simplex 99 - 184 SP_U04_433.45 433.45 433.45 High 10 90 - Color 1 1 - 46 # Simplex 99 - 185 SP_U05_430.4125 430.4125 430.4125 Low 10 90 - Color 1 1 - 46 # Simplex 99 - 186 SP_U06_439.4125 439.4125 439.4125 Low 10 90 - Color 1 1 - 46 # Simplex 99 - 187 SP_U07_430.425 430.425 430.425 Low 10 90 - Color 1 1 - 46 # Simplex 99 - 188 SP_U08_439.425 439.425 439.425 Low 10 90 - Color 1 1 - 46 # Simplex 99 + 179 SP_V01_145.790 145.79 145.79 High 11 90 - - 1 1 - 46 # Simplex 99 + 180 SP_V02_145.510 145.51 145.51 High 11 90 - - 1 1 - 46 # Simplex 99 + 181 SP_U01_441.000 441.0 441.0 High 10 90 - - 1 1 - 46 # Simplex 99 + 182 SP_U02_446.5 446.5 446.5 High 10 90 - - 1 1 - 46 # Simplex 99 + 183 SP_U03_446.075 446.075 446.075 High 10 90 - - 1 1 - 46 # Simplex 99 + 184 SP_U04_433.45 433.45 433.45 High 10 90 - - 1 1 - 46 # Simplex 99 + 185 SP_U05_430.4125 430.4125 430.4125 Low 10 90 - - 1 1 - 46 # Simplex 99 + 186 SP_U06_439.4125 439.4125 439.4125 Low 10 90 - - 1 1 - 46 # Simplex 99 + 187 SP_U07_430.425 430.425 430.425 Low 10 90 - - 1 1 - 46 # Simplex 99 + 188 SP_U08_439.425 439.425 439.425 Low 10 90 - - 1 1 - 46 # Simplex 99 189 R_U09_430.4375 430.4375 439.4375 Low 12 90 - Color 1 1 - 5 # Local 1 190 R_U10_430.450 430.45 439.45 Low 12 90 - Color 1 1 - 5 # Local 1 191 R_U11_430.4625 430.4625 439.4625 Low 12 90 - Color 1 1 - 5 # Local 1 @@ -2480,4 +2480,4 @@ Name: My Radio # Text displayed when the radio powers up. Intro Line 1: dzcb -Intro Line 2: 2021-03-07 \ No newline at end of file +Intro Line 2: 2021-03-07 diff --git a/tests/default-codeplug-expect-output/dmrconfig/md-uv380-int.conf b/tests/default-codeplug-expect-output/dmrconfig/md-uv380-int.conf index 5444e54..2838f38 100644 --- a/tests/default-codeplug-expect-output/dmrconfig/md-uv380-int.conf +++ b/tests/default-codeplug-expect-output/dmrconfig/md-uv380-int.conf @@ -216,16 +216,16 @@ Analog Name Receive Transmit Power Scan TOT RO Admit Squelch RxTon # 12) Receive group list: - or index in Grouplist table # 13) Contact for transmit: - or index in Contacts table Digital Name Receive Transmit Power Scan TOT RO Admit Color Slot RxGL TxContact - 179 SP_V01_145.790 145.79 145.79 High 11 90 - Color 1 1 - 46 # Simplex 99 - 180 SP_V02_145.510 145.51 145.51 High 11 90 - Color 1 1 - 46 # Simplex 99 - 181 SP_U01_441.000 441.0 441.0 High 10 90 - Color 1 1 - 46 # Simplex 99 - 182 SP_U02_446.5 446.5 446.5 High 10 90 - Color 1 1 - 46 # Simplex 99 - 183 SP_U03_446.075 446.075 446.075 High 10 90 - Color 1 1 - 46 # Simplex 99 - 184 SP_U04_433.45 433.45 433.45 High 10 90 - Color 1 1 - 46 # Simplex 99 - 185 SP_U05_430.4125 430.4125 430.4125 Low 10 90 - Color 1 1 - 46 # Simplex 99 - 186 SP_U06_439.4125 439.4125 439.4125 Low 10 90 - Color 1 1 - 46 # Simplex 99 - 187 SP_U07_430.425 430.425 430.425 Low 10 90 - Color 1 1 - 46 # Simplex 99 - 188 SP_U08_439.425 439.425 439.425 Low 10 90 - Color 1 1 - 46 # Simplex 99 + 179 SP_V01_145.790 145.79 145.79 High 11 90 - - 1 1 - 46 # Simplex 99 + 180 SP_V02_145.510 145.51 145.51 High 11 90 - - 1 1 - 46 # Simplex 99 + 181 SP_U01_441.000 441.0 441.0 High 10 90 - - 1 1 - 46 # Simplex 99 + 182 SP_U02_446.5 446.5 446.5 High 10 90 - - 1 1 - 46 # Simplex 99 + 183 SP_U03_446.075 446.075 446.075 High 10 90 - - 1 1 - 46 # Simplex 99 + 184 SP_U04_433.45 433.45 433.45 High 10 90 - - 1 1 - 46 # Simplex 99 + 185 SP_U05_430.4125 430.4125 430.4125 Low 10 90 - - 1 1 - 46 # Simplex 99 + 186 SP_U06_439.4125 439.4125 439.4125 Low 10 90 - - 1 1 - 46 # Simplex 99 + 187 SP_U07_430.425 430.425 430.425 Low 10 90 - - 1 1 - 46 # Simplex 99 + 188 SP_U08_439.425 439.425 439.425 Low 10 90 - - 1 1 - 46 # Simplex 99 189 R_U09_430.4375 430.4375 439.4375 Low 12 90 - Color 1 1 - 5 # Local 1 190 R_U10_430.450 430.45 439.45 Low 12 90 - Color 1 1 - 5 # Local 1 191 R_U11_430.4625 430.4625 439.4625 Low 12 90 - Color 1 1 - 5 # Local 1 @@ -2537,4 +2537,4 @@ Name: My Radio # Text displayed when the radio powers up. Intro Line 1: dzcb -Intro Line 2: 2021-03-07 \ No newline at end of file +Intro Line 2: 2021-03-07 diff --git a/tests/default-codeplug-expect-output/dmrconfig/md380-int.conf b/tests/default-codeplug-expect-output/dmrconfig/md380-int.conf index 44676c1..0f86281 100644 --- a/tests/default-codeplug-expect-output/dmrconfig/md380-int.conf +++ b/tests/default-codeplug-expect-output/dmrconfig/md380-int.conf @@ -154,14 +154,14 @@ Analog Name Receive Transmit Power Scan TOT RO Admit Squelch RxTon # 12) Receive group list: - or index in Grouplist table # 13) Contact for transmit: - or index in Contacts table Digital Name Receive Transmit Power Scan TOT RO Admit Color Slot RxGL TxContact - 28 SP_U01_441.000 441.0 441.0 High 6 90 - Color 1 1 - 46 # Simplex 99 - 29 SP_U02_446.5 446.5 446.5 High 6 90 - Color 1 1 - 46 # Simplex 99 - 30 SP_U03_446.075 446.075 446.075 High 6 90 - Color 1 1 - 46 # Simplex 99 - 31 SP_U04_433.45 433.45 433.45 High 6 90 - Color 1 1 - 46 # Simplex 99 - 32 SP_U05_430.4125 430.4125 430.4125 Low 6 90 - Color 1 1 - 46 # Simplex 99 - 33 SP_U06_439.4125 439.4125 439.4125 Low 6 90 - Color 1 1 - 46 # Simplex 99 - 34 SP_U07_430.425 430.425 430.425 Low 6 90 - Color 1 1 - 46 # Simplex 99 - 35 SP_U08_439.425 439.425 439.425 Low 6 90 - Color 1 1 - 46 # Simplex 99 + 28 SP_U01_441.000 441.0 441.0 High 6 90 - - 1 1 - 46 # Simplex 99 + 29 SP_U02_446.5 446.5 446.5 High 6 90 - - 1 1 - 46 # Simplex 99 + 30 SP_U03_446.075 446.075 446.075 High 6 90 - - 1 1 - 46 # Simplex 99 + 31 SP_U04_433.45 433.45 433.45 High 6 90 - - 1 1 - 46 # Simplex 99 + 32 SP_U05_430.4125 430.4125 430.4125 Low 6 90 - - 1 1 - 46 # Simplex 99 + 33 SP_U06_439.4125 439.4125 439.4125 Low 6 90 - - 1 1 - 46 # Simplex 99 + 34 SP_U07_430.425 430.425 430.425 Low 6 90 - - 1 1 - 46 # Simplex 99 + 35 SP_U08_439.425 439.425 439.425 Low 6 90 - - 1 1 - 46 # Simplex 99 103 R_U09_430.4375 430.4375 439.4375 Low 7 90 - Color 1 1 - 5 # Local 1 104 R_U10_430.450 430.45 439.45 Low 7 90 - Color 1 1 - 5 # Local 1 105 R_U11_430.4625 430.4625 439.4625 Low 7 90 - Color 1 1 - 5 # Local 1 @@ -1314,4 +1314,4 @@ Name: My Radio # Text displayed when the radio powers up. Intro Line 1: dzcb -Intro Line 2: 2021-03-07 \ No newline at end of file +Intro Line 2: 2021-03-07 diff --git a/tests/default-codeplug-expect-output/editcp/md-uv380.json b/tests/default-codeplug-expect-output/editcp/md-uv380.json index 5b98a1b..4b5ae9d 100644 --- a/tests/default-codeplug-expect-output/editcp/md-uv380.json +++ b/tests/default-codeplug-expect-output/editcp/md-uv380.json @@ -9271,7 +9271,7 @@ "Power": "Medium" }, { - "AdmitCriteria": "Color code", + "AdmitCriteria": "Always", "AllowTalkaround": "Off", "Autoscan": "Off", "ColorCode": "1", @@ -9322,7 +9322,7 @@ "Power": "High" }, { - "AdmitCriteria": "Color code", + "AdmitCriteria": "Always", "AllowTalkaround": "Off", "Autoscan": "Off", "ColorCode": "1", @@ -9373,7 +9373,7 @@ "Power": "High" }, { - "AdmitCriteria": "Color code", + "AdmitCriteria": "Always", "AllowTalkaround": "Off", "Autoscan": "Off", "ColorCode": "1", @@ -9424,7 +9424,7 @@ "Power": "High" }, { - "AdmitCriteria": "Color code", + "AdmitCriteria": "Always", "AllowTalkaround": "Off", "Autoscan": "Off", "ColorCode": "1", @@ -9475,7 +9475,7 @@ "Power": "High" }, { - "AdmitCriteria": "Color code", + "AdmitCriteria": "Always", "AllowTalkaround": "Off", "Autoscan": "Off", "ColorCode": "1", @@ -9526,7 +9526,7 @@ "Power": "High" }, { - "AdmitCriteria": "Color code", + "AdmitCriteria": "Always", "AllowTalkaround": "Off", "Autoscan": "Off", "ColorCode": "1", @@ -9577,7 +9577,7 @@ "Power": "High" }, { - "AdmitCriteria": "Color code", + "AdmitCriteria": "Always", "AllowTalkaround": "Off", "Autoscan": "Off", "ColorCode": "1", @@ -9628,7 +9628,7 @@ "Power": "Low" }, { - "AdmitCriteria": "Color code", + "AdmitCriteria": "Always", "AllowTalkaround": "Off", "Autoscan": "Off", "ColorCode": "1", @@ -9679,7 +9679,7 @@ "Power": "Low" }, { - "AdmitCriteria": "Color code", + "AdmitCriteria": "Always", "AllowTalkaround": "Off", "Autoscan": "Off", "ColorCode": "1", @@ -9730,7 +9730,7 @@ "Power": "Low" }, { - "AdmitCriteria": "Color code", + "AdmitCriteria": "Always", "AllowTalkaround": "Off", "Autoscan": "Off", "ColorCode": "1", @@ -115749,4 +115749,4 @@ ] } ] -} \ No newline at end of file +} diff --git a/tests/default-codeplug-expect-output/editcp/md-uv390.json b/tests/default-codeplug-expect-output/editcp/md-uv390.json index e652b33..5683a6a 100644 --- a/tests/default-codeplug-expect-output/editcp/md-uv390.json +++ b/tests/default-codeplug-expect-output/editcp/md-uv390.json @@ -9271,7 +9271,7 @@ "Power": "Medium" }, { - "AdmitCriteria": "Color code", + "AdmitCriteria": "Always", "AllowTalkaround": "Off", "Autoscan": "Off", "ColorCode": "1", @@ -9322,7 +9322,7 @@ "Power": "High" }, { - "AdmitCriteria": "Color code", + "AdmitCriteria": "Always", "AllowTalkaround": "Off", "Autoscan": "Off", "ColorCode": "1", @@ -9373,7 +9373,7 @@ "Power": "High" }, { - "AdmitCriteria": "Color code", + "AdmitCriteria": "Always", "AllowTalkaround": "Off", "Autoscan": "Off", "ColorCode": "1", @@ -9424,7 +9424,7 @@ "Power": "High" }, { - "AdmitCriteria": "Color code", + "AdmitCriteria": "Always", "AllowTalkaround": "Off", "Autoscan": "Off", "ColorCode": "1", @@ -9475,7 +9475,7 @@ "Power": "High" }, { - "AdmitCriteria": "Color code", + "AdmitCriteria": "Always", "AllowTalkaround": "Off", "Autoscan": "Off", "ColorCode": "1", @@ -9526,7 +9526,7 @@ "Power": "High" }, { - "AdmitCriteria": "Color code", + "AdmitCriteria": "Always", "AllowTalkaround": "Off", "Autoscan": "Off", "ColorCode": "1", @@ -9577,7 +9577,7 @@ "Power": "High" }, { - "AdmitCriteria": "Color code", + "AdmitCriteria": "Always", "AllowTalkaround": "Off", "Autoscan": "Off", "ColorCode": "1", @@ -9628,7 +9628,7 @@ "Power": "Low" }, { - "AdmitCriteria": "Color code", + "AdmitCriteria": "Always", "AllowTalkaround": "Off", "Autoscan": "Off", "ColorCode": "1", @@ -9679,7 +9679,7 @@ "Power": "Low" }, { - "AdmitCriteria": "Color code", + "AdmitCriteria": "Always", "AllowTalkaround": "Off", "Autoscan": "Off", "ColorCode": "1", @@ -9730,7 +9730,7 @@ "Power": "Low" }, { - "AdmitCriteria": "Color code", + "AdmitCriteria": "Always", "AllowTalkaround": "Off", "Autoscan": "Off", "ColorCode": "1", @@ -115749,4 +115749,4 @@ ] } ] -} \ No newline at end of file +} diff --git a/tests/digital-channels-tx-permit/Digital-Others__Main.csv b/tests/digital-channels-tx-permit/Digital-Others__Main.csv new file mode 100644 index 0000000..19a41be --- /dev/null +++ b/tests/digital-channels-tx-permit/Digital-Others__Main.csv @@ -0,0 +1,5 @@ +Zone,Channel Name,Power,RX Freq,TX Freq,Color Code,Talk Group,TimeSlot,Call Type,TX Permit +Bar,Always,High,430.4375,430.4375,1,TG 2,1,Group Call,Always +Bar,ChannelFree,High,430.4375,430.4375,1,TG 2,1,Group Call,ChannelFree +Bar,SameColor,High,430.4375,430.4375,1,TG 2,1,Group Call,Same Color Code +Bar,DifferentColor,High,430.4375,430.4375,1,TG 2,1,Group Call,Different Color Code diff --git a/tests/digital-channels-tx-permit/Talkgroups__Main.csv b/tests/digital-channels-tx-permit/Talkgroups__Main.csv new file mode 100644 index 0000000..33e5bc3 --- /dev/null +++ b/tests/digital-channels-tx-permit/Talkgroups__Main.csv @@ -0,0 +1 @@ +TG 2,2 diff --git a/tests/test_dmrconfig.py b/tests/test_dmrconfig.py index d43bdf7..a52bcb3 100644 --- a/tests/test_dmrconfig.py +++ b/tests/test_dmrconfig.py @@ -82,3 +82,49 @@ def test_dmrconfig_contact_integrity(same_contact_both_timeslots_codeplug, templ digital_channels = "\n".join(dmrconfig_cp.digital.render()) for ch_name in exp_channel_names: assert ch_name.replace(" ", "_") in digital_channels + +@pytest.fixture +def all_admit_criteria_codeplug(): + """ + Minimal code plug channels for each value of admit criteria. + """ + + ct = dzcb.model.Contact( + name="CT", + dmrid=1, + ) + tg_1 = dzcb.model.Talkgroup.from_contact(ct, timeslot=dzcb.model.Timeslot.ONE) + + chs = [ + dzcb.model.DigitalChannel( + name=ac.value, frequency="444.444", static_talkgroups=[tg_1], + admit_criteria=ac, + ) + for ac in dzcb.model.AdmitCriteria + ] + + zn = dzcb.model.Zone( + name="ZN", + channels_a=chs, + channels_b=chs, + ) + + return dzcb.model.Codeplug( + contacts=[tg_1], + channels=chs, + zones=[zn], + ) + + +def test_dmrconfig_admit_criteria(all_admit_criteria_codeplug): + """ + Verify that a codeplug using all admit criteria can be converted without error. + """ + + cp = all_admit_criteria_codeplug + assert len(cp.channels) > 0 + + exp_cp = cp.expand_static_talkgroups() + dmrconfig_cp = dzcb.output.dmrconfig.Dmrconfig_Codeplug.from_codeplug( + codeplug=exp_cp, + ) diff --git a/tests/test_farnsworth.py b/tests/test_farnsworth.py new file mode 100644 index 0000000..738a5fe --- /dev/null +++ b/tests/test_farnsworth.py @@ -0,0 +1,91 @@ +import pytest + +import dzcb.model +import dzcb.farnsworth + + +@pytest.fixture +def supported_admit_criteria_codeplug(): + """ + Minimal code plug channels for each admit criteria supported + by Farnsworth codeplugs. + """ + + ct = dzcb.model.Contact( + name="CT", + dmrid=1, + ) + tg_1 = dzcb.model.Talkgroup.from_contact(ct, timeslot=dzcb.model.Timeslot.ONE) + + chs = [ + dzcb.model.DigitalChannel( + name=ac.value, frequency="444.444", static_talkgroups=[tg_1], + admit_criteria=ac, + ) + for ac in dzcb.farnsworth.AdmitCriteria_map + ] + + zn = dzcb.model.Zone( + name="ZN", + channels_a=chs, + channels_b=chs, + ) + + return dzcb.model.Codeplug( + contacts=[tg_1], + channels=chs, + zones=[zn], + ) + + +def test_farnsworth_admit_criteria(supported_admit_criteria_codeplug): + """ + Verify that a codeplug using all admit criteria supported by + Farnsworth codeplugs can be converted without error. + """ + + cp = supported_admit_criteria_codeplug + assert len(cp.channels) > 0 + + exp_cp = cp.expand_static_talkgroups() + json = dzcb.farnsworth.Codeplug_to_json(exp_cp) + + +@pytest.fixture +def unsupported_admit_criteria_codeplug(): + """ + Minimal code plug with a channel with admit criteria that is not supported by editcp. + """ + + ct = dzcb.model.Contact( + name="CT", + dmrid=1, + ) + tg_1 = dzcb.model.Talkgroup.from_contact(ct, timeslot=dzcb.model.Timeslot.ONE) + + ch = dzcb.model.DigitalChannel( + name="RP", frequency="444.444", static_talkgroups=[tg_1], + admit_criteria=dzcb.model.AdmitCriteria.DIFFERENT_COLOR, + ) + + zn = dzcb.model.Zone( + name="ZN", + channels_a=[ch], + channels_b=[ch], + ) + + return dzcb.model.Codeplug( + contacts=[tg_1], + channels=[ch], + zones=[zn], + ) + + +def test_farnsworth_unsupported_admit_criteria(unsupported_admit_criteria_codeplug): + cp = unsupported_admit_criteria_codeplug + assert len(cp.channels) == 1 + + exp_cp = cp.expand_static_talkgroups() + + with pytest.raises(ValueError): + dzcb.farnsworth.Codeplug_to_json(exp_cp) diff --git a/tests/test_k7abd.py b/tests/test_k7abd.py index dbaf10d..60ec759 100644 --- a/tests/test_k7abd.py +++ b/tests/test_k7abd.py @@ -5,7 +5,7 @@ import pytest from dzcb import farnsworth, k7abd -from dzcb.model import Timeslot, ContactType +from dzcb.model import Timeslot, ContactType, AdmitCriteria def codeplug_from_relative_dir(dname): @@ -201,3 +201,26 @@ def test_digital_repeaters_same_tg_different_ts(): assert len(fw_cp["GroupLists"]) == 3 for grouplist in fw_cp["GroupLists"]: assert grouplist["Contact"] == [tg_name] + +def test_digital_channels_tx_permit(): + """ + Verify that the "TX Permit" column will be parsed correctly in + Digital-Others__*.csv. + """ + + cp = codeplug_from_relative_dir("digital-channels-tx-permit") + assert len(cp.zones) == 1 + assert len(cp.contacts) == 1 + assert len(cp.channels) == 4 + + assert cp.channels[0].name == "Always" + assert cp.channels[0].admit_criteria == AdmitCriteria.ALWAYS + + assert cp.channels[1].name == "ChannelFree" + assert cp.channels[1].admit_criteria == AdmitCriteria.CHANNEL_FREE + + assert cp.channels[2].name == "SameColor" + assert cp.channels[2].admit_criteria == AdmitCriteria.SAME_COLOR + + assert cp.channels[3].name == "DifferentColor" + assert cp.channels[3].admit_criteria == AdmitCriteria.DIFFERENT_COLOR