mirror of
https://github.com/joBr99/nspanel-lovelace-ui.git
synced 2026-02-05 04:48:54 +01:00
Fix for empty detail page after change on previous page (#662)
* Update mqtt.py Allow force sending duplicate messages * Update pages.py Allow forcing sending MQTT message when the detail page is initially generated * Update controller.py Set is_open_detail to True when generate_xx_detail_page is called from detail_open
This commit is contained in:
@@ -180,17 +180,18 @@ class LuiController(object):
|
|||||||
|
|
||||||
def detail_open(self, detail_type, entity_id):
|
def detail_open(self, detail_type, entity_id):
|
||||||
if detail_type == "popupShutter":
|
if detail_type == "popupShutter":
|
||||||
self._pages_gen.generate_shutter_detail_page(entity_id)
|
self._pages_gen.generate_shutter_detail_page(entity_id, True)
|
||||||
if detail_type == "popupLight":
|
if detail_type == "popupLight":
|
||||||
self._pages_gen.generate_light_detail_page(entity_id)
|
self._pages_gen.generate_light_detail_page(entity_id, True)
|
||||||
if detail_type == "popupFan":
|
if detail_type == "popupFan":
|
||||||
self._pages_gen.generate_fan_detail_page(entity_id)
|
self._pages_gen.generate_fan_detail_page(entity_id, True)
|
||||||
if detail_type == "popupThermo":
|
if detail_type == "popupThermo":
|
||||||
self._pages_gen.generate_thermo_detail_page(entity_id)
|
self._pages_gen.generate_thermo_detail_page(entity_id, True)
|
||||||
if detail_type == "popupInSel":
|
if detail_type == "popupInSel":
|
||||||
self._pages_gen.generate_input_select_detail_page(entity_id)
|
self._pages_gen.generate_input_select_detail_page(entity_id, True)
|
||||||
if detail_type == "popupTimer":
|
if detail_type == "popupTimer":
|
||||||
self._pages_gen.generate_timer_detail_page(entity_id)
|
self._pages_gen.generate_timer_detail_page(entity_id, True)
|
||||||
|
|
||||||
def button_press(self, entity_id, button_type, value):
|
def button_press(self, entity_id, button_type, value):
|
||||||
apis.ha_api.log(f"Button Press Event; entity_id: {entity_id}; button_type: {button_type}; value: {value} ")
|
apis.ha_api.log(f"Button Press Event; entity_id: {entity_id}; button_type: {button_type}; value: {value} ")
|
||||||
# internal buttons
|
# internal buttons
|
||||||
|
|||||||
@@ -64,8 +64,9 @@ class LuiMqttSender(object):
|
|||||||
self._topic_send = topic_send
|
self._topic_send = topic_send
|
||||||
self._prev_msg = ""
|
self._prev_msg = ""
|
||||||
|
|
||||||
def send_mqtt_msg(self, msg, topic=None):
|
def send_mqtt_msg(self, msg, topic=None, force=False):
|
||||||
if self._prev_msg == msg:
|
if not force and self._prev_msg == msg:
|
||||||
|
self._ha_api.log(f"Dropping identical consecutive message: {msg}")
|
||||||
return
|
return
|
||||||
self._prev_msg = msg
|
self._prev_msg = msg
|
||||||
if topic is None:
|
if topic is None:
|
||||||
|
|||||||
@@ -709,7 +709,7 @@ class LuiPagesGen(object):
|
|||||||
self.generate_power_page(navigation, card.title, card.entities)
|
self.generate_power_page(navigation, card.title, card.entities)
|
||||||
return
|
return
|
||||||
|
|
||||||
def generate_light_detail_page(self, entity_id):
|
def generate_light_detail_page(self, entity_id, is_open_detail=False):
|
||||||
entity = apis.ha_api.get_entity(entity_id)
|
entity = apis.ha_api.get_entity(entity_id)
|
||||||
switch_val = 1 if entity.state == "on" else 0
|
switch_val = 1 if entity.state == "on" else 0
|
||||||
icon_color = self.get_entity_color(entity)
|
icon_color = self.get_entity_color(entity)
|
||||||
@@ -744,9 +744,9 @@ class LuiPagesGen(object):
|
|||||||
color_translation = "Color"
|
color_translation = "Color"
|
||||||
brightness_translation = get_translation(self._locale, "frontend.ui.card.light.brightness")
|
brightness_translation = get_translation(self._locale, "frontend.ui.card.light.brightness")
|
||||||
color_temp_translation = get_translation(self._locale, "frontend.ui.card.light.color_temperature")
|
color_temp_translation = get_translation(self._locale, "frontend.ui.card.light.color_temperature")
|
||||||
self._send_mqtt_msg(f"entityUpdateDetail~{entity_id}~~{icon_color}~{switch_val}~{brightness}~{color_temp}~{color}~{color_translation}~{color_temp_translation}~{brightness_translation}~{effect_supported}")
|
self._send_mqtt_msg(f"entityUpdateDetail~{entity_id}~~{icon_color}~{switch_val}~{brightness}~{color_temp}~{color}~{color_translation}~{color_temp_translation}~{brightness_translation}~{effect_supported}", force=is_open_detail)
|
||||||
|
|
||||||
def generate_shutter_detail_page(self, entity_id):
|
def generate_shutter_detail_page(self, entity_id, is_open_detail=False):
|
||||||
entity = apis.ha_api.get_entity(entity_id)
|
entity = apis.ha_api.get_entity(entity_id)
|
||||||
entityType = "cover"
|
entityType = "cover"
|
||||||
device_class = entity.attributes.get("device_class", "window")
|
device_class = entity.attributes.get("device_class", "window")
|
||||||
@@ -812,9 +812,9 @@ class LuiPagesGen(object):
|
|||||||
if(tilt_pos == 100):
|
if(tilt_pos == 100):
|
||||||
iconTiltLeftStatus = "disable"
|
iconTiltLeftStatus = "disable"
|
||||||
|
|
||||||
self._send_mqtt_msg(f"entityUpdateDetail~{entity_id}~{pos}~{pos_translation}: {pos_status}~{pos_translation}~{icon_id}~{icon_up}~{icon_stop}~{icon_down}~{icon_up_status}~{icon_stop_status}~{icon_down_status}~{textTilt}~{iconTiltLeft}~{iconTiltStop}~{iconTiltRight}~{iconTiltLeftStatus}~{iconTiltStopStatus}~{iconTiltRightStatus}~{tilt_pos}")
|
self._send_mqtt_msg(f"entityUpdateDetail~{entity_id}~{pos}~{pos_translation}: {pos_status}~{pos_translation}~{icon_id}~{icon_up}~{icon_stop}~{icon_down}~{icon_up_status}~{icon_stop_status}~{icon_down_status}~{textTilt}~{iconTiltLeft}~{iconTiltStop}~{iconTiltRight}~{iconTiltLeftStatus}~{iconTiltStopStatus}~{iconTiltRightStatus}~{tilt_pos}", force=is_open_detail)
|
||||||
|
|
||||||
def generate_fan_detail_page(self, entity_id):
|
def generate_fan_detail_page(self, entity_id, is_open_detail=False):
|
||||||
entity = apis.ha_api.get_entity(entity_id)
|
entity = apis.ha_api.get_entity(entity_id)
|
||||||
switch_val = 1 if entity.state == "on" else 0
|
switch_val = 1 if entity.state == "on" else 0
|
||||||
icon_color = self.get_entity_color(entity)
|
icon_color = self.get_entity_color(entity)
|
||||||
@@ -838,9 +838,9 @@ class LuiPagesGen(object):
|
|||||||
else:
|
else:
|
||||||
preset_modes = ""
|
preset_modes = ""
|
||||||
|
|
||||||
self._send_mqtt_msg(f"entityUpdateDetail~{entity_id}~~{icon_color}~{switch_val}~{speed}~{speedMax}~{speed_translation}~{preset_mode}~{preset_modes}")
|
self._send_mqtt_msg(f"entityUpdateDetail~{entity_id}~~{icon_color}~{switch_val}~{speed}~{speedMax}~{speed_translation}~{preset_mode}~{preset_modes}", force=is_open_detail)
|
||||||
|
|
||||||
def generate_thermo_detail_page(self, entity_id):
|
def generate_thermo_detail_page(self, entity_id, is_open_detail=False):
|
||||||
icon_id = get_icon_ha(entity_id)
|
icon_id = get_icon_ha(entity_id)
|
||||||
entity = apis.ha_api.get_entity(entity_id)
|
entity = apis.ha_api.get_entity(entity_id)
|
||||||
icon_color = self.get_entity_color(entity, ha_type="climate")
|
icon_color = self.get_entity_color(entity, ha_type="climate")
|
||||||
@@ -862,9 +862,9 @@ class LuiPagesGen(object):
|
|||||||
if modes:
|
if modes:
|
||||||
modes_out += f"{heading}~{mode}~{cur_mode}~{modes_res}~"
|
modes_out += f"{heading}~{mode}~{cur_mode}~{modes_res}~"
|
||||||
|
|
||||||
self._send_mqtt_msg(f"entityUpdateDetail~{entity_id}~{icon_id}~{icon_color}~{modes_out}")
|
self._send_mqtt_msg(f"entityUpdateDetail~{entity_id}~{icon_id}~{icon_color}~{modes_out}", force=is_open_detail)
|
||||||
|
|
||||||
def generate_input_select_detail_page(self, entity_id):
|
def generate_input_select_detail_page(self, entity_id, is_open_detail=False):
|
||||||
entity = apis.ha_api.get_entity(entity_id)
|
entity = apis.ha_api.get_entity(entity_id)
|
||||||
options = []
|
options = []
|
||||||
icon_color = 0
|
icon_color = 0
|
||||||
@@ -879,9 +879,9 @@ class LuiPagesGen(object):
|
|||||||
state = entity.attributes.get("source", "")
|
state = entity.attributes.get("source", "")
|
||||||
options = entity.attributes.get("source_list", [])
|
options = entity.attributes.get("source_list", [])
|
||||||
options = "?".join(options)
|
options = "?".join(options)
|
||||||
self._send_mqtt_msg(f"entityUpdateDetail2~{entity_id}~~{icon_color}~{ha_type}~{state}~{options}~")
|
self._send_mqtt_msg(f"entityUpdateDetail2~{entity_id}~~{icon_color}~{ha_type}~{state}~{options}~", force=is_open_detail)
|
||||||
|
|
||||||
def generate_timer_detail_page(self, entity_id):
|
def generate_timer_detail_page(self, entity_id, is_open_detail=False):
|
||||||
if isinstance(entity_id, dict):
|
if isinstance(entity_id, dict):
|
||||||
entity_id = entity_id["entity_id"]
|
entity_id = entity_id["entity_id"]
|
||||||
entity = apis.ha_api.get_entity(entity_id)
|
entity = apis.ha_api.get_entity(entity_id)
|
||||||
@@ -915,7 +915,7 @@ class LuiPagesGen(object):
|
|||||||
label1 = get_translation(self._locale, "frontend.ui.card.timer.actions.pause")
|
label1 = get_translation(self._locale, "frontend.ui.card.timer.actions.pause")
|
||||||
label2 = get_translation(self._locale, "frontend.ui.card.timer.actions.cancel")
|
label2 = get_translation(self._locale, "frontend.ui.card.timer.actions.cancel")
|
||||||
label3 = get_translation(self._locale, "frontend.ui.card.timer.actions.finish")
|
label3 = get_translation(self._locale, "frontend.ui.card.timer.actions.finish")
|
||||||
self._send_mqtt_msg(f"entityUpdateDetail~{entity_id}~~{icon_color}~{entity_id}~{min_remaining}~{sec_remaining}~{editable}~{action1}~{action2}~{action3}~{label1}~{label2}~{label3}")
|
self._send_mqtt_msg(f"entityUpdateDetail~{entity_id}~~{icon_color}~{entity_id}~{min_remaining}~{sec_remaining}~{editable}~{action1}~{action2}~{action3}~{label1}~{label2}~{label3}", force=is_open_detail)
|
||||||
|
|
||||||
def send_message_page(self, ident, heading, msg, b1, b2):
|
def send_message_page(self, ident, heading, msg, b1, b2):
|
||||||
self._send_mqtt_msg(f"pageType~popupNotify")
|
self._send_mqtt_msg(f"pageType~popupNotify")
|
||||||
|
|||||||
Reference in New Issue
Block a user