Exemplo n.º 1
0
 def generate_media_page(self, navigation, entity):
     item = entity.entityId
     if not self._ha_api.entity_exists(item):
         command = f"entityUpd~|Not found||{item}|{get_icon_id('alert-circle-outline')}|Please check your|apps.yaml in AppDaemon|50|{get_icon_id('alert-circle-outline')}"
     else:
         entity        = self._ha_api.get_entity(item)
         heading       = entity.attributes.friendly_name
         icon          = 0
         title         = get_attr_safe(entity, "media_title", "")
         author        = get_attr_safe(entity, "media_artist", "")
         volume        = int(get_attr_safe(entity, "volume_level", 0)*100)
         iconplaypause = get_icon_id("pause") if entity.state == "playing" else get_icon_id("play")
         if "media_content_type" in entity.attributes:
             if entity.attributes.media_content_type == "music":
                 icon = get_icon_id("music")
         source        = get_attr_safe(entity, "source", "")
         speakerlist   = get_attr_safe(entity, "source_list",[])
         if source in speakerlist:
             # move current source to the end of the list
             speakerlist.remove(source)
             speakerlist.append(source)
         if len(speakerlist) == 1:
             speakerlist = []
         speakerlist = "?".join(speakerlist)
         bits = entity.attributes.supported_features
         onoffbutton = "disable"
         if bits & 0b10000000:
             if entity.state == "off":
                 onoffbutton = 1374
             else:
                 onoffbutton = rgb_dec565([255,255,255])
         command = f"entityUpd~{heading}~{navigation}~{item}~{icon}~{title}~{author}~{volume}~{iconplaypause}~{source}~{speakerlist[:200]}~{onoffbutton}"
     self._send_mqtt_msg(command)
Exemplo n.º 2
0
    def generate_alarm_page(self, navigation, entity):
        item = entity.entityId
        if not self._ha_api.entity_exists(item):
            command = f"entityUpd~{item}~~Not found~Not found~Check your~Check your~apps.~apps.~yaml~yaml~0~~0"
        else:
            entity        = self._ha_api.get_entity(item)
            icon = get_icon_id("shield-off")
            color = rgb_dec565([255,255,255])
            supported_modes = []
            numpad = "enable"
            if entity.state == "disarmed":
                color = rgb_dec565([13,160,53])
                icon = get_icon_id("shield-off")
                if not entity.attributes.get("code_arm_required", False):
                    numpad = "disable"
                bits = entity.attributes.supported_features
                if bits & 0b000001:
                    supported_modes.append("arm_home")
                if bits & 0b000010:
                    supported_modes.append("arm_away")
                if bits & 0b000100:
                    supported_modes.append("arm_night")
                if bits & 0b100000:
                    supported_modes.append("arm_vacation")
            else:
                supported_modes.append("disarm")

            if entity.state == "armed_home":
                color = rgb_dec565([223,76,30])
                icon = get_icon_id("shield-home")
            if entity.state == "armed_away":
                color = rgb_dec565([223,76,30])
                icon = get_icon_id("shield-lock")
            if entity.state == "armed_night":
                color = rgb_dec565([223,76,30])
                icon = get_icon_id("weather-night")
            if entity.state == "armed_vacation":
                color = rgb_dec565([223,76,30])
                icon = get_icon_id("shield-airplane")

            flashing = "disable"
            if entity.state in ["arming", "pending"]:
                color = rgb_dec565([243,179,0])
                icon = get_icon_id("shield")
                flashing = "enable"
            if entity.state == "triggered":
                color = rgb_dec565([223,76,30])
                icon = get_icon_id("bell-ring")
                flashing = "enable"

            # add padding to arm buttons
            arm_buttons = ""
            for b in supported_modes:
                arm_buttons += f"~{get_translation(self._locale, b)}~{b}"
            if len(supported_modes) < 4:
                arm_buttons += "~"*((4-len(supported_modes))*2)
            command = f"entityUpd~{item}~{navigation}{arm_buttons}~{icon}~{color}~{numpad}~{flashing}"
        self._send_mqtt_msg(command)
Exemplo n.º 3
0
 def generate_thermo_page(self, navigation, entity):
     item = entity.entityId
     if not self._ha_api.entity_exists(item):
         command = f"entityUpd~{heading}~{navigation}~{item}~220~220~Not found~150~300~5"
     else:
         entity       = self._ha_api.get_entity(item)
         heading      = entity.attributes.friendly_name
         current_temp = int(get_attr_safe(entity, "current_temperature", 0)*10)
         dest_temp    = int(get_attr_safe(entity, "temperature", 0)*10)
         status       = get_attr_safe(entity, "hvac_action", "")
         status       = get_translation(self._locale,status)
         min_temp     = int(get_attr_safe(entity, "min_temp", 0)*10)
         max_temp     = int(get_attr_safe(entity, "max_temp", 0)*10)
         step_temp    = int(get_attr_safe(entity, "target_temp_step", 0.5)*10) 
         icon_res = ""
         hvac_modes = get_attr_safe(entity, "hvac_modes", [])
         for mode in hvac_modes:
             icon_id = get_icon_id('alert-circle-outline')
             color_on = 64512
             if mode == "auto":
                 icon_id = get_icon_id("calendar-sync")
                 color_on = 1024
             if mode == "heat":
                 icon_id = get_icon_id("fire")
                 color_on = 64512
             if mode == "off":
                 icon_id = get_icon_id("power")
                 color_on = 35921
             if mode == "cool":
                 icon_id = get_icon_id("snowflake")
                 color_on = 11487
             if mode == "dry":
                 icon_id = get_icon_id("water-percent")
                 color_on = 60897
             if mode == "fan_only":
                 icon_id = get_icon_id("fan")
                 color_on = 35921
             state = 0
             if(mode == entity.state):
                 state = 1
             icon_res += f"~{icon_id}~{color_on}~{state}~{mode}"
 
         len_hvac_modes = len(hvac_modes)
         if len_hvac_modes%2 == 0:
             # even
             padding_len = int((4-len_hvac_modes)/2)
             icon_res =  "~"*4*padding_len + icon_res + "~"*4*padding_len
             # use last 4 icons
             icon_res =  "~"*4*5 + icon_res
         else:
             # uneven
             padding_len = int((5-len_hvac_modes)/2)
             icon_res =  "~"*4*padding_len + icon_res + "~"*4*padding_len
             # use first 5 icons
             icon_res = icon_res + "~"*4*4
         command = f"entityUpd~{heading}~{navigation}~{item}~{current_temp}~{dest_temp}~{status}~{min_temp}~{max_temp}~{step_temp}{icon_res}"
     self._send_mqtt_msg(command)
Exemplo n.º 4
0
def get_icon_id_ha(ha_name, 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))
Exemplo n.º 5
0
 def generate_entities_item(self, entity):
     entityId = entity.entityId
     icon = entity.iconOverride
     name = entity.nameOverride
     # type of the item is the string before the "." in the entityId
     entityType = entityId.split(".")[0]
     
     self._ha_api.log(f"Generating item for {entityId} with type {entityType}", level="DEBUG")
     # Internal types
     if entityType == "delete":
         return f"~{entityType}~~~~~"
     if entityType == "navigate":
         page_search_res = self._config.searchCard(entityId)
         if page_search_res is not None:
             name = name if name is not None else page_search_res.title
             text = get_translation(self._locale,"PRESS")
             icon_id = get_icon_id(icon) if icon is not None else get_icon_id("gesture-tap-button")
             return f"~button~{entityId}~{icon_id}~17299~{name}~{text}"
         else:
             return f"~text~{entityId}~{get_icon_id('alert-circle-outline')}~17299~page not found~"
     if not self._ha_api.entity_exists(entityId):
         return f"~text~{entityId}~{get_icon_id('alert-circle-outline')}~17299~Not found check~ apps.yaml"
     
     # HA Entities
     entity = self._ha_api.get_entity(entityId)
     name = name if name is not None else entity.attributes.friendly_name
     if entityType == "cover":
         icon_id = get_icon_id_ha("cover", state=entity.state, overwrite=icon)
         return f"~shutter~{entityId}~{icon_id}~17299~{name}~"
     if entityType in "light":
         switch_val = 1 if entity.state == "on" else 0
         icon_color = self.get_entity_color(entity)
         icon_id = get_icon_id_ha("light", overwrite=icon)
         return f"~{entityType}~{entityId}~{icon_id}~{icon_color}~{name}~{switch_val}"
     if entityType in ["switch", "input_boolean"]:
         switch_val = 1 if entity.state == "on" else 0
         icon_color = self.get_entity_color(entity)
         icon_id = get_icon_id_ha(entityType, state=entity.state, overwrite=icon)
         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
         icon_color = self.get_entity_color(entity)
         return f"~text~{entityId}~{icon_id}~{icon_color}~{name}~{value}"
     if entityType in ["button", "input_button"]:
         icon_id = get_icon_id_ha("button", overwrite=icon)
         text = get_translation(self._locale,"PRESS")
         return f"~button~{entityId}~{icon_id}~17299~{name}~{text}"
     if entityType == "scene":
         icon_id = get_icon_id_ha("scene", overwrite=icon)
         text = get_translation(self._locale,"ACTIVATE")
         return f"~button~{entityId}~{icon_id}~17299~{name}~{text}"
     if entityType == "script":
         icon_id = get_icon_id_ha("script", overwrite=icon)
         text = get_translation(self._locale,"run")
         return f"~button~{entityId}~{icon_id}~17299~{name}~{text}"
     if entityType == "lock":
         icon_id = get_icon_id_ha("lock", state=entity.state, overwrite=icon)
         icon_color = self.get_entity_color(entity)
         text = get_translation(self._locale,"lock") if entity.state == "unlocked" else get_translation(self._locale,"unlock")
         return f"~button~{entityId}~{icon_id}~{icon_color}~{name}~{text}"
     if entityType == "number":
         icon_id = get_icon_id_ha("number", overwrite=icon)
         min_v = entity.attributes.get("min", 0)
         max_v = entity.attributes.get("max", 100)
         return f"~number~{entityId}~{icon_id}~17299~{name}~{entity.state}|{min_v}|{max_v}"
     if entityType == "fan":
         icon_id = get_icon_id_ha("fan", overwrite=icon)
         icon_color = self.get_entity_color(entity)
         return f"~number~{entityId}~{icon_id}~{icon_color}~{name}~{entity.attributes.percentage}|0|100"
     if entityType == "input_text":
         icon_id = get_icon_id_ha("input_text", overwrite=icon)
         value = entity.state
         return f"~text~{entityId}~{icon_id}~17299~{name}~{value}"
     return f"~text~{entityId}~{get_icon_id('alert-circle-outline')}~17299~error~"