some more cleanup

This commit is contained in:
joBr99
2022-03-22 00:09:04 +01:00
committed by GitHub
parent 60acdf0600
commit fab72bd954

View File

@@ -190,9 +190,9 @@ class LovelaceUIPanel:
self.generate_entities_page(items) self.generate_entities_page(items)
# send detail pages in case they are open # send detail pages in case they are open
if(entity.startswith("cover")): if(entity.startswith("cover")):
self.generate_detail_page("popupShutter", entity) self.generate_shutter_detail_page(entity)
if(entity.startswith("light")): if(entity.startswith("light")):
self.generate_detail_page("popupLight", entity) self.generate_light_detail_page(entity)
return return
if page_type in ["cardThermo", "cardMedia"]: if page_type in ["cardThermo", "cardMedia"]:
@@ -283,7 +283,10 @@ class LovelaceUIPanel:
if msg[1] == "pageOpenDetail": if msg[1] == "pageOpenDetail":
self.api.log("Received pageOpenDetail command", level="DEBUG") self.api.log("Received pageOpenDetail command", level="DEBUG")
self.generate_detail_page(msg[2], msg[3]) if msg[2] == "popupShutter":
self.generate_shutter_detail_page(msg[3])
if msg[2] == "popupLight":
self.generate_light_detail_page(msg[3])
if msg[1] == "tempUpd": if msg[1] == "tempUpd":
self.api.log("Received tempUpd command", level="DEBUG") self.api.log("Received tempUpd command", level="DEBUG")
@@ -632,44 +635,41 @@ class LovelaceUIPanel:
icon_color = rgb_dec565(color) icon_color = rgb_dec565(color)
return icon_color return icon_color
def generate_light_detail_page(self, entity):
def generate_detail_page(self, page_type, entity): entity = self.api.get_entity(entity)
if page_type == "popupLight": switch_val = 1 if entity.state == "on" else 0
entity = self.api.get_entity(entity) icon_color = self.getEntityColor(entity)
switch_val = 1 if entity.state == "on" else 0 brightness = "disable"
color_temp = "disable"
icon_color = self.getEntityColor(entity) color = "disable"
# scale 0-255 brightness from ha to 0-100
brightness = "disable" if entity.state == "on":
color_temp = "disable" if "brightness" in entity.attributes:
color = "disable" brightness = int(scale(entity.attributes.brightness,(0,255),(0,100)))
# scale 0-255 brightness from ha to 0-100 else:
if entity.state == "on": brightness = "disable"
if "brightness" in entity.attributes: if "color_temp" in entity.attributes.supported_color_modes:
brightness = int(scale(entity.attributes.brightness,(0,255),(0,100))) if "color_temp" in entity.attributes:
# scale ha color temp range to 0-100
color_temp = int(scale(entity.attributes.color_temp,(entity.attributes.min_mireds, entity.attributes.max_mireds),(0,100)))
else: else:
brightness = "disable" color_temp = "unknown"
if "color_temp" in entity.attributes.supported_color_modes: else:
if "color_temp" in entity.attributes: color_temp = "disable"
# scale ha color temp range to 0-100
color_temp = int(scale(entity.attributes.color_temp,(entity.attributes.min_mireds, entity.attributes.max_mireds),(0,100)))
else:
color_temp = "unknown"
else:
color_temp = "disable"
list_color_modes = ["xy", "rgb", "rgbw", "hs"] list_color_modes = ["xy", "rgb", "rgbw", "hs"]
if any(item in list_color_modes for item in entity.attributes.supported_color_modes): if any(item in list_color_modes for item in entity.attributes.supported_color_modes):
color = "enable" color = "enable"
else: else:
color = "disable" color = "disable"
self.send_mqtt_msg(f"entityUpdateDetail,{get_icon_id('lightbulb')},{icon_color},{switch_val},{brightness},{color_temp},{color}") self.send_mqtt_msg(f"entityUpdateDetail,{get_icon_id('lightbulb')},{icon_color},{switch_val},{brightness},{color_temp},{color}")
if page_type == "popupShutter":
pos = self.api.get_entity(entity).attributes.current_position def generate_shutter_detail_page(self, entity):
# reverse position for slider pos = self.api.get_entity(entity).attributes.current_position
pos = 100-pos # reverse position for slider
self.send_mqtt_msg(f"entityUpdateDetail,{pos}") pos = 100-pos
self.send_mqtt_msg(f"entityUpdateDetail,{pos}")
def send_message_page(self, id, heading, msg, b1, b2): def send_message_page(self, id, heading, msg, b1, b2):
self.send_mqtt_msg(f"pageType,popupNotify") self.send_mqtt_msg(f"pageType,popupNotify")