mirror of
https://github.com/joBr99/nspanel-lovelace-ui.git
synced 2026-02-15 17:36:59 +01:00
Implemented safe values for thermo page
This commit is contained in:
@@ -366,21 +366,22 @@ class NsPanelLovelaceUI:
|
|||||||
if item_type == "scene":
|
if item_type == "scene":
|
||||||
return "entityUpd,{0},{1},{2},{3},{4},{5}".format(item_nr, "button", item, 10, name, "ACTIVATE")
|
return "entityUpd,{0},{1},{2},{3},{4},{5}".format(item_nr, "button", item, 10, name, "ACTIVATE")
|
||||||
|
|
||||||
def generate_thermo_page(self, item):
|
def get_safe_ha_attribute(self, eattr, attr, default):
|
||||||
|
return eattr[attr] if attr in eattr else default
|
||||||
|
|
||||||
|
def generate_thermo_page(self, item):
|
||||||
|
|
||||||
if not self.api.entity_exists(item):
|
if not self.api.entity_exists(item):
|
||||||
return f"entityUpd,{item},Not found,220,220,Not found,150,300,5"
|
return f"entityUpd,{item},Not found,220,220,Not found,150,300,5"
|
||||||
|
|
||||||
entity = self.api.get_entity(item)
|
entity = self.api.get_entity(item)
|
||||||
heading = entity.attributes.friendly_name
|
heading = entity.attributes.friendly_name
|
||||||
current_temp = int(entity.attributes.current_temperature*10)
|
current_temp = int(self.get_safe_ha_attribute(entity.attributes, "current_temperature", 0)*10)
|
||||||
dest_temp = int(entity.attributes.temperature*10)
|
dest_temp = int(self.get_safe_ha_attribute(entity.attributes, "temperature", 0)*10)
|
||||||
status = ""
|
status = self.get_safe_ha_attribute(entity.attributes, "hvac_action", "")
|
||||||
if "hvac_action" in entity.attributes:
|
min_temp = int(self.get_safe_ha_attribute(entity.attributes, "min_temp", 0)*10)
|
||||||
status = entity.attributes.hvac_action
|
max_temp = int(self.get_safe_ha_attribute(entity.attributes, "max_temp", 0)*10)
|
||||||
min_temp = int(entity.attributes.min_temp*10)
|
step_temp = int(self.get_safe_ha_attribute(entity.attributes, "target_temp_step", 0.5)*10)
|
||||||
max_temp = int(entity.attributes.max_temp*10)
|
|
||||||
step_temp = int(0.5*10)
|
|
||||||
|
|
||||||
return f"entityUpd,{item},{heading},{current_temp},{dest_temp},{status},{min_temp},{max_temp},{step_temp}"
|
return f"entityUpd,{item},{heading},{current_temp},{dest_temp},{status},{min_temp},{max_temp},{step_temp}"
|
||||||
|
|
||||||
@@ -492,3 +493,4 @@ class NsPanelLovelaceUI:
|
|||||||
hsv = (math.degrees(math.atan2(y, x))%360/360, sat, 1)
|
hsv = (math.degrees(math.atan2(y, x))%360/360, sat, 1)
|
||||||
rgb = self.hsv2rgb(hsv[0],hsv[1],hsv[2])
|
rgb = self.hsv2rgb(hsv[0],hsv[1],hsv[2])
|
||||||
return rgb
|
return rgb
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user