mirror of
https://github.com/arendst/Tasmota.git
synced 2025-07-19 08:46:32 +00:00
Berryfy code
This commit is contained in:
parent
b90ef3b400
commit
04302414c8
@ -5,7 +5,6 @@ var LwRegions = ["EU868", "US915", "IN865","AU915","KZ865","RU864","AS923", "AS9
|
|||||||
var LwDeco
|
var LwDeco
|
||||||
|
|
||||||
import mqtt
|
import mqtt
|
||||||
import string
|
|
||||||
|
|
||||||
class lwdecode_cls
|
class lwdecode_cls
|
||||||
var thisDevice
|
var thisDevice
|
||||||
@ -59,9 +58,7 @@ class lwdecode_cls
|
|||||||
var unit = "d"
|
var unit = "d"
|
||||||
if since > (24 * 3600)
|
if since > (24 * 3600)
|
||||||
since /= (24 * 3600)
|
since /= (24 * 3600)
|
||||||
if since > 99
|
if since > 99 since = 99 end
|
||||||
since = 99
|
|
||||||
end
|
|
||||||
elif since > 3600
|
elif since > 3600
|
||||||
since /= 3600
|
since /= 3600
|
||||||
unit = "h"
|
unit = "h"
|
||||||
@ -69,42 +66,38 @@ class lwdecode_cls
|
|||||||
since /= 60
|
since /= 60
|
||||||
unit = "m"
|
unit = "m"
|
||||||
end
|
end
|
||||||
return string.format("%02d%s", since, unit)
|
return format("%02d%s", since, unit)
|
||||||
end
|
end
|
||||||
|
|
||||||
def header(name, name_tooltip, battery, battery_last_seen, rssi, last_seen)
|
def header(name, name_tooltip, battery, battery_last_seen, rssi, last_seen)
|
||||||
var color_text = f'{tasmota.webcolor(0 #-COL_TEXT-#)}' # '#eaeaea'
|
var color_text = f'{tasmota.webcolor(0 #-COL_TEXT-#)}' # '#eaeaea'
|
||||||
var msg = string.format("<tr class='ltd htr'>") # ==== Start first table row
|
var msg = "<tr class='ltd htr'>" # ==== Start first table row
|
||||||
msg += string.format("<td><b title='%s'>%s</b></td>", name_tooltip, name)
|
msg += format("<td><b title='%s'>%s</b></td>", name_tooltip, name)
|
||||||
if (battery < 1000)
|
if battery < 1000
|
||||||
# Battery low <= 2.5V (0%), high >= 3.1V (100%)
|
# Battery low <= 2.5V (0%), high >= 3.1V (100%)
|
||||||
var batt_percent = (battery * 1000) - 2500
|
var batt_percent = (battery * 1000) - 2500
|
||||||
batt_percent /= 6 # 3.1V - 2.5V = 0.6V = 100%
|
batt_percent /= 6 # 3.1V - 2.5V = 0.6V = 100%
|
||||||
if batt_percent < 0
|
if batt_percent < 0 batt_percent = 0 end
|
||||||
batt_percent = 0
|
if batt_percent > 98 batt_percent = 98 end # 98% / 14px = 7
|
||||||
end
|
batt_percent /= 7 # 1..14px showing battery load
|
||||||
if batt_percent > 100
|
msg += format("<td><i class=\"bt\" title=\"%.3fV (%s)\" style=\"--bl:%dpx;color:%s\"></i></td>",
|
||||||
batt_percent = 100
|
battery, self.dhm(battery_last_seen), batt_percent, color_text)
|
||||||
end
|
|
||||||
batt_percent /= 7.14 # 1..14px showing battery load
|
|
||||||
msg += string.format("<td><i class=\"bt\" title=\"%.3fV (%s)\" style=\"--bl:%dpx;color:%s\"></i></td>",
|
|
||||||
battery, self.dhm(battery_last_seen), batt_percent, color_text)
|
|
||||||
else
|
else
|
||||||
msg += "<td> </td>"
|
msg += "<td> </td>"
|
||||||
end
|
end
|
||||||
if rssi < 1000
|
if rssi < 1000
|
||||||
|
if rssi < -132 rssi = -132 end
|
||||||
var num_bars = 4 - ((rssi * -1) / 33)
|
var num_bars = 4 - ((rssi * -1) / 33)
|
||||||
msg += string.format("<td><div title='RSSI %i' class='si'>",rssi)
|
msg += format("<td><div title='RSSI %i' class='si'>", rssi)
|
||||||
for j:0..3
|
for j:0..3
|
||||||
msg += string.format("<i class='b%d%s'></i>",
|
msg += format("<i class='b%d%s'></i>", j, (num_bars < j) ? " o30" : "") # Bars
|
||||||
j, (num_bars < j) ? " o30" : "") # Bars
|
|
||||||
end
|
end
|
||||||
msg += string.format("</div></td>") # Close RSSI
|
msg += "</div></td>" # Close RSSI
|
||||||
else
|
else
|
||||||
msg += "<td> </td>"
|
msg += "<td> </td>"
|
||||||
end
|
end
|
||||||
msg += string.format("<td style='color:%s'>🕗%s</td>", # Clock
|
msg += format("<td style='color:%s'>🕗%s</td>", # Clock
|
||||||
color_text, self.dhm(last_seen))
|
color_text, self.dhm(last_seen))
|
||||||
msg += "</tr>" # ==== End first table row
|
msg += "</tr>" # ==== End first table row
|
||||||
return msg
|
return msg
|
||||||
end #sensor()
|
end #sensor()
|
||||||
@ -114,30 +107,28 @@ class lwdecode_cls
|
|||||||
Called every WebRefresh time
|
Called every WebRefresh time
|
||||||
------------------------------------------------------------#
|
------------------------------------------------------------#
|
||||||
def web_sensor()
|
def web_sensor()
|
||||||
import string
|
|
||||||
|
|
||||||
var msg = ""
|
var msg = ""
|
||||||
for decoder: self.LwDecoders
|
for decoder: self.LwDecoders
|
||||||
msg += decoder.add_web_sensor()
|
msg += decoder.add_web_sensor()
|
||||||
end
|
end
|
||||||
if msg
|
if msg
|
||||||
var color_text = f'{tasmota.webcolor(0 #-COL_TEXT-#)}' # '#eaeaea'
|
var color_text = f'{tasmota.webcolor(0 #-COL_TEXT-#)}' # '#eaeaea'
|
||||||
var full_msg = string.format("</table>".. # Terminate current two column table and open new table
|
var full_msg = format("</table>" # Terminate current two column table and open new table
|
||||||
"<style>"..
|
"<style>"
|
||||||
# Table CSS
|
# Table CSS
|
||||||
".ltd td:not(:first-child){width:20px;font-size:70%%}"..
|
".ltd td:not(:first-child){width:20px;font-size:70%%}"
|
||||||
".ltd td:last-child{width:45px}"..
|
".ltd td:last-child{width:45px}"
|
||||||
".ltd .bt{margin-right:10px;}".. # Margin right should be half of the not-first width
|
".ltd .bt{margin-right:10px;}" # Margin right should be half of the not-first width
|
||||||
".htr{line-height:20px}"..
|
".htr{line-height:20px}"
|
||||||
# Signal Strength Indicator
|
# Signal Strength Indicator
|
||||||
".si{display:inline-flex;align-items:flex-end;height:15px;padding:0}"..
|
".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 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}"..
|
".si .b0{height:25%%}.si .b1{height:50%%}.si .b2{height:75%%}.si .b3{height:100%%}.o30{opacity:.3}"
|
||||||
"</style>"..
|
"</style>"
|
||||||
"{t}", # Open new table
|
"{t}", # Open new table
|
||||||
color_text)
|
color_text)
|
||||||
full_msg += msg
|
full_msg += msg
|
||||||
full_msg += "</table>{t}" # Close table and open new table
|
full_msg += "</table>{t}" # Close table and open new table
|
||||||
|
|
||||||
tasmota.web_send_decimal(full_msg)
|
tasmota.web_send_decimal(full_msg)
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user