Merge pull request #213 from illuzn/illuzn-patch-1

Refactored icons.py and pages.py
This commit is contained in:
joBr99
2022-05-23 07:36:03 +02:00
committed by GitHub
2 changed files with 23 additions and 23 deletions

View File

@@ -77,30 +77,29 @@ cover_mapping = {
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":
elif ha_type == "button":
return "gesture-tap-button"
if ha_type == "scene":
elif ha_type == "scene":
return "palette"
if ha_type == "script":
elif ha_type == "script":
return "script-text"
if ha_type == "switch":
elif ha_type == "switch":
return "light-switch"
if ha_type == "number":
elif ha_type == "number":
return "ray-vertex"
if ha_type == "light":
elif ha_type == "light":
return "lightbulb"
if ha_type == "fan":
elif ha_type == "fan":
return "fan"
if ha_type == "input_boolean":
elif ha_type == "input_boolean":
return "check-circle-outline" if state == "on" else "close-circle-outline"
if ha_type == "cover":
elif ha_type == "cover":
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"
if ha_type == "lock":
elif ha_type == "lock":
return "lock-open" if state == "unlocked" else "lock"
elif ha_type == "sensor":
if state == "on":
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"
else:
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_name, state=None, device_class=None, overwrite=None):
def get_icon_id_ha(ha_type, 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))
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):
if overwrite is not None:

View File

@@ -151,10 +151,10 @@ class LuiPagesGen(object):
if entityType == "cover":
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_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)
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=entityType, action="open", 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=entityType, action="close", device_class=device_class)
pos = int(entity.attributes.get("current_position", 50))
if pos == 100:
@@ -454,8 +454,9 @@ class LuiPagesGen(object):
def generate_shutter_detail_page(self, entity):
entity = self._ha_api.get_entity(entity)
entityType="cover"
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")
if pos is None:
@@ -465,9 +466,9 @@ class LuiPagesGen(object):
pos_status = pos
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)
icon_up = get_action_id_ha(ha_type=entityType, action="open", 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=entityType, action="close", device_class=device_class)
icon_up_status = "enable"
icon_stop_status = "enable"
icon_down_status = "enable"