implemented server side rendering of alarm page content #81

This commit is contained in:
Johannes
2022-03-28 15:58:37 +02:00
parent a742fbb2ae
commit f0bdc3c8ac
7 changed files with 59 additions and 2 deletions

View File

@@ -129,7 +129,7 @@ The following message can be used to update the content on the cardEntities Page
### cardAlarm Page
`entityUpd,*internalNameEntity*,*arm1*,*arm1ActionName*,*arm2*,*arm2ActionName*,*arm3*,*arm3ActionName*,*arm4*,*arm4ActionName*,*icon*,*numpadStatus*`
`entityUpd,*internalNameEntity*,*arm1*,*arm1ActionName*,*arm2*,*arm2ActionName*,*arm3*,*arm3ActionName*,*arm4*,*arm4ActionName*,*icon*,*iconcolor*,*numpadStatus*`
## Messages from Nextion Display

View File

@@ -40,7 +40,10 @@ icons = [
"shield-home",
"door-open",
"door-closed",
"window-closed"
"window-closed",
"shield-off",
"shield",
"shield-lock"
]

View File

@@ -43,3 +43,6 @@ ID | MD Icon Name | Icon
36 | door-open | ![door-open](https://raw.githubusercontent.com/Templarian/MaterialDesign-SVG/0aeb4d612644d80d9d1fe242f705f362985de5dc/svg/door-open.svg)
37 | door-closed | ![door-closed](https://raw.githubusercontent.com/Templarian/MaterialDesign-SVG/0aeb4d612644d80d9d1fe242f705f362985de5dc/svg/door-closed.svg)
38 | window-closed | ![window-closed](https://raw.githubusercontent.com/Templarian/MaterialDesign-SVG/0aeb4d612644d80d9d1fe242f705f362985de5dc/svg/window-closed.svg)
39 | shield-off | ![shield-off](https://raw.githubusercontent.com/Templarian/MaterialDesign-SVG/0aeb4d612644d80d9d1fe242f705f362985de5dc/svg/shield-off.svg)
40 | shield | ![shield](https://raw.githubusercontent.com/Templarian/MaterialDesign-SVG/0aeb4d612644d80d9d1fe242f705f362985de5dc/svg/shield.svg)
41 | shield-lock | ![shield-lock](https://raw.githubusercontent.com/Templarian/MaterialDesign-SVG/0aeb4d612644d80d9d1fe242f705f362985de5dc/svg/shield-lock.svg)

Binary file not shown.

Binary file not shown.

View File

@@ -38,6 +38,9 @@ icons = {
'door-open': 36,
'door-closed': 37,
'window-closed': 38,
'shield-off': 39,
'shield': 40,
'shield-lock': 41,
}
def get_icon_id(ma_name):

View File

@@ -252,6 +252,51 @@ class LuiPagesGen(object):
command = f"entityUpd,|{item}|{heading}|{icon}|{title}|{author}|{volume}|{iconplaypause}|{source}|{speakerlist}"
self._send_mqtt_msg(command)
def generate_alarm_page(self, item):
if not self._ha_api.entity_exists(item):
command = f"entityUpd,{item},Not found,Not found,Check your,Check your,apps.,apps.,yaml,yaml,0,,0"
else:
entity = self._ha_api.get_entity(item)
icon = get_icon_id("shield-off")
color = rgb_dec565([255,255,255])
supported_modes = []
numpad = "enable"
if entity.state == "disarmed":
color = rgb_dec565([13,160,53])
icon = get_icon_id("shield-off")
if entity.attributes.get("code_arm_required", "false") == "false":
numpad = "disable"
bits = entity.attributes.supported_features
if bits & 0b000001:
supported_modes.append("ARM HOME")
if bits & 0b000010:
supported_modes.append("ARM AWAY")
if bits & 0b000100:
supported_modes.append("ARM NIGHT")
if bits & 0b100000:
supported_modes.append("ARM VACATION")
if entity.state == "armed_home":
color = rgb_dec565([223,76,30])
icon = get_icon_id("shield-home")
supported_modes.append("DISARM")
if entity.state == "arming":
color = rgb_dec565([243,179,0])
icon = get_icon_id("shield")
supported_modes.append("DISARM")
if entity.state == "armed_away":
color = rgb_dec565([223,76,30])
icon = get_icon_id("shield-lock")
supported_modes.append("DISARM")
# add padding to arm buttons
arm_buttons = ""
for b in supported_modes:
arm_buttons += f",{b},{b}"
if len(supported_modes) < 4:
arm_buttons += ","*((4-len(supported_modes))*2)
command = f"entityUpd,{item}{arm_buttons},{icon},{color},0"
self._send_mqtt_msg(command)
def render_page(self, page, send_page_type=True):
config = page.data
page_type = config["type"]
@@ -267,6 +312,9 @@ class LuiPagesGen(object):
self.generate_thermo_page(page.data.get("item"))
if page_type == "cardMedia":
self.generate_media_page(page.data.get("item"))
if page_type == "cardAlarm":
self.generate_alarm_page(page.data.get("item"))
def generate_light_detail_page(self, entity):
entity = self._ha_api.get_entity(entity)