#!/usr/bin/python3 import cherrypy import influxdb from modules import dynamic import config class EnergyInfo(object): def __init__(self): base_url = 'https://bastart.spoton.cz/static' self.array_full = base_url + '/img/battery_full.png' #100-90 self.array_80 = base_url + '/img/battery_80.png' # 90-70 self.array_60 = base_url + '/img/battery_60.png' # 70-50 self.array_40 = base_url + '/img/battery_40.png' # 50-30 self.array_20 = base_url + '/img/battery_20.png' # 30-10 self.array_0 = base_url + '/img/battery_0.png' # 10-0 self.array_ch = base_url + '/img/battery_charging.png' self.charge_current_icon = base_url + '/img/battery_current.png' self.solar_power_icon = base_url + '/img/solar_power.png' self.battery_icon = self.array_full self.measures_obj = dynamic.DynamicEnergy() @cherrypy.expose def index(self): header = config.read_html('header', config._templates) menu_raw = config.read_html('top_menu', config._templates) menu = menu_raw.format(energy = 'active', weather = '', status = '', temphumi = '') body = self.body() footer = config.read_html('footer', config._templates) result = header\ + menu\ + body\ + footer return result def set_battery_icon(self, percentage, state): ''' Interprets % of battery state in icon changes expects: float(percentage): Percentage -> battery icon sets: str(self.battery_icon): the path to appropriate icon image ''' if state == 1: self.battery_icon = self.array_ch else: if percentage > 70.0 and percentage < 89.9: self.battery_icon = self.array_80 if percentage > 50.0 and percentage < 69.9: self.battery_icon = self.array_60 if percentage > 30.0 and percentage < 49.9: self.battery_icon = self.array_40 if percentage > 10.0 and percentage < 29.9: self.battery_icon = self.array_20 if percentage > 0.0 and percentage < 9.9: self.battery_icon = self.array_0 def tableConstructor(self, header, body): ''' The idea behind is to have a method of constructing