Skip to content

Commit

Permalink
few minor improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
PiDiBi committed Jul 29, 2024
1 parent 6fb197c commit 3b85f71
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
3 changes: 2 additions & 1 deletion mesh_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@

def exit_handler(signum, frame):
print("\nSystem: Closing Autoresponder")
interface.close()
if interface:
interface.close()
exit(0)


Expand Down
13 changes: 13 additions & 0 deletions tests/test_weather_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
4 changes: 2 additions & 2 deletions weather_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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
Expand Down

0 comments on commit 3b85f71

Please sign in to comment.