diff --git a/tasmota/berry/lorawan/decoders/LwDecode.be b/tasmota/berry/lorawan/decoders/LwDecode.be index fa7c8216a..79223edbd 100644 --- a/tasmota/berry/lorawan/decoders/LwDecode.be +++ b/tasmota/berry/lorawan/decoders/LwDecode.be @@ -5,7 +5,6 @@ var LwRegions = ["EU868", "US915", "IN865","AU915","KZ865","RU864","AS923", "AS9 var LwDeco import mqtt -import string class lwdecode_cls var thisDevice @@ -59,9 +58,7 @@ class lwdecode_cls var unit = "d" if since > (24 * 3600) since /= (24 * 3600) - if since > 99 - since = 99 - end + if since > 99 since = 99 end elif since > 3600 since /= 3600 unit = "h" @@ -69,42 +66,38 @@ class lwdecode_cls since /= 60 unit = "m" end - return string.format("%02d%s", since, unit) + return format("%02d%s", since, unit) end def header(name, name_tooltip, battery, battery_last_seen, rssi, last_seen) var color_text = f'{tasmota.webcolor(0 #-COL_TEXT-#)}' # '#eaeaea' - var msg = string.format("") # ==== Start first table row - msg += string.format("%s", name_tooltip, name) - if (battery < 1000) + var msg = "" # ==== Start first table row + msg += format("%s", name_tooltip, name) + if battery < 1000 # Battery low <= 2.5V (0%), high >= 3.1V (100%) var batt_percent = (battery * 1000) - 2500 batt_percent /= 6 # 3.1V - 2.5V = 0.6V = 100% - if batt_percent < 0 - batt_percent = 0 - end - if batt_percent > 100 - batt_percent = 100 - end - batt_percent /= 7.14 # 1..14px showing battery load - msg += string.format("", - battery, self.dhm(battery_last_seen), batt_percent, color_text) + if batt_percent < 0 batt_percent = 0 end + if batt_percent > 98 batt_percent = 98 end # 98% / 14px = 7 + batt_percent /= 7 # 1..14px showing battery load + msg += format("", + battery, self.dhm(battery_last_seen), batt_percent, color_text) else msg += " " end if rssi < 1000 + if rssi < -132 rssi = -132 end var num_bars = 4 - ((rssi * -1) / 33) - msg += string.format("
",rssi) + msg += format("
", rssi) for j:0..3 - msg += string.format("", - j, (num_bars < j) ? " o30" : "") # Bars + msg += format("", j, (num_bars < j) ? " o30" : "") # Bars end - msg += string.format("
") # Close RSSI + msg += "
" # Close RSSI else msg += " " end - msg += string.format("🕗%s", # Clock - color_text, self.dhm(last_seen)) + msg += format("🕗%s", # Clock + color_text, self.dhm(last_seen)) msg += "" # ==== End first table row return msg end #sensor() @@ -114,30 +107,28 @@ class lwdecode_cls Called every WebRefresh time ------------------------------------------------------------# def web_sensor() - import string - var msg = "" for decoder: self.LwDecoders msg += decoder.add_web_sensor() end if msg var color_text = f'{tasmota.webcolor(0 #-COL_TEXT-#)}' # '#eaeaea' - var full_msg = string.format("".. # Terminate current two column table and open new table - "".. - "{t}", # Open new table + ".si{display:inline-flex;align-items:flex-end;height:15px;padding:0}" + ".si i{width:3px;margin-right:1px;border-radius:3px;background-color:%s}" # WebColor(COL_TEXT) + ".si .b0{height:25%%}.si .b1{height:50%%}.si .b2{height:75%%}.si .b3{height:100%%}.o30{opacity:.3}" + "" + "{t}", # Open new table color_text) full_msg += msg - full_msg += "{t}" # Close table and open new table + full_msg += "{t}" # Close table and open new table tasmota.web_send_decimal(full_msg) end