mirror of
https://github.com/joBr99/nspanel-lovelace-ui.git
synced 2026-02-21 13:44:45 +01:00
Merge pull request #213 from illuzn/illuzn-patch-1
Refactored icons.py and pages.py
This commit is contained in:
@@ -77,30 +77,29 @@ cover_mapping = {
|
|||||||
def map_to_mdi_name(ha_type, state=None, device_class=None, cardType=None):
|
def map_to_mdi_name(ha_type, state=None, device_class=None, cardType=None):
|
||||||
if ha_type == "weather":
|
if ha_type == "weather":
|
||||||
return weather_mapping[state] if state in weather_mapping else "alert-circle-outline"
|
return weather_mapping[state] if state in weather_mapping else "alert-circle-outline"
|
||||||
if ha_type == "button":
|
elif ha_type == "button":
|
||||||
return "gesture-tap-button"
|
return "gesture-tap-button"
|
||||||
if ha_type == "scene":
|
elif ha_type == "scene":
|
||||||
return "palette"
|
return "palette"
|
||||||
if ha_type == "script":
|
elif ha_type == "script":
|
||||||
return "script-text"
|
return "script-text"
|
||||||
if ha_type == "switch":
|
elif ha_type == "switch":
|
||||||
return "light-switch"
|
return "light-switch"
|
||||||
if ha_type == "number":
|
elif ha_type == "number":
|
||||||
return "ray-vertex"
|
return "ray-vertex"
|
||||||
if ha_type == "light":
|
elif ha_type == "light":
|
||||||
return "lightbulb"
|
return "lightbulb"
|
||||||
if ha_type == "fan":
|
elif ha_type == "fan":
|
||||||
return "fan"
|
return "fan"
|
||||||
if ha_type == "input_boolean":
|
elif ha_type == "input_boolean":
|
||||||
return "check-circle-outline" if state == "on" else "close-circle-outline"
|
return "check-circle-outline" if state == "on" else "close-circle-outline"
|
||||||
if ha_type == "cover":
|
elif ha_type == "cover":
|
||||||
if state == "closed":
|
if state == "closed":
|
||||||
return cover_mapping[device_class][1] if device_class in cover_mapping else "alert-circle-outline"
|
return cover_mapping[device_class][1] if device_class in cover_mapping else "alert-circle-outline"
|
||||||
else:
|
else:
|
||||||
return cover_mapping[device_class][0] if device_class in cover_mapping else "alert-circle-outline"
|
return cover_mapping[device_class][0] if device_class in cover_mapping else "alert-circle-outline"
|
||||||
if ha_type == "lock":
|
elif ha_type == "lock":
|
||||||
return "lock-open" if state == "unlocked" else "lock"
|
return "lock-open" if state == "unlocked" else "lock"
|
||||||
|
|
||||||
elif ha_type == "sensor":
|
elif ha_type == "sensor":
|
||||||
if state == "on":
|
if state == "on":
|
||||||
return sensor_mapping_on[device_class] if device_class in sensor_mapping_on else "alert-circle-outline"
|
return sensor_mapping_on[device_class] if device_class in sensor_mapping_on else "alert-circle-outline"
|
||||||
@@ -108,13 +107,13 @@ def map_to_mdi_name(ha_type, state=None, device_class=None, cardType=None):
|
|||||||
return sensor_mapping_off[device_class] if device_class in sensor_mapping_off else "alert-circle-outline"
|
return sensor_mapping_off[device_class] if device_class in sensor_mapping_off else "alert-circle-outline"
|
||||||
else:
|
else:
|
||||||
return sensor_mapping[device_class] if device_class in sensor_mapping else "alert-circle-outline"
|
return sensor_mapping[device_class] if device_class in sensor_mapping else "alert-circle-outline"
|
||||||
|
else:
|
||||||
|
return "alert-circle-outline"
|
||||||
|
|
||||||
return "alert-circle-outline"
|
def get_icon_id_ha(ha_type, state=None, device_class=None, overwrite=None):
|
||||||
|
|
||||||
def get_icon_id_ha(ha_name, state=None, device_class=None, overwrite=None):
|
|
||||||
if overwrite is not None:
|
if overwrite is not None:
|
||||||
return get_icon_id(overwrite)
|
return get_icon_id(overwrite)
|
||||||
return get_icon_id(map_to_mdi_name(ha_name, state, device_class))
|
return get_icon_id(map_to_mdi_name(ha_type, state, device_class))
|
||||||
|
|
||||||
def get_action_id_ha(ha_type, action, device_class=None, overwrite=None):
|
def get_action_id_ha(ha_type, action, device_class=None, overwrite=None):
|
||||||
if overwrite is not None:
|
if overwrite is not None:
|
||||||
|
|||||||
@@ -151,10 +151,10 @@ class LuiPagesGen(object):
|
|||||||
if entityType == "cover":
|
if entityType == "cover":
|
||||||
|
|
||||||
device_class = entity.attributes.get("device_class", "window")
|
device_class = entity.attributes.get("device_class", "window")
|
||||||
icon_id = get_icon_id_ha("cover", state=entity.state, device_class=device_class, overwrite=icon)
|
icon_id = get_icon_id_ha(ha_type=entityType, state=entity.state, device_class=device_class, overwrite=icon)
|
||||||
icon_up = get_action_id_ha(ha_type="cover", action="open", device_class=device_class)
|
icon_up = get_action_id_ha(ha_type=entityType, action="open", device_class=device_class)
|
||||||
icon_stop = get_action_id_ha(ha_type="cover", action="stop", device_class=device_class)
|
icon_stop = get_action_id_ha(ha_type=entityType, action="stop", device_class=device_class)
|
||||||
icon_down = get_action_id_ha(ha_type="cover", action="close", device_class=device_class)
|
icon_down = get_action_id_ha(ha_type=entityType, action="close", device_class=device_class)
|
||||||
|
|
||||||
pos = int(entity.attributes.get("current_position", 50))
|
pos = int(entity.attributes.get("current_position", 50))
|
||||||
if pos == 100:
|
if pos == 100:
|
||||||
@@ -454,8 +454,9 @@ class LuiPagesGen(object):
|
|||||||
|
|
||||||
def generate_shutter_detail_page(self, entity):
|
def generate_shutter_detail_page(self, entity):
|
||||||
entity = self._ha_api.get_entity(entity)
|
entity = self._ha_api.get_entity(entity)
|
||||||
|
entityType="cover"
|
||||||
device_class = entity.attributes.get("device_class", "")
|
device_class = entity.attributes.get("device_class", "")
|
||||||
icon_id = get_icon_id_ha("cover", state=entity.state, device_class=device_class)
|
icon_id = get_icon_id_ha(entityType, state=entity.state, device_class=device_class)
|
||||||
|
|
||||||
pos = entity.attributes.get("current_position")
|
pos = entity.attributes.get("current_position")
|
||||||
if pos is None:
|
if pos is None:
|
||||||
@@ -465,9 +466,9 @@ class LuiPagesGen(object):
|
|||||||
pos_status = pos
|
pos_status = pos
|
||||||
|
|
||||||
|
|
||||||
icon_up = get_action_id_ha(ha_type="cover", action="open", device_class=device_class)
|
icon_up = get_action_id_ha(ha_type=entityType, action="open", device_class=device_class)
|
||||||
icon_stop = get_action_id_ha(ha_type="cover", action="stop", device_class=device_class)
|
icon_stop = get_action_id_ha(ha_type=entityType, action="stop", device_class=device_class)
|
||||||
icon_down = get_action_id_ha(ha_type="cover", action="close", device_class=device_class)
|
icon_down = get_action_id_ha(ha_type=entityType, action="close", device_class=device_class)
|
||||||
icon_up_status = "enable"
|
icon_up_status = "enable"
|
||||||
icon_stop_status = "enable"
|
icon_stop_status = "enable"
|
||||||
icon_down_status = "enable"
|
icon_down_status = "enable"
|
||||||
|
|||||||
Reference in New Issue
Block a user