From d1161e9a367ece67924e5094f14f3908717cfba1 Mon Sep 17 00:00:00 2001 From: Lars Lehtonen Date: Mon, 27 May 2024 16:30:23 -0700 Subject: [PATCH] Add openonly filter to Repeaterbook queries --- chirp/sources/repeaterbook.py | 7 +++++++ chirp/wxui/query_sources.py | 7 +++++++ tests/unit/test_repeaterbook.py | 6 ++++++ 3 files changed, 20 insertions(+) diff --git a/chirp/sources/repeaterbook.py b/chirp/sources/repeaterbook.py index 2c2b2223e..252df054c 100644 --- a/chirp/sources/repeaterbook.py +++ b/chirp/sources/repeaterbook.py @@ -216,6 +216,8 @@ def do_fetch(self, status, params): bands = params.pop('bands', []) modes = params.pop('modes', []) fmconv = params.pop('fmconv', False) + openonly = params.pop('openonly') + data_file = self.get_data(status, params.get('country'), params.pop('state'), @@ -244,6 +246,9 @@ def match(item): return (not search_filter or search_filter.lower() in content.lower()) + def open_repeater(item): + return item['Use'] == 'OPEN' + def included_band(item): if not bands: return True @@ -257,6 +262,8 @@ def included_band(item): key=sorter): if not item: continue + if openonly and not open_repeater(item): + continue if item['Operational Status'] != 'On-air': continue if dist and lat and lon and ( diff --git a/chirp/wxui/query_sources.py b/chirp/wxui/query_sources.py index 829d6d860..d135ff837 100644 --- a/chirp/wxui/query_sources.py +++ b/chirp/wxui/query_sources.py @@ -329,6 +329,11 @@ def build(self): self.Bind(wx.EVT_CHECKBOX, self._select_modes, self._modefilter) self._add_grid(grid, _('Limit Modes'), self._modefilter) + self._openonly = wx.CheckBox(panel, label=_('Open repeaters only')) + self._openonly.SetValue(CONF.get_bool('openonly', 'repeaterbook')) + self._openonly.SetToolTip(_('Exclude private and closed repeaters')) + self._add_grid(grid, _('Limit use'), self._openonly) + self._fmconv = wx.CheckBox(panel, label=_('Convert to FM')) self._fmconv.SetValue(CONF.get_bool('fmconv', 'repeaterbook')) self._fmconv.SetToolTip(_('Dual-mode digital repeaters that support ' @@ -420,6 +425,7 @@ def do_query(self): CONF.set('country', self._country.GetStringSelection(), 'repeaterbook') CONF.set('service', self._service.GetStringSelection(), 'repeaterbook') CONF.set_bool('fmconv', self._fmconv.IsChecked(), 'repeaterbook') + CONF.set_bool('openonly', self._openonly.IsChecked(), 'repeaterbook') self.result_radio = repeaterbook.RepeaterBook() super().do_query() @@ -437,6 +443,7 @@ def get_params(self): 'service': 'gmrs' if service == _('GMRS') else '', 'service_display': self._service.GetStringSelection(), 'fmconv': self._fmconv.IsChecked(), + 'openonly': self._openonly.IsChecked(), } diff --git a/tests/unit/test_repeaterbook.py b/tests/unit/test_repeaterbook.py index dc8b2e27e..05a9c55c3 100644 --- a/tests/unit/test_repeaterbook.py +++ b/tests/unit/test_repeaterbook.py @@ -42,6 +42,7 @@ def test_get_oregon(self): 'lat': 45, 'lon': -122, 'dist': 100, + 'openonly': False, }) m = rb.get_memory(0) self.assertIsInstance(m, chirp_common.Memory) @@ -71,6 +72,7 @@ def test_get_wyoming(self): 'lat': 45, 'lon': -122, 'dist': 0, + 'openonly': False, }) m = rb.get_memory(0) self.assertIsInstance(m, chirp_common.Memory) @@ -88,6 +90,7 @@ def test_get_oregon_gmrs(self): 'lon': -122, 'dist': 100, 'service': 'gmrs', + 'openonly': False, }) m = rb.get_memory(0) self.assertIsInstance(m, chirp_common.Memory) @@ -104,6 +107,7 @@ def test_get_australia(self): 'lat': -26, 'lon': 133, 'dist': 20000, + 'openonly': False, }) m = rb.get_memory(0) self.assertIsInstance(m, chirp_common.Memory) @@ -123,6 +127,7 @@ def test_filter(self): 'lat': 45, 'lon': -122, 'dist': 0, + 'openonly': False, 'filter': 'tower'} rb = self._test_with_mocked(params) self.assertGreater(sum(rb.get_features().memory_bounds), 5) @@ -133,6 +138,7 @@ def test_distance(self): 'lat': 45, 'lon': -122, 'dist': 0, + 'openonly': False, 'filter': 'tower'} rb1 = self._test_with_mocked(dict(params)) self.assertGreater(sum(rb1.get_features().memory_bounds), 5)