implement cardunlock

This commit is contained in:
joBr99
2023-11-28 16:41:26 +01:00
parent 51dd978c8c
commit d7e417eaf7
3 changed files with 360 additions and 329 deletions

View File

@@ -533,6 +533,30 @@ class AlarmCard(HACard):
result = f"{self.title}~{self.gen_nav()}~{main_entity.entity_id}{arm_buttons}~{icon}~{color}~{numpad}~{flashing}~{add_btn}" result = f"{self.title}~{self.gen_nav()}~{main_entity.entity_id}{arm_buttons}~{icon}~{color}~{numpad}~{flashing}~{add_btn}"
libs.panel_cmd.entityUpd(self.panel.sendTopic, result) libs.panel_cmd.entityUpd(self.panel.sendTopic, result)
class UnlockCard(HACard):
def __init__(self, locale, config, panel):
super().__init__(locale, config, panel)
def render(self):
color = rgb_dec565([255,0,0])
icon = get_icon_char("lock")
supported_modes = ["cardUnlock-unlock"]
entity_id = self.config.get("entity")
# add padding to arm buttons
arm_buttons = ""
for b in supported_modes:
arm_buttons += f'~{get_translation(self.locale, "frontend.ui.card.lock.unlock")}~{b}'
if len(supported_modes) < 4:
arm_buttons += "~"*((4-len(supported_modes))*2)
numpad = "enable"
result = f"{self.title}~{self.gen_nav()}~{entity_id}{arm_buttons}~{icon}~{color}~{numpad}~disable~"
libs.panel_cmd.entityUpd(self.panel.sendTopic, result)
class Screensaver(HACard): class Screensaver(HACard):
def __init__(self, locale, config, panel): def __init__(self, locale, config, panel):
super().__init__(locale, config, panel) super().__init__(locale, config, panel)
@@ -594,6 +618,8 @@ def card_factory(locale, settings, panel):
card = ClimateCard(locale, settings, panel) card = ClimateCard(locale, settings, panel)
case 'cardAlarm': case 'cardAlarm':
card = AlarmCard(locale, settings, panel) card = AlarmCard(locale, settings, panel)
case 'cardUnlock':
card = UnlockCard(locale, settings, panel)
case _: case _:
logging.error("card type %s not implemented", settings["type"]) logging.error("card type %s not implemented", settings["type"])
return "NotImplemented", None return "NotImplemented", None

View File

@@ -246,6 +246,12 @@ class LovelaceUIPanel:
# send ha stuff to ha # send ha stuff to ha
case _: case _:
ha_control.handle_buttons(entity_id, btype, value) ha_control.handle_buttons(entity_id, btype, value)
case 'cardUnlock-unlock':
card_iid = entity_id.split(".")[1]
if int(self.current_card.config.get("pin")) == int(value):
self.privious_cards.append(self.current_card)
self.current_card = self.searchCard(card_iid)
self.render_current_page(switchPages=True)
case _: case _:
ha_control.handle_buttons(entity_id, btype, value) ha_control.handle_buttons(entity_id, btype, value)

View File

@@ -19,7 +19,6 @@ class Card:
def render(self): def render(self):
raise NotImplementedError raise NotImplementedError
class Entity: class Entity:
def __init__(self, locale, config, panel): def __init__(self, locale, config, panel):
self.iid = iid() self.iid = iid()