mirror of
https://github.com/joBr99/nspanel-lovelace-ui.git
synced 2025-12-22 23:44:25 +01:00
@@ -60,33 +60,21 @@ sensor_mapping = {
|
||||
"voltage": "flash"
|
||||
}
|
||||
|
||||
cover_mapping_open = {
|
||||
"awning": "window-open",
|
||||
"blind": "blinds-open",
|
||||
"curtain": "curtains-closed",
|
||||
"damper": "checkbox-blank-circle",
|
||||
"door": "door-open",
|
||||
"garage": "garage-open",
|
||||
"gate": "gate-open",
|
||||
"shade": "blinds-open",
|
||||
"shutter": "window-shutter-open",
|
||||
"window": "window-open"
|
||||
cover_mapping = {
|
||||
#"device_class": ("icon-open", "icon-closed", "icon-cover-open", "icon-cover-stop", "icon-cover-close")
|
||||
"awning": ("window-open", "window-closed", "arrow-up", "stop", "arrow-down"),
|
||||
"blind": ("blinds-open", "blinds", "arrow-up", "stop", "arrow-down"),
|
||||
"curtain": ("curtains-closed", "curtains", "arrow-expand-horizontal", "stop", "arrow-collapse-horizontal"),
|
||||
"damper": ("checkbox-blank-circle", "circle-slice-8", "arrow-up", "stop", "arrow-down"),
|
||||
"door": ("door-open", "door-closed", "arrow-expand-horizontal", "stop", "arrow-collapse-horizontal"),
|
||||
"garage": ("garage-open", "garage", "arrow-up", "stop", "arrow-down"),
|
||||
"gate": ("gate-open", "gate", "arrow-expand-horizontal", "stop", "arrow-collapse-horizontal"),
|
||||
"shade": ("blinds-open", "blinds", "arrow-up", "stop", "arrow-down"),
|
||||
"shutter": ("window-shutter-open", "window-shutter", "arrow-up", "stop", "arrow-down"),
|
||||
"window": ("window-open" "window-closed", "arrow-up", "stop", "arrow-down"),
|
||||
}
|
||||
|
||||
cover_mapping_closed = {
|
||||
"awning": "window-closed",
|
||||
"blind": "blinds",
|
||||
"curtain": "curtains",
|
||||
"damper": "circle-slice-8",
|
||||
"door": "door-closed",
|
||||
"garage": "garage",
|
||||
"gate": "gate",
|
||||
"shade": "blinds",
|
||||
"shutter": "window-shutter",
|
||||
"window": "window-closed"
|
||||
}
|
||||
|
||||
def map_to_mdi_name(ha_type, state=None, device_class=None):
|
||||
def map_to_mdi_name(ha_type, state=None, device_class=None, cardType=None):
|
||||
if ha_type == "weather":
|
||||
return weather_mapping[state] if state in weather_mapping else "alert-circle-outline"
|
||||
if ha_type == "button":
|
||||
@@ -109,9 +97,9 @@ def map_to_mdi_name(ha_type, state=None, device_class=None):
|
||||
if device_class is None:
|
||||
device_class = "window"
|
||||
if state == "closed":
|
||||
return cover_mapping_closed[device_class] if device_class in cover_mapping_closed else "alert-circle-outline"
|
||||
return cover_mapping[device_class][1] if device_class in cover_mapping else "alert-circle-outline"
|
||||
else:
|
||||
return cover_mapping_open[device_class] if device_class in cover_mapping_open else "alert-circle-outline"
|
||||
return cover_mapping[device_class][0] if device_class in cover_mapping else "alert-circle-outline"
|
||||
if ha_type == "lock":
|
||||
return "lock-open" if state == "unlocked" else "lock"
|
||||
|
||||
@@ -129,3 +117,22 @@ def get_icon_id_ha(ha_name, state=None, device_class=None, overwrite=None):
|
||||
if overwrite is not None:
|
||||
return get_icon_id(overwrite)
|
||||
return get_icon_id(map_to_mdi_name(ha_name, state, device_class))
|
||||
|
||||
def get_action_id_ha(ha_type, action, device_class=None, overwrite=None):
|
||||
if overwrite is not None:
|
||||
return get_icon_id(overwrite)
|
||||
if ha_type == "cover":
|
||||
if device_class is None:
|
||||
device_class = "window"
|
||||
if action == "open":
|
||||
actionicon = cover_mapping[device_class][2] if device_class in cover_mapping else "alert-circle-outline"
|
||||
elif action == "close":
|
||||
actionicon = cover_mapping[device_class][4] if device_class in cover_mapping else "alert-circle-outline"
|
||||
elif action == "stop":
|
||||
actionicon = cover_mapping[device_class][3] if device_class in cover_mapping else "alert-circle-outline"
|
||||
else:
|
||||
actionicon = "alert-circle-outline"
|
||||
else:
|
||||
actionicon = "alert-circle-outline"
|
||||
return get_icon_id(actionicon)
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ import dateutil.parser as dp
|
||||
|
||||
from icon_mapping import get_icon_id
|
||||
from icons import get_icon_id_ha
|
||||
from icons import get_action_id_ha
|
||||
from helper import scale, rgb_dec565, rgb_brightness, get_attr_safe, convert_temperature
|
||||
from localization import get_translation
|
||||
|
||||
@@ -146,9 +147,9 @@ class LuiPagesGen(object):
|
||||
|
||||
device_class = entity.attributes.get("device_class", "")
|
||||
icon_id = get_icon_id_ha("cover", state=entity.state, device_class=device_class, overwrite=icon)
|
||||
icon_up = get_icon_id("arrow-up")
|
||||
icon_stop = get_icon_id("stop")
|
||||
icon_down = get_icon_id("arrow-down")
|
||||
icon_up = get_action_id_ha(ha_type="cover", action="open", device_class=device_class)
|
||||
icon_stop = get_action_id_ha(ha_type="cover", action="stop", device_class=device_class)
|
||||
icon_down = get_action_id_ha(ha_type="cover", action="close", device_class=device_class)
|
||||
|
||||
pos = int(entity.attributes.get("current_position", 50))
|
||||
if pos == 100:
|
||||
@@ -440,14 +441,19 @@ class LuiPagesGen(object):
|
||||
pos_status = pos
|
||||
|
||||
|
||||
icon_up = get_icon_id("arrow-up")
|
||||
icon_stop = get_icon_id("stop")
|
||||
icon_down = get_icon_id("arrow-down")
|
||||
icon_up = get_action_id_ha(ha_type="cover", action="open", device_class=device_class)
|
||||
icon_stop = get_action_id_ha(ha_type="cover", action="stop", device_class=device_class)
|
||||
icon_down = get_action_id_ha(ha_type="cover", action="close", device_class=device_class)
|
||||
|
||||
if pos == 100:
|
||||
icon_up = "disable"
|
||||
elif pos == 0:
|
||||
icon_down = "disable"
|
||||
elif pos == "disable":
|
||||
if pos_status == "open":
|
||||
icon_up = "disable"
|
||||
elif pos_status == "closed":
|
||||
icon_down = "disable"
|
||||
|
||||
pos_translation = get_translation(self._locale, "position")
|
||||
self._send_mqtt_msg(f"entityUpdateDetail~{pos}~{pos_translation}: {pos_status}~{pos_translation}~{icon_id}~{icon_up}~{icon_stop}~{icon_down}")
|
||||
|
||||
Reference in New Issue
Block a user