Updated kodi settings on Lenovo
This commit is contained in:
@@ -7,6 +7,7 @@ from concurrent.futures import ThreadPoolExecutor
|
||||
|
||||
from . import config
|
||||
from . import utils
|
||||
from . import conv
|
||||
|
||||
class Main():
|
||||
|
||||
@@ -79,28 +80,44 @@ class Main():
|
||||
if self.mode == 'kodi':
|
||||
utils.monitor.waitForService()
|
||||
|
||||
# Note: Setting window properties is CPU bound, using threads seems to be slower
|
||||
# This needs more testing ...
|
||||
# with ThreadPoolExecutor(3) as pool:
|
||||
# pool.map(self.setdata, config.map)
|
||||
for map in config.map:
|
||||
self.setdata(map)
|
||||
# KODI
|
||||
if not config.addon.full:
|
||||
for map in config.map:
|
||||
self.setdata(map)
|
||||
|
||||
# Alerts
|
||||
for map in config.map:
|
||||
self.setalert(map)
|
||||
self.setother()
|
||||
utils.setprops()
|
||||
|
||||
# Properties
|
||||
self.setprop()
|
||||
# SKIN
|
||||
if config.addon.skin:
|
||||
config.addon.api = True
|
||||
config.loc.prop = {}
|
||||
|
||||
for map in config.map:
|
||||
self.setdata(map)
|
||||
|
||||
self.setother()
|
||||
utils.setprops()
|
||||
|
||||
# Update locs
|
||||
elif self.mode == 'updatelocs':
|
||||
|
||||
# KODI
|
||||
self.setlocs()
|
||||
utils.setprops()
|
||||
|
||||
# SKIN
|
||||
if config.addon.skin:
|
||||
config.addon.api = True
|
||||
config.loc.prop = {}
|
||||
|
||||
self.setlocs()
|
||||
utils.setprops()
|
||||
|
||||
# Notification (Queue)
|
||||
elif self.mode == 'msgqueue':
|
||||
for map in config.map:
|
||||
self.setalert(map)
|
||||
self.msgqueue(map)
|
||||
|
||||
# Notification (Send)
|
||||
elif self.mode == 'msgsend':
|
||||
@@ -123,7 +140,8 @@ class Main():
|
||||
self.today = utils.dt('nowloc').strftime('%Y-%m-%d')
|
||||
|
||||
# Directory
|
||||
os.makedirs(f'{config.addon_cache}/{locid}', exist_ok=True)
|
||||
p = Path(f'{config.addon_cache}/{locid}')
|
||||
p.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
### GET DATA
|
||||
def getdata(self, type):
|
||||
@@ -154,7 +172,7 @@ class Main():
|
||||
self.setmap(type, map)
|
||||
|
||||
# Current (Advanced)
|
||||
elif map[0] == 'currentskin' and config.addon.skin:
|
||||
elif map[0] == 'currentskin' and config.addon.api:
|
||||
self.setmap(type, map)
|
||||
|
||||
# Current (KODI)
|
||||
@@ -169,7 +187,7 @@ class Main():
|
||||
self.setmulti(type, [ map, 'hourly', indexmid, config.maxhours, config.minhours, 'hour' ])
|
||||
|
||||
# Hourly (Advanced)
|
||||
elif map[0] == 'hourlyskin' and config.addon.skin:
|
||||
elif map[0] == 'hourlyskin' and config.addon.api:
|
||||
self.setmulti(type, [ map, 'hourly', indexnow, config.maxhours, config.minhours, 'hourly' ])
|
||||
|
||||
if config.addon.enablehour:
|
||||
@@ -178,18 +196,31 @@ class Main():
|
||||
# Daily (Compatibility)
|
||||
elif map[0] == 'daily':
|
||||
self.setmulti(type, [ map, 'daily', indexday, config.maxdays, config.mindays, 'daily' ])
|
||||
self.setmulti(type, [ map, 'daily', indexday, config.maxdays, config.mindays, 'day' ])
|
||||
|
||||
if not config.addon.api:
|
||||
self.setmulti(type, [ map, 'daily', indexday, config.maxdays, config.mindays, 'day' ])
|
||||
|
||||
# Daily (Advanced)
|
||||
elif map[0] == 'dailyskin' and config.addon.skin:
|
||||
elif map[0] == 'dailyskin' and config.addon.api:
|
||||
self.setmulti(type, [ map, 'daily', indexday, config.maxdays, config.mindays, 'daily' ])
|
||||
self.setmulti(type, [ map, 'daily', indexday, config.maxdays, config.mindays, 'day' ])
|
||||
|
||||
# Daily (KODI)
|
||||
elif map[0] == 'dailykodi' and self.mode == 'kodi':
|
||||
self.setmulti(type, [ map, 'daily', indexday, config.maxdays, config.mindays, 'daily' ])
|
||||
self.setmulti(type, [ map, 'daily', indexday, config.maxdays, config.mindays, 'day' ])
|
||||
|
||||
# TimeOfDay
|
||||
elif map[0] == 'timeofday':
|
||||
self.setmap(type, map)
|
||||
|
||||
# Graph
|
||||
elif map[0] == 'graph':
|
||||
self.setmap(type, map)
|
||||
|
||||
# Alert
|
||||
if map[3] == 'graph':
|
||||
self.setalert(type, [ map, indexnow ])
|
||||
|
||||
### SET CURRENT
|
||||
def setcurrent(self, type, locid):
|
||||
|
||||
@@ -209,7 +240,7 @@ class Main():
|
||||
self.setmap(type, map, locid=locid)
|
||||
|
||||
# Current (Advanced)
|
||||
elif map[0] == 'currentskin' and config.addon.skin:
|
||||
elif map[0] == 'currentskin' and config.addon.api:
|
||||
self.setmap(type, map, locid=locid)
|
||||
|
||||
### SET LOCATIONS
|
||||
@@ -224,40 +255,174 @@ class Main():
|
||||
|
||||
# Set "Current.X" only if called from service
|
||||
if self.mode != 'kodi':
|
||||
config.loc(locid)
|
||||
for map in config.map:
|
||||
self.setcurrent(map, locid)
|
||||
|
||||
if locuser:
|
||||
utils.setprop(f'location{locid}', locuser)
|
||||
utils.addprop(f'location{locid}', locuser)
|
||||
else:
|
||||
utils.setprop(f'location{locid}', loc)
|
||||
utils.addprop(f'location{locid}', loc)
|
||||
else:
|
||||
utils.setprop(f'location{locid}', '')
|
||||
utils.addprop(f'location{locid}', '')
|
||||
|
||||
utils.setprop('locations', locs)
|
||||
utils.addprop('locations', locs)
|
||||
|
||||
### SET ALERT
|
||||
def setalert(self, type):
|
||||
## SET ALERT
|
||||
def setalert(self, src, map):
|
||||
winprops = [ 'name', 'value', 'icon', 'unit', 'time', 'hours', 'status' ]
|
||||
|
||||
data = self.data[src]
|
||||
type = map[0][2][1]
|
||||
idx = map[1]
|
||||
prop = config.alert.map[type]['type']
|
||||
unit = config.alert.map[type]['unit']
|
||||
icon = config.alert.map[type]['icon']
|
||||
name = utils.locaddon(config.alert.map[type]['loc'])
|
||||
hours = 0
|
||||
code = 0
|
||||
value = 0
|
||||
|
||||
# Invalid index
|
||||
if not idx:
|
||||
utils.log('Index invalid, weather data is not up to date ...', 3)
|
||||
return
|
||||
|
||||
# Alert disabled
|
||||
if not utils.setting(f'alert_{prop}_enabled', 'bool', True):
|
||||
utils.log(f'Disabled alert: {prop}', 3)
|
||||
|
||||
utils.addprop(f'alert.{prop}', '')
|
||||
for winprop in winprops:
|
||||
utils.addprop(f'alert.{prop}.{winprop}', '')
|
||||
|
||||
return
|
||||
|
||||
# Checking alert
|
||||
utils.log(f'Checking alert: {prop}', 3)
|
||||
l = []
|
||||
ll = []
|
||||
|
||||
for index in range(idx, idx + config.addon.alerthours):
|
||||
|
||||
try:
|
||||
v = int(data[map[0][1][0]][map[0][1][1]][index])
|
||||
vv = int(data[map[0][1][0]]['time'][index])
|
||||
except:
|
||||
if not self.mode == 'msgqueue':
|
||||
utils.addprop(f'alert.{prop}', 0)
|
||||
for winprop in winprops:
|
||||
utils.addprop(f'alert.{prop}.{winprop}', '')
|
||||
return
|
||||
else:
|
||||
l.append(v)
|
||||
ll.append(vv)
|
||||
|
||||
for c, d in [(x, y) for x in [ 3, 2, 1 ] for y in [ 'high', 'low', 'wmo' ] ]:
|
||||
alert = f'alert_{prop}_{d}_{c}'
|
||||
last = False
|
||||
|
||||
try:
|
||||
if d == 'wmo':
|
||||
limit = list(config.alert.map[type][alert].split(' '))
|
||||
else:
|
||||
limit = int(config.alert.map[type][alert])
|
||||
except:
|
||||
continue
|
||||
|
||||
for idx, v in enumerate(l):
|
||||
|
||||
if d == 'high':
|
||||
if v >= limit:
|
||||
hours += 1
|
||||
if last and v > last:
|
||||
code, value, last, stamp = c, v, v, ll[idx]
|
||||
elif not last:
|
||||
code, value, last, stamp = c, v, v, ll[idx]
|
||||
elif d == 'low':
|
||||
if v <= limit:
|
||||
hours += 1
|
||||
if last and v < last:
|
||||
code, value, last, stamp = c, v, v, ll[idx]
|
||||
elif not last:
|
||||
code, value, last, stamp = c, v, v, ll[idx]
|
||||
elif d == 'wmo':
|
||||
for wmo in limit:
|
||||
if v == int(wmo):
|
||||
hours += 1
|
||||
if last and v > last:
|
||||
code, value, last, stamp = c, v, v, ll[idx]
|
||||
elif not last:
|
||||
code, value, last, stamp = c, v, v, ll[idx]
|
||||
if hours:
|
||||
break
|
||||
|
||||
# Check alert code
|
||||
if code != 0:
|
||||
icon = f'{icon}{code}'
|
||||
time = conv.time('time', stamp)
|
||||
|
||||
if prop == 'condition':
|
||||
icon = f'{config.map_alert_condition.get(value)}{code}'
|
||||
value = config.localization.wmo.get(f'{value}d')
|
||||
else:
|
||||
value, unit = conv.item(value, unit)
|
||||
|
||||
# Notification Queue
|
||||
if self.mode == 'msgqueue':
|
||||
if code == 1 and utils.setting(f'alert_{prop}_notice', 'bool'):
|
||||
config.addon.msgqueue.append([ f'{config.loc.short} - {utils.locaddon(32340)} ({hours} {utils.locaddon(32288)})', f'({time}) {name}: {value}{unit}', f'{config.addon_icons}/alert/{icon}.png' ])
|
||||
elif code == 2 and utils.setting(f'alert_{prop}_caution', 'bool'):
|
||||
config.addon.msgqueue.append([ f'{config.loc.short} - {utils.locaddon(32341)} ({hours} {utils.locaddon(32288)})', f'({time}) {name}: {value}{unit}', f'{config.addon_icons}/alert/{icon}.png' ])
|
||||
elif code == 3 and utils.setting(f'alert_{prop}_danger', 'bool'):
|
||||
config.addon.msgqueue.append([ f'{config.loc.short} - {utils.locaddon(32342)} ({hours} {utils.locaddon(32288)})', f'({time}) {name}: {value}{unit}', f'{config.addon_icons}/alert/{icon}.png' ])
|
||||
|
||||
return
|
||||
|
||||
# Set alert properties
|
||||
utils.log(f'Updating alert: {prop} = {code}', 3)
|
||||
config.addon.alerts += 1
|
||||
|
||||
utils.addprop(f'alert.{prop}', code)
|
||||
utils.addprop(f'alert.{prop}.name', name)
|
||||
utils.addprop(f'alert.{prop}.time', time)
|
||||
utils.addprop(f'alert.{prop}.hours', hours)
|
||||
utils.addprop(f'alert.{prop}.icon', f'{config.addon_icons}/alert/{icon}.png')
|
||||
utils.addprop(f'alert.{prop}.value', value)
|
||||
utils.addprop(f'alert.{prop}.unit', unit)
|
||||
|
||||
if code == 1:
|
||||
utils.addprop(f'alert.{prop}.status', utils.locaddon(32340))
|
||||
elif code == 2:
|
||||
utils.addprop(f'alert.{prop}.status', utils.locaddon(32341))
|
||||
elif code == 3:
|
||||
utils.addprop(f'alert.{prop}.status', utils.locaddon(32342))
|
||||
|
||||
else:
|
||||
if self.mode == 'msgqueue':
|
||||
return
|
||||
|
||||
utils.addprop(f'alert.{prop}', 0)
|
||||
for winprop in winprops:
|
||||
utils.addprop(f'alert.{prop}.{winprop}', '')
|
||||
|
||||
### SET QUEUE
|
||||
def msgqueue(self, type):
|
||||
|
||||
# Data
|
||||
self.data[type] = utils.getfile(f'{config.loc.id}/{type}.json')
|
||||
if not self.data[type]:
|
||||
utils.log(f'[Alert] No {type} data for location {config.loc.id}', 4)
|
||||
utils.log(f'No {type} data for location {config.loc.id}', 2)
|
||||
return
|
||||
|
||||
# Index
|
||||
idx = utils.index("now", self.data[type])
|
||||
if not idx:
|
||||
utils.log(f'[Alert] No {type} index for location {config.loc.id}', 4)
|
||||
return
|
||||
|
||||
# Notification
|
||||
loc = utils.setting(f'loc{config.loc.id}').split(',')[0]
|
||||
indexnow = utils.index("now", self.data[type])
|
||||
|
||||
# Update msgqueue
|
||||
for map in config.map.get(type):
|
||||
|
||||
# Alert
|
||||
if map[3] == 'graph':
|
||||
utils.setalert(self.data[type], map, idx, config.loc.id, config.loc.cid, loc, self.mode)
|
||||
self.setalert(type, [ map, indexnow ])
|
||||
|
||||
### SET MULTI
|
||||
def setmulti(self, src, map):
|
||||
@@ -268,11 +433,15 @@ class Main():
|
||||
min = map[4]
|
||||
prop = map[5]
|
||||
|
||||
if config.addon.skin is False and ( prop == 'hourly' or prop == 'daily' ):
|
||||
if config.addon.api is False and ( prop == 'hourly' or prop == 'daily' ):
|
||||
count = 1
|
||||
else:
|
||||
count = 0
|
||||
|
||||
if not idx:
|
||||
utils.log('Index invalid, weather data is not up to date ...', 3)
|
||||
return
|
||||
|
||||
for index in range(idx, idx + max, 1):
|
||||
map[0][2][0] = prop
|
||||
self.setmap(src, map[0], index, count)
|
||||
@@ -305,18 +474,20 @@ class Main():
|
||||
content = utils.getprop(data, map, idx, count)
|
||||
except TypeError as e:
|
||||
utils.log(f'{property}: {type(e).__name__} {e}', 4)
|
||||
utils.clrprop(property)
|
||||
utils.addprop(property, '')
|
||||
except Exception as e:
|
||||
utils.log(f'{property}: {type(e).__name__} {e}', 3)
|
||||
utils.clrprop(property)
|
||||
utils.addprop(property, '')
|
||||
else:
|
||||
utils.setprop(property, content)
|
||||
utils.addprop(property, content)
|
||||
|
||||
### GET MAP
|
||||
def getmap(self, type):
|
||||
|
||||
if not utils.setting(f'map{type}', 'bool'):
|
||||
return
|
||||
# Layers disabled
|
||||
if not type == 'osm':
|
||||
if not utils.setting(f'map{type}', 'bool') or not utils.setting(f'loc{config.loc.id}maps', 'bool'):
|
||||
return
|
||||
|
||||
# Check connectivity
|
||||
if not api.network():
|
||||
@@ -362,7 +533,7 @@ class Main():
|
||||
|
||||
dir = f'{config.addon_cache}/{config.loc.id}'
|
||||
files = sorted(list(Path(dir).glob(f'{type}_*')), reverse=True)
|
||||
history = config.addon.maphistory * 2
|
||||
history = config.addon.maphistory
|
||||
|
||||
for idx in range(0,100):
|
||||
|
||||
@@ -376,18 +547,28 @@ class Main():
|
||||
os.remove(file)
|
||||
|
||||
### PROPERTIES
|
||||
def setprop(self):
|
||||
def setother(self):
|
||||
|
||||
# Maps
|
||||
index = 1
|
||||
if config.addon.api:
|
||||
index = 0
|
||||
else:
|
||||
index = 1
|
||||
|
||||
for layer in config.map_layers:
|
||||
|
||||
if not utils.setting(f'map{layer}', 'bool'):
|
||||
# Layers disabled
|
||||
if not utils.setting(f'map{layer}', 'bool') or not utils.setting(f'loc{config.loc.id}maps', 'bool'):
|
||||
for item in [ 'area', 'layer', 'heading', 'time', 'legend' ]:
|
||||
utils.addprop(f'Map.{index}.{item}', '')
|
||||
|
||||
index += 1
|
||||
continue
|
||||
|
||||
# Files
|
||||
dir = f'{config.addon_cache}/{config.loc.id}'
|
||||
files = sorted(list(Path(dir).glob(f'{layer}_*')), reverse=True)
|
||||
history = config.addon.maphistory * 2
|
||||
history = config.addon.maphistory
|
||||
|
||||
# Area
|
||||
if files:
|
||||
@@ -396,14 +577,14 @@ class Main():
|
||||
date = tz.strftime(config.kodi.date)
|
||||
time = tz.strftime(config.kodi.time)
|
||||
|
||||
utils.setprop(f'Map.{index}.Area', f'{dir}/osm.png')
|
||||
utils.setprop(f'Map.{index}.Layer', f'{dir}/{layer}_{ut}.png')
|
||||
utils.setprop(f'Map.{index}.Heading', config.localization.layers.get(layer))
|
||||
utils.setprop(f'Map.{index}.Time', f'{date} {time}')
|
||||
utils.setprop(f'Map.{index}.Legend', '')
|
||||
utils.addprop(f'Map.{index}.Area', f'{dir}/osm.png')
|
||||
utils.addprop(f'Map.{index}.Layer', f'{dir}/{layer}_{ut}.png')
|
||||
utils.addprop(f'Map.{index}.Heading', config.localization.layers.get(layer))
|
||||
utils.addprop(f'Map.{index}.Time', f'{date} {time}')
|
||||
utils.addprop(f'Map.{index}.Legend', '')
|
||||
else:
|
||||
for item in [ 'area', 'layer', 'heading', 'time', 'legend' ]:
|
||||
utils.setprop(f'Map.{index}.{item}', '')
|
||||
utils.addprop(f'Map.{index}.{item}', '')
|
||||
|
||||
# Layers
|
||||
for idx in range(0, history):
|
||||
@@ -411,39 +592,39 @@ class Main():
|
||||
try:
|
||||
file = files[idx]
|
||||
except:
|
||||
utils.setprop(f'Map.{index}.Layer.{idx}', '')
|
||||
utils.setprop(f'Map.{index}.Time.{idx}', '')
|
||||
utils.addprop(f'Map.{index}.Layer.{idx}', '')
|
||||
utils.addprop(f'Map.{index}.Time.{idx}', '')
|
||||
else:
|
||||
ut = int(file.stem.split('_')[1])
|
||||
tz = utils.dt('stamploc', ut)
|
||||
date = tz.strftime(config.kodi.date)
|
||||
time = tz.strftime(config.kodi.time)
|
||||
|
||||
utils.setprop(f'Map.{index}.Layer.{idx}', f'{dir}/{layer}_{ut}.png')
|
||||
utils.setprop(f'Map.{index}.Time.{idx}', f'{date} {time}')
|
||||
utils.addprop(f'Map.{index}.Layer.{idx}', f'{dir}/{layer}_{ut}.png')
|
||||
utils.addprop(f'Map.{index}.Time.{idx}', f'{date} {time}')
|
||||
|
||||
index += 1
|
||||
|
||||
# Locations
|
||||
if config.loc.user:
|
||||
utils.setprop('current.location', config.loc.user)
|
||||
utils.setprop('location', config.loc.user)
|
||||
else:
|
||||
utils.setprop('current.location', config.loc.name.split(',')[0])
|
||||
utils.setprop('location', config.loc.name)
|
||||
|
||||
utils.addprop('current.location', config.loc.name)
|
||||
utils.addprop('location', config.loc.name)
|
||||
self.setlocs()
|
||||
|
||||
# Fetched
|
||||
for prop in [ 'current', 'weather', 'hourly', 'daily', 'map' ]:
|
||||
utils.setprop(f'{prop}.isfetched', 'true')
|
||||
for prop in [ 'current', 'weather', 'hourly', 'daily', 'timeofday', 'map' ]:
|
||||
utils.addprop(f'{prop}.isfetched', 'true')
|
||||
|
||||
# Other
|
||||
utils.setprop('alerts', config.addon.alerts)
|
||||
utils.setprop('addon.icons', config.addon.icons)
|
||||
utils.setprop('addon.iconsdir', config.addon_icons)
|
||||
utils.setprop('WeatherProvider', 'open-meteo.com, rainviewer.com, weather.gc.ca, met.no')
|
||||
utils.setprop('WeatherProviderLogo', f'{config.addon_path}/resources/banner.png')
|
||||
utils.addprop('alerts', config.addon.alerts)
|
||||
|
||||
if config.addon.api:
|
||||
utils.addprop('icons', config.addon.icons)
|
||||
utils.addprop('iconsdir', config.addon_icons)
|
||||
utils.addprop('Provider', 'open-meteo.com, rainviewer.com, weather.gc.ca, met.no')
|
||||
utils.addprop('ProviderLogo', f'{config.addon_path}/resources/banner.png')
|
||||
else:
|
||||
utils.addprop('WeatherProvider', 'open-meteo.com, rainviewer.com, weather.gc.ca, met.no')
|
||||
utils.addprop('WeatherProviderLogo', f'{config.addon_path}/resources/banner.png')
|
||||
|
||||
### NOTIFICATION
|
||||
def notification(self):
|
||||
|
||||
Reference in New Issue
Block a user