From 3b85f7169b9a297c8cff79f00e733d49c4fa895a Mon Sep 17 00:00:00 2001 From: David Bures Date: Mon, 29 Jul 2024 13:32:46 -0700 Subject: [PATCH] few minor improvements --- mesh_bot.py | 3 ++- tests/test_weather_bot.py | 13 +++++++++++++ weather_bot.py | 4 ++-- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/mesh_bot.py b/mesh_bot.py index 7d71be7..e109d74 100644 --- a/mesh_bot.py +++ b/mesh_bot.py @@ -42,7 +42,8 @@ def exit_handler(signum, frame): print("\nSystem: Closing Autoresponder") - interface.close() + if interface: + interface.close() exit(0) diff --git a/tests/test_weather_bot.py b/tests/test_weather_bot.py index a0c923b..a4c2f52 100644 --- a/tests/test_weather_bot.py +++ b/tests/test_weather_bot.py @@ -39,6 +39,19 @@ def test_get_weather_with_valid_coordinates(mock_interface): assert "showers" not in weather assert "thunderstorms" not in weather +@patch("meshtastic.serial_interface.SerialInterface") +def test_get_weather_with_valid_EU_coordinates(mock_interface): + # Mock the SerialInterface to avoid actual serial communication + mock_interface = MagicMock() + mock_interface.return_value = mock_interface + bot = WeatherBot(mock_interface) + # Brno, Czech Republic + lat = "49.2835628812946" + lon = "16.565363025853" + weather = bot.get_weather(lat, lon) + print(f"weather: {weather}") + assert weather != bot.NO_DATA_NOGPS + assert weather == bot.ERROR_FETCHING_DATA @patch("meshtastic.serial_interface.SerialInterface") def test_get_weather_with_invalid_coordinates(mock_interface): diff --git a/weather_bot.py b/weather_bot.py index 223bd38..8add5dc 100644 --- a/weather_bot.py +++ b/weather_bot.py @@ -18,7 +18,7 @@ class WeatherBot(MessageProcessor): def __init__(self, interface: StreamInterface): super(WeatherBot, self).__init__(interface) - self.trap_list = ["sun", "solar", "hfcond", "tide", "moon", "wxc", "wx", "alerts"] + self.trap_list = ["sun", "solar", "hfcond", "tide", "moon", "wxc", "wx", "wxa"] pass def auto_response( @@ -42,7 +42,7 @@ def auto_response( bot_response = self.get_weather(str(location[0]), str(location[1]), 1) elif "wx" in message: bot_response = self.get_weather(str(location[0]), str(location[1])) - elif "alerts" in message: + elif "wxa" in message: bot_response = self.get_wx_alerts(str(location[0]), str(location[1])) return bot_response