Skip to content

Commit

Permalink
Merge branch 'release/v22.12.2' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
peted-davis committed Dec 22, 2022
2 parents 2f88baa + f3c8ba3 commit 10e4ad9
Show file tree
Hide file tree
Showing 7 changed files with 146 additions and 111 deletions.
3 changes: 1 addition & 2 deletions kvlang/layout.kv
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,7 @@
font_size: dp(16*app.scaleFactor)
text: app.config['Station']['Name']
MenuField:
_color: '#9aba2fff' if app.CurrentConditions.Status['station_status'] == 'Online' else '#c8c8c8ff' if app.CurrentConditions.Status['station_status'] == '-' else '#d73027ff'
text: 'Station status: [color=' + self._color + ']' + app.CurrentConditions.Status['station_status'] + '[/color]'
text: 'Station status: ' + app.CurrentConditions.Status['station_status']
GridLayout:
cols: 2
padding: [dp(0),dp(0),dp(0),dp(10)]
Expand Down
2 changes: 1 addition & 1 deletion kvlang/rainfall.kv
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@
source: 'icons/misc/offline' + app.scaleSuffix
keep_ratio: 0
allow_stretch: 1
opacity: 1 if app.CurrentConditions.Status['station_status'] == 'Offline' or app.CurrentConditions.Status['station_status'] == 'Error' else 0
opacity: 1 if 'Offline' in app.CurrentConditions.Status['station_status'] else 0
pos_hint: {'x': 230/262, 'y': 9/202}
size_hint: (30/262, 30/202)

Expand Down
4 changes: 2 additions & 2 deletions kvlang/update.kv
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
## =============================================================================
<updateNotification>:
size_hint: (None, 76/480)
pos_hint: {'x': app.CurrentConditions.ids.PanelSix.x/app.window.width, 'y': 2/app.window.height}
width: app.CurrentConditions.ids.PanelSix.size[0]
pos_hint: {'x': app.CurrentConditions.ids.panel_six.x/app.window.width, 'y': 2/app.window.height}
width: app.CurrentConditions.ids.panel_six.size[0]
UpdateNotifBackground:
_panelTitle: 'Update Available'
RelativeLayout:
Expand Down
2 changes: 1 addition & 1 deletion lib/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import os

# Define wfpiconsole version number
Version = 'v22.12.1'
Version = 'v22.12.2'

# Define required variables
TEMPEST = False
Expand Down
195 changes: 102 additions & 93 deletions lib/status.py

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions panels/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
# Load required Kivy modules
from kivy.uix.modalview import ModalView
from kivy.properties import StringProperty
from kivy.app import App


# ==============================================================================
Expand All @@ -29,5 +30,6 @@ class updateNotification(ModalView):

def __init__(self, latest_ver, **kwargs):
super().__init__(**kwargs)
self.app = App.get_running_app()
setattr(self.app, self.__class__.__name__, self)
self.latest_ver = latest_ver
49 changes: 37 additions & 12 deletions service/websocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import asyncio
import socket
import json
import time
import ssl


Expand All @@ -51,17 +52,19 @@ async def create(cls):
self.system = system()

# Initialise websocketClient class variables
self._keep_running = True
self._switch_device = False
self.reply_timeout = 60
self.ping_timeout = 60
self.sleep_time = 10
self.thread_list = {}
self.task_list = {}
self.connected = False
self.connection = None
self.station = int(self.config['Station']['StationID'])
self.url = 'wss://ws.weatherflow.com/swd/data?token=' + self.config['Keys']['WeatherFlow']
self._keep_running = True
self._switch_device = False
self.watchdog_timeout = 300
self.reply_timeout = 60
self.ping_timeout = 60
self.sleep_time = 10
self.thread_list = {}
self.task_list = {}
self.watchdog_list = {}
self.connected = False
self.connection = None
self.station = int(self.config['Station']['StationID'])
self.url = 'wss://swd.weatherflow.com/swd/data?token=' + self.config['Keys']['WeatherFlow']

# Initialise Observation Parser
self.app.obsParser = obsParser()
Expand Down Expand Up @@ -122,13 +125,17 @@ async def __async__get_devices(self):
self.device_list = {'tempest': None, 'sky': None, 'out_air': None, 'in_air': None}
if self.config['Station']['TempestID']:
self.device_list['tempest'] = self.config['Station']['TempestID']
self.watchdog_list['obs_st'], self.watchdog_list['rapid_wind'] = time.time(), time.time()
else:
if self.config['Station']['SkyID']:
self.device_list['sky'] = self.config['Station']['SkyID']
self.watchdog_list['obs_sky'], self.watchdog_list['rapid_wind'] = time.time(), time.time()
if self.config['Station']['OutAirID']:
self.device_list['out_air'] = self.config['Station']['OutAirID']
self.watchdog_list['obs_out_air'] = time.time()
if self.config['Station']['InAirID']:
self.device_list['in_air'] = self.config['Station']['InAirID']
self.watchdog_list['obs_in_air'] = time.time()

async def __async__listen_devices(self, action):
devices = []
Expand Down Expand Up @@ -165,18 +172,31 @@ async def __async__getMessage(self):
await self.task_list['verify']
return {}

async def __async__watchdog(self):
now = time.time()
watchdog_triggered = False
for ob in self.watchdog_list:
if self.watchdog_list[ob] < (now - self.watchdog_timeout):
watchdog_triggered = True
break
if watchdog_triggered:
Logger.warning(f'Websocket: {self.system.log_time()} - Watchdog triggered {ob}')
await self.__async__disconnect()
await self.__async__connect()

async def __async__decodeMessage(self):
try:
if self.message:
if 'type' in self.message:
if self.message['type'] in ['ack', 'evt_precip']:
if self.message['type'] in ['connection_opened', 'ack', 'evt_precip']:
pass
else:
if 'device_id' in self.message:
if self.message['type'] == 'obs_st':
if 'obs_st' in self.thread_list:
while self.thread_list['obs_st'].is_alive():
await asyncio.sleep(0.1)
self.watchdog_list['obs_st'] = time.time()
self.thread_list['obs_st'] = threading.Thread(target=self.app.obsParser.parse_obs_st,
args=(self.message, self.config, ),
name="obs_st")
Expand All @@ -185,6 +205,7 @@ async def __async__decodeMessage(self):
if 'obs_sky' in self.thread_list:
while self.thread_list['obs_sky'].is_alive():
await asyncio.sleep(0.1)
self.watchdog_list['obs_sky'] = time.time()
self.thread_list['obs_sky'] = threading.Thread(target=self.app.obsParser.parse_obs_sky,
args=(self.message, self.config, ),
name='obs_sky')
Expand All @@ -194,6 +215,7 @@ async def __async__decodeMessage(self):
if 'obs_out_air' in self.thread_list:
while self.thread_list['obs_out_air'].is_alive():
await asyncio.sleep(0.1)
self.watchdog_list['obs_out_air'] = time.time()
self.thread_list['obs_out_air'] = threading.Thread(target=self.app.obsParser.parse_obs_out_air,
args=(self.message, self.config, ),
name='obs_out_air')
Expand All @@ -202,11 +224,13 @@ async def __async__decodeMessage(self):
if 'obs_in_air' in self.thread_list:
while self.thread_list['obs_in_air'].is_alive():
await asyncio.sleep(0.1)
self.watchdog_list['obs_in_air'] = time.time()
self.thread_list['obs_in_air'] = threading.Thread(target=self.app.obsParser.parse_obs_in_air,
args=(self.message, self.config, ),
name='obs_in_air')
self.thread_list['obs_in_air'].start()
elif self.message['type'] == 'rapid_wind':
self.watchdog_list['rapid_wind'] = time.time()
self.app.obsParser.parse_rapid_wind(self.message, self.config)
elif self.message['type'] == 'evt_strike':
self.app.obsParser.parse_evt_strike(self.message, self.config)
Expand All @@ -223,6 +247,7 @@ async def __async__listen(self):
try:
while self._keep_running:
self.message = await self.__async__getMessage()
await self.__async__watchdog()
await self.__async__decodeMessage()
except asyncio.CancelledError:
raise
Expand Down

0 comments on commit 10e4ad9

Please sign in to comment.