Make sensors useful in cardGrid

Previously: sensors in cardGrid show an icon and the title below.

Desired Result: Sensors now display the state in place of the icon.

Rationale: Displaying a static icon in cardGrid is pointless. This way the state is displayed in large font which makes it useful and easier to read for the sight impaired.

Synopsis of Changes: render_card() now passes on cardType to generate_entities_page() which in turn passes it onto generate_entities_item(). If the cardType is `cardGrid` then the state is displayed instead of the icon.
This commit is contained in:
illuzn
2022-05-22 20:25:45 +09:30
committed by GitHub
parent dfd696b1f9
commit fee0c81832

View File

@@ -116,7 +116,7 @@ class LuiPagesGen(object):
self._send_mqtt_msg(f"weatherUpdate~{icon_cur}~{text_cur}{weather_res}{altLayout}")
def generate_entities_item(self, entity):
def generate_entities_item(self, entity, cardType):
entityId = entity.entityId
icon = entity.iconOverride
name = entity.nameOverride
@@ -170,9 +170,12 @@ class LuiPagesGen(object):
return f"~switch~{entityId}~{icon_id}~{icon_color}~{name}~{switch_val}"
if entityType in ["sensor", "binary_sensor"]:
device_class = entity.attributes.get("device_class", "")
icon_id = get_icon_id_ha("sensor", state=entity.state, device_class=device_class, overwrite=icon)
unit_of_measurement = entity.attributes.get("unit_of_measurement", "")
value = entity.state + " " + unit_of_measurement
if cardType == "cardGrid":
icon_id = entity.state
else:
icon_id = get_icon_id_ha("sensor", state=entity.state, device_class=device_class, overwrite=icon)
icon_color = self.get_entity_color(entity)
return f"~text~{entityId}~{icon_id}~{icon_color}~{name}~{value}"
if entityType in ["button", "input_button"]:
@@ -207,11 +210,11 @@ class LuiPagesGen(object):
return f"~text~{entityId}~{icon_id}~17299~{name}~{value}"
return f"~text~{entityId}~{get_icon_id('alert-circle-outline')}~17299~error~"
def generate_entities_page(self, navigation, heading, items):
def generate_entities_page(self, navigation, heading, items, cardType):
command = f"entityUpd~{heading}~{navigation}"
# Get items and construct cmd string
for item in items:
command += self.generate_entities_item(item)
command += self.generate_entities_item(item, cardType)
self._send_mqtt_msg(command)
def generate_thermo_page(self, navigation, entity, temp_unit):
@@ -380,7 +383,7 @@ class LuiPagesGen(object):
self.page_type(card.cardType)
if card.cardType in ["cardEntities", "cardGrid"]:
self.generate_entities_page(navigation, card.title, card.entities)
self.generate_entities_page(navigation, card.title, card.entities, card.cardType)
return
if card.cardType == "cardThermo":
temp_unit = card.raw_config.get("temperatureUnit", "celsius")