mirror of
https://github.com/joBr99/nspanel-lovelace-ui.git
synced 2026-02-06 21:38:56 +01:00
some icon refactoring
This commit is contained in:
@@ -175,93 +175,7 @@ media_content_type_mapping = {
|
|||||||
'playlist': 'alert-circle-outline'
|
'playlist': 'alert-circle-outline'
|
||||||
}
|
}
|
||||||
|
|
||||||
def map_to_mdi_name(ha_type, state=None, device_class="_", cardType=None):
|
def get_icon(ha_type, overwrite=None):
|
||||||
if ha_type == "weather":
|
|
||||||
return weather_mapping[state] if state in weather_mapping else "alert-circle-outline"
|
|
||||||
elif ha_type in ["button", "navigate", "input_button", "input_select"]:
|
|
||||||
return "gesture-tap-button"
|
|
||||||
elif ha_type == "scene":
|
|
||||||
return "palette"
|
|
||||||
elif ha_type == "script":
|
|
||||||
return "script-text"
|
|
||||||
elif ha_type == "switch":
|
|
||||||
return "light-switch"
|
|
||||||
elif ha_type == "automation":
|
|
||||||
return "robot"
|
|
||||||
elif ha_type in ["number", "input_number"]:
|
|
||||||
return "ray-vertex"
|
|
||||||
elif ha_type == "light":
|
|
||||||
return "lightbulb"
|
|
||||||
elif ha_type == "fan":
|
|
||||||
return "fan"
|
|
||||||
elif ha_type == "person":
|
|
||||||
return "account"
|
|
||||||
elif ha_type == "vacuum":
|
|
||||||
return "robot-vacuum"
|
|
||||||
elif ha_type == "input_boolean":
|
|
||||||
return "check-circle-outline" if state == "on" else "close-circle-outline"
|
|
||||||
elif ha_type == "cover":
|
|
||||||
if device_class is None:
|
|
||||||
device_class = "window"
|
|
||||||
if state == "closed":
|
|
||||||
return cover_mapping[device_class][1] if device_class in cover_mapping else "alert-circle-outline"
|
|
||||||
else:
|
|
||||||
return cover_mapping[device_class][0] if device_class in cover_mapping else "alert-circle-outline"
|
|
||||||
elif ha_type == "lock":
|
|
||||||
return "lock-open" if state == "unlocked" else "lock"
|
|
||||||
elif ha_type == "sensor":
|
|
||||||
return sensor_mapping[device_class] if device_class in sensor_mapping else "alert-circle-outline"
|
|
||||||
elif ha_type == "binary_sensor":
|
|
||||||
if state == "on":
|
|
||||||
if device_class in sensor_mapping_on:
|
|
||||||
return sensor_mapping_on[device_class]
|
|
||||||
else:
|
|
||||||
return "checkbox-marked-circle"
|
|
||||||
else:
|
|
||||||
if device_class in sensor_mapping_off:
|
|
||||||
return sensor_mapping_off[device_class]
|
|
||||||
else:
|
|
||||||
return "radiobox-blank"
|
|
||||||
|
|
||||||
elif ha_type == "alarm-arm-fail":
|
|
||||||
return "progress-alert"
|
|
||||||
elif ha_type == "alarm_control_panel":
|
|
||||||
if state == "disarmed":
|
|
||||||
return "shield-off"
|
|
||||||
if state == "armed_home":
|
|
||||||
return "shield-home"
|
|
||||||
if state == "armed_away":
|
|
||||||
return "shield-lock"
|
|
||||||
if state == "armed_night":
|
|
||||||
return "weather-night"
|
|
||||||
if state == "armed_vacation":
|
|
||||||
return "shield-airplane"
|
|
||||||
if state in ["arming", "pending"]:
|
|
||||||
return "shield"
|
|
||||||
if state == "triggered":
|
|
||||||
return "bell-ring"
|
|
||||||
elif ha_type == "climate":
|
|
||||||
if state in ["auto", "heat_cool"]:
|
|
||||||
return "calendar-sync"
|
|
||||||
if state == "heat":
|
|
||||||
return "fire"
|
|
||||||
if state == "off":
|
|
||||||
return "power"
|
|
||||||
if state == "cool":
|
|
||||||
return "snowflake"
|
|
||||||
if state == "dry":
|
|
||||||
return "water-percent"
|
|
||||||
if state == "fan_only":
|
|
||||||
return "fan"
|
|
||||||
elif ha_type == "sun":
|
|
||||||
if state == "above_horizon":
|
|
||||||
return "weather-sunset-up"
|
|
||||||
if state == "below_horizon":
|
|
||||||
return "weather-sunset-down"
|
|
||||||
else:
|
|
||||||
return "alert-circle-outline"
|
|
||||||
|
|
||||||
def get_icon(ha_type, state=None, device_class=None, overwrite=None):
|
|
||||||
if overwrite is not None:
|
if overwrite is not None:
|
||||||
if type(overwrite) is str:
|
if type(overwrite) is str:
|
||||||
return get_icon_char(overwrite)
|
return get_icon_char(overwrite)
|
||||||
@@ -269,7 +183,14 @@ def get_icon(ha_type, state=None, device_class=None, overwrite=None):
|
|||||||
for overwrite_state, overwrite_icon in overwrite.items():
|
for overwrite_state, overwrite_icon in overwrite.items():
|
||||||
if overwrite_state == state:
|
if overwrite_state == state:
|
||||||
return get_icon_char(overwrite_icon)
|
return get_icon_char(overwrite_icon)
|
||||||
return get_icon_char(map_to_mdi_name(ha_type, state, device_class))
|
|
||||||
|
result_icon = "alert-circle-outline"
|
||||||
|
if ha_type == "script":
|
||||||
|
result_icon = "script-text"
|
||||||
|
elif ha_type == "alarm-arm-fail":
|
||||||
|
result_icon = "progress-alert"
|
||||||
|
|
||||||
|
return get_icon_char(result_icon)
|
||||||
|
|
||||||
def get_action_icon(ha_type, action, device_class=None, overwrite=None):
|
def get_action_icon(ha_type, action, device_class=None, overwrite=None):
|
||||||
if overwrite is not None:
|
if overwrite is not None:
|
||||||
@@ -287,7 +208,7 @@ def get_action_icon(ha_type, action, device_class=None, overwrite=None):
|
|||||||
actionicon = "alert-circle-outline"
|
actionicon = "alert-circle-outline"
|
||||||
return get_icon_char(actionicon)
|
return get_icon_char(actionicon)
|
||||||
|
|
||||||
def get_icon_ha(entity_id, overwrite=None):
|
def get_icon_ha(entity_id, overwrite=None, stateOverwrite=None):
|
||||||
if overwrite is not None:
|
if overwrite is not None:
|
||||||
if type(overwrite) is str:
|
if type(overwrite) is str:
|
||||||
return get_icon_char(overwrite)
|
return get_icon_char(overwrite)
|
||||||
@@ -301,7 +222,7 @@ def get_icon_ha(entity_id, overwrite=None):
|
|||||||
ha_type = entity_id.split(".")[0]
|
ha_type = entity_id.split(".")[0]
|
||||||
if (apis.ha_api.entity_exists(entity_id)):
|
if (apis.ha_api.entity_exists(entity_id)):
|
||||||
entity = apis.ha_api.get_entity(entity_id)
|
entity = apis.ha_api.get_entity(entity_id)
|
||||||
state = entity.state
|
state = entity.state if stateOverwrite is None else stateOverwrite
|
||||||
# icons only based on state
|
# icons only based on state
|
||||||
if ha_type in simple_type_mapping:
|
if ha_type in simple_type_mapping:
|
||||||
result_icon = simple_type_mapping[ha_type]
|
result_icon = simple_type_mapping[ha_type]
|
||||||
@@ -346,9 +267,4 @@ def get_icon_ha(entity_id, overwrite=None):
|
|||||||
if entity.attributes.media_content_type in media_content_type_mapping:
|
if entity.attributes.media_content_type in media_content_type_mapping:
|
||||||
result_icon = media_content_type_mapping[entity.attributes.media_content_type]
|
result_icon = media_content_type_mapping[entity.attributes.media_content_type]
|
||||||
|
|
||||||
# TODO: get rid of this one
|
|
||||||
elif ha_type == "alarm-arm-fail":
|
|
||||||
result_icon = "progress-alert"
|
|
||||||
else:
|
|
||||||
result_icon = "alert-circle-outline"
|
|
||||||
return get_icon_char(result_icon)
|
return get_icon_char(result_icon)
|
||||||
@@ -104,9 +104,9 @@ class LuiPagesGen(object):
|
|||||||
apis.ha_api.error(f"Skipping Weather Update, entity {we_name} not found")
|
apis.ha_api.error(f"Skipping Weather Update, entity {we_name} not found")
|
||||||
return
|
return
|
||||||
|
|
||||||
icon_cur = get_icon("weather", state=we.state)
|
icon_cur = get_icon_ha(we_name)
|
||||||
state["tMainIcon"] = we.state
|
state["tMainIcon"] = we.state
|
||||||
text_cur = convert_temperature(we.attributes.temperature, unit)
|
text_cur = convert_temperature(we.attributes.temperature, unit)
|
||||||
|
|
||||||
forecastSkip = self._config._config_screensaver.raw_config.get(f"forecastSkip")+1
|
forecastSkip = self._config._config_screensaver.raw_config.get(f"forecastSkip")+1
|
||||||
# check if the difference between the first 2 forecast items is less than 24h
|
# check if the difference between the first 2 forecast items is less than 24h
|
||||||
@@ -131,7 +131,7 @@ class LuiPagesGen(object):
|
|||||||
up = up.strftime('%H:%M')
|
up = up.strftime('%H:%M')
|
||||||
else:
|
else:
|
||||||
up = up.strftime('%a')
|
up = up.strftime('%a')
|
||||||
icon = get_icon("weather", state=we.attributes.forecast[fid]['condition'])
|
icon = get_icon_ha(we_name, stateOverwrite=we.attributes.forecast[fid]['condition'])
|
||||||
if i == 1:
|
if i == 1:
|
||||||
state["tF1Icon"] = we.attributes.forecast[fid]['condition']
|
state["tF1Icon"] = we.attributes.forecast[fid]['condition']
|
||||||
elif i == 2:
|
elif i == 2:
|
||||||
@@ -151,7 +151,7 @@ class LuiPagesGen(object):
|
|||||||
name = wOF.get("name")
|
name = wOF.get("name")
|
||||||
entity = apis.ha_api.get_entity(wOF.get("entity"))
|
entity = apis.ha_api.get_entity(wOF.get("entity"))
|
||||||
up = name if name is not None else entity.attributes.friendly_name
|
up = name if name is not None else entity.attributes.friendly_name
|
||||||
icon = get_icon("sensor", state=entity.state, device_class=entity.attributes.get("device_class", ""), overwrite=icon)
|
icon = get_icon_ha(wOF.get("entity"), overwrite=icon)
|
||||||
if "color" in wOF:
|
if "color" in wOF:
|
||||||
if theme is None:
|
if theme is None:
|
||||||
theme = {}
|
theme = {}
|
||||||
@@ -185,7 +185,7 @@ class LuiPagesGen(object):
|
|||||||
icon = statusIcon.get("icon")
|
icon = statusIcon.get("icon")
|
||||||
entity = apis.ha_api.get_entity(statusIcon.get("entity"))
|
entity = apis.ha_api.get_entity(statusIcon.get("entity"))
|
||||||
entityType = statusIcon.get("entity").split(".")[0]
|
entityType = statusIcon.get("entity").split(".")[0]
|
||||||
icon = get_icon(entityType, state=entity.state, device_class=entity.attributes.get("device_class", ""), overwrite=icon)
|
icon = get_icon_ha(statusIcon.get("entity"), overwrite=icon)
|
||||||
color = self.get_entity_color(entity, ha_type=entityType, overwrite=statusIcon.get("color", None))
|
color = self.get_entity_color(entity, ha_type=entityType, overwrite=statusIcon.get("color", None))
|
||||||
status_res += f"~{icon}~{color}"
|
status_res += f"~{icon}~{color}"
|
||||||
|
|
||||||
@@ -429,7 +429,7 @@ class LuiPagesGen(object):
|
|||||||
if overwrite_supported_modes is not None:
|
if overwrite_supported_modes is not None:
|
||||||
hvac_modes = overwrite_supported_modes
|
hvac_modes = overwrite_supported_modes
|
||||||
for mode in hvac_modes:
|
for mode in hvac_modes:
|
||||||
icon_id = get_icon("climate", state=mode)
|
icon_id = get_icon_ha(item, stateOverwrite=mode)
|
||||||
color_on = 64512
|
color_on = 64512
|
||||||
if mode in ["auto", "heat_cool"]:
|
if mode in ["auto", "heat_cool"]:
|
||||||
color_on = 1024
|
color_on = 1024
|
||||||
@@ -714,7 +714,7 @@ class LuiPagesGen(object):
|
|||||||
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")
|
||||||
icon_id = get_icon(entityType, state=entity.state, device_class=device_class)
|
icon_id = get_icon_ha(entity_id)
|
||||||
|
|
||||||
pos = entity.attributes.get("current_position")
|
pos = entity.attributes.get("current_position")
|
||||||
if pos is None:
|
if pos is None:
|
||||||
|
|||||||
Reference in New Issue
Block a user