mirror of
https://github.com/joBr99/nspanel-lovelace-ui.git
synced 2026-02-20 13:14:44 +01:00
fix thermo None values
This commit is contained in:
@@ -112,7 +112,7 @@ class LuiBackendConfig(object):
|
|||||||
'weatherOverrideForecast2': None,
|
'weatherOverrideForecast2': None,
|
||||||
'weatherOverrideForecast3': None,
|
'weatherOverrideForecast3': None,
|
||||||
'weatherOverrideForecast4': None,
|
'weatherOverrideForecast4': None,
|
||||||
'doubleTapToUnlock' False,
|
'doubleTapToUnlock': False,
|
||||||
'pages': [{
|
'pages': [{
|
||||||
'type': 'cardEntities',
|
'type': 'cardEntities',
|
||||||
'heading': 'Test Entities 1',
|
'heading': 'Test Entities 1',
|
||||||
|
|||||||
@@ -42,3 +42,7 @@ def rgb_dec565(rgb_color):
|
|||||||
# take in the red, green and blue values (0-255) as 8 bit values and then combine
|
# take in the red, green and blue values (0-255) as 8 bit values and then combine
|
||||||
# and shift them to make them a 16 bit dec value in 565 format.
|
# and shift them to make them a 16 bit dec value in 565 format.
|
||||||
return ((int(red / 255 * 31) << 11) | (int(green / 255 * 63) << 5) | (int(blue / 255 * 31)))
|
return ((int(red / 255 * 31) << 11) | (int(green / 255 * 63) << 5) | (int(blue / 255 * 31)))
|
||||||
|
|
||||||
|
def get_attr_safe(entity, attr, default):
|
||||||
|
res = entity.attributes.get(attr, default) if not None else default
|
||||||
|
return res
|
||||||
@@ -3,7 +3,7 @@ import datetime
|
|||||||
|
|
||||||
from icon_mapping import get_icon_id
|
from icon_mapping import get_icon_id
|
||||||
from icons import get_icon_id_ha
|
from icons import get_icon_id_ha
|
||||||
from helper import scale, rgb_dec565, rgb_brightness
|
from helper import scale, rgb_dec565, rgb_brightness, get_attr_safe
|
||||||
from localization import get_translation
|
from localization import get_translation
|
||||||
|
|
||||||
# check Babel
|
# check Babel
|
||||||
@@ -168,21 +168,22 @@ class LuiPagesGen(object):
|
|||||||
self._send_mqtt_msg(command)
|
self._send_mqtt_msg(command)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def generate_thermo_page(self, item):
|
def generate_thermo_page(self, item):
|
||||||
if not self._ha_api.entity_exists(item):
|
if not self._ha_api.entity_exists(item):
|
||||||
command = f"entityUpd,{item},Not found,220,220,Not found,150,300,5"
|
command = f"entityUpd,{item},Not found,220,220,Not found,150,300,5"
|
||||||
else:
|
else:
|
||||||
entity = self._ha_api.get_entity(item)
|
entity = self._ha_api.get_entity(item)
|
||||||
heading = entity.attributes.friendly_name
|
heading = entity.attributes.friendly_name
|
||||||
current_temp = int(entity.attributes.get("current_temperature", 0)*10)
|
current_temp = int(get_attr_safe(entity, "current_temperature", 0)*10)
|
||||||
dest_temp = int(entity.attributes.get("temperature", 0)*10)
|
dest_temp = int(get_attr_safe(entity, "temperature", 0)*10)
|
||||||
status = entity.attributes.get("hvac_action", "")
|
status = get_attr_safe(entity, "hvac_action", "")
|
||||||
status = get_translation(self._locale,status)
|
status = get_translation(self._locale,status)
|
||||||
min_temp = int(entity.attributes.get("min_temp", 0)*10)
|
min_temp = int(get_attr_safe(entity, "min_temp", 0)*10)
|
||||||
max_temp = int(entity.attributes.get("max_temp", 0)*10)
|
max_temp = int(get_attr_safe(entity, "max_temp", 0)*10)
|
||||||
step_temp = int(entity.attributes.get("target_temp_step", 0.5)*10)
|
step_temp = int(get_attr_safe(entity, "target_temp_step", 0.5)*10)
|
||||||
icon_res = ""
|
icon_res = ""
|
||||||
hvac_modes = entity.attributes.get("hvac_modes", [])
|
hvac_modes = get_attr_safe(entity, "hvac_modes", [])
|
||||||
for mode in hvac_modes:
|
for mode in hvac_modes:
|
||||||
icon_id = get_icon_id('alert-circle-outline')
|
icon_id = get_icon_id('alert-circle-outline')
|
||||||
color_on = 64512
|
color_on = 64512
|
||||||
@@ -232,15 +233,15 @@ class LuiPagesGen(object):
|
|||||||
entity = self._ha_api.get_entity(item)
|
entity = self._ha_api.get_entity(item)
|
||||||
heading = entity.attributes.friendly_name
|
heading = entity.attributes.friendly_name
|
||||||
icon = 0
|
icon = 0
|
||||||
title = entity.attributes.get("media_title", "")
|
title = get_attr_safe(entity, "media_title", "")
|
||||||
author = entity.attributes.get("media_artist", "")
|
author = get_attr_safe(entity, "media_artist", "")
|
||||||
volume = int(entity.attributes.get("volume_level", 0)*100)
|
volume = int(get_attr_safe(entity, "volume_level", 0)*100)
|
||||||
iconplaypause = get_icon_id("pause") if entity.state == "playing" else get_icon_id("play")
|
iconplaypause = get_icon_id("pause") if entity.state == "playing" else get_icon_id("play")
|
||||||
if "media_content_type" in entity.attributes:
|
if "media_content_type" in entity.attributes:
|
||||||
if entity.attributes.media_content_type == "music":
|
if entity.attributes.media_content_type == "music":
|
||||||
icon = get_icon_id("music")
|
icon = get_icon_id("music")
|
||||||
source = entity.attributes.get("source", "")
|
source = get_attr_safe(entity, "source", "")
|
||||||
speakerlist = entity.attributes.get("source_list",[])
|
speakerlist = get_attr_safe(entity, "source_list",[])
|
||||||
if source in speakerlist:
|
if source in speakerlist:
|
||||||
# move current source to the end of the list
|
# move current source to the end of the list
|
||||||
speakerlist.remove(source)
|
speakerlist.remove(source)
|
||||||
|
|||||||
Reference in New Issue
Block a user