Home Information - Your home, your data, organized.
Python
Add integration logos to select modal, sidebar nav, and entity dialogs
Anthony Cassandra26966de9c91a
diff --git a/src/hi/apps/entity/templates/entity/edit/panes/entity_edit_mode_panel.html b/src/hi/apps/entity/templates/entity/edit/panes/entity_edit_mode_panel.htmlindex 9fb56b78..41fec0f0 100644--- a/src/hi/apps/entity/templates/entity/edit/panes/entity_edit_mode_panel.html+++ b/src/hi/apps/entity/templates/entity/edit/panes/entity_edit_mode_panel.html@@ -1,4 +1,4 @@-{% load icons %}+{% load icons static %}{% load integration_tags %}<div class="d-flex justify-content-between mt-2"><div class="h4">Item Layout</div>@@ -12,7 +12,11 @@{% if entity.integration_id %}<div class="my-2">- <div class="text-muted">From: <strong>{% integration_display_name entity %}</strong></div>+ <div class="text-muted">+ {% integration_logo_path entity as logo_path %}+ {% if logo_path %}<img src="{% static logo_path %}" alt="" style="max-height: 18px; width: auto; margin-right: 4px;">{% endif %}+ From: <strong>{% integration_display_name entity %}</strong>+ </div></div>{% endif %}diff --git a/src/hi/apps/entity/templates/entity/modals/entity_edit.html b/src/hi/apps/entity/templates/entity/modals/entity_edit.htmlindex 01411864..c1596c4d 100644--- a/src/hi/apps/entity/templates/entity/modals/entity_edit.html+++ b/src/hi/apps/entity/templates/entity/modals/entity_edit.html@@ -1,5 +1,5 @@{% extends "modals/base.html" %}-{% load icons %}+{% load icons static %}{% load integration_tags %}{% block modal_dialog_class %}hi-modal-dialog-700{% endblock %}@@ -7,7 +7,13 @@{% block body %}{% if entity.integration_id %}-<div class="text-muted text-center"><small>From: {% integration_display_name entity %}</small></div>+<div class="text-muted text-center">+ <small>+ {% integration_logo_path entity as logo_path %}+ {% if logo_path %}<img src="{% static logo_path %}" alt="" style="max-height: 18px; width: auto; margin-right: 4px;">{% endif %}+ From: {% integration_display_name entity %}+ </small>+</div>{% endif %}<!-- Root container for this attribute editing context --><div id="{{ attr_page_context.container_html_id }}"diff --git a/src/hi/apps/entity/templates/entity/modals/entity_status.html b/src/hi/apps/entity/templates/entity/modals/entity_status.htmlindex 4f2ea57f..60289f9e 100644--- a/src/hi/apps/entity/templates/entity/modals/entity_status.html+++ b/src/hi/apps/entity/templates/entity/modals/entity_status.html@@ -1,5 +1,5 @@{% extends "modals/action_3.html" %}-{% load icons %}+{% load icons static %}{% load video_tags %}{% load integration_tags %}@@ -19,7 +19,13 @@ Status<div class="text-center"><div class="h4 mb-0">{{ entity.name }}</div>{% if entity.integration_id %}- <div class="text-muted"><small>From: {% integration_display_name entity %}</small></div>+ <div class="text-muted">+ <small>+ {% integration_logo_path entity as logo_path %}+ {% if logo_path %}<img src="{% static logo_path %}" alt="" style="max-height: 18px; width: auto; margin-right: 4px;">{% endif %}+ From: {% integration_display_name entity %}+ </small>+ </div>{% endif %}</div><div>diff --git a/src/hi/integrations/templates/integrations/modals/integrations_select.html b/src/hi/integrations/templates/integrations/modals/integrations_select.htmlindex 76fa5e80..f580b5fe 100644--- a/src/hi/integrations/templates/integrations/modals/integrations_select.html+++ b/src/hi/integrations/templates/integrations/modals/integrations_select.html@@ -1,5 +1,5 @@{% extends "modals/action_done.html" %}-{% load icons %}+{% load icons static %}{% block modal_dialog_class %}hi-modal-dialog-600{% endblock %}@@ -11,7 +11,11 @@ Select Integrations{% for integration_data in integration_data_list %}<div class="d-flex justify-content-between {% if not forloop.first %}border-top{% endif %} py-2 my-1">- <div class="col-6">+ <div class="col-6 d-flex align-items-center">+ <img src="{% static integration_data.integration_metadata.logo_static_path %}"+ alt="{{ integration_data.integration_metadata.label }}"+ class="img-fluid mr-2"+ style="max-height: 24px; width: auto;">{{ integration_data.integration_metadata.label }}</div><div class="col-3">diff --git a/src/hi/integrations/templates/integrations/pages/integration_manage.html b/src/hi/integrations/templates/integrations/pages/integration_manage.htmlindex 8210ee74..b1453c7b 100644--- a/src/hi/integrations/templates/integrations/pages/integration_manage.html+++ b/src/hi/integrations/templates/integrations/pages/integration_manage.html@@ -1,5 +1,5 @@{% extends "config/pages/config_base.html" %}-{% load icons %}+{% load icons static %}{% block config_content %}<div id="hi-integration-settings" class="row">@@ -17,7 +17,12 @@href="{% url 'integrations_manage' integration_id=integration_data.integration_id %}"data-async="true"><div class="d-flex justify-content-between align-items-center">- <span>{{ integration_data.label }}</span>+ <span class="d-flex align-items-center" style="white-space: nowrap;">+ <img src="{% static integration_data.integration_metadata.logo_static_path %}"+ alt="{{ integration_data.label }}"+ style="max-height: 18px; width: auto; margin-right: 6px; flex-shrink: 0;">+ {{ integration_data.label }}+ </span>{% with health_status=integration_data.integration_gateway.get_health_status_provider.health_status %}{% if health_status.is_error %}<span class="text-danger">diff --git a/src/hi/integrations/templatetags/integration_tags.py b/src/hi/integrations/templatetags/integration_tags.pyindex 756ebac6..07a667ae 100644--- a/src/hi/integrations/templatetags/integration_tags.py+++ b/src/hi/integrations/templatetags/integration_tags.py@@ -9,16 +9,26 @@ logger = logging.getLogger(__name__)register = template.Library()-def integration_display_name( model : IntegrationDetailsModel ) -> str:+def _get_integration_metadata( model : IntegrationDetailsModel ):if not model:return Noneintegration_manager = IntegrationManager()try:gateway = integration_manager.get_integration_gateway( model.integration_id )- metadata = gateway.get_metadata()- return metadata.label+ return gateway.get_metadata()except Exception:passreturn None++def integration_display_name( model : IntegrationDetailsModel ) -> str:+ metadata = _get_integration_metadata( model )+ return metadata.label if metadata else None+++def integration_logo_path( model : IntegrationDetailsModel ) -> str:+ metadata = _get_integration_metadata( model )+ return metadata.logo_static_path if metadata else ''+diff --git a/src/hi/integrations/transient_models.py b/src/hi/integrations/transient_models.pyindex db068f1f..38319194 100644--- a/src/hi/integrations/transient_models.py+++ b/src/hi/integrations/transient_models.py@@ -14,6 +14,7 @@ class IntegrationMetaData:attribute_type : IntegrationAttributeTypeallow_entity_deletion : boolcan_add_custom_attributes : bool = True+ logo_static_path : str = 'img/integrations/default.svg'@dataclassdiff --git a/src/hi/services/hass/hass_metadata.py b/src/hi/services/hass/hass_metadata.pyindex f88e08a0..61372b8d 100644--- a/src/hi/services/hass/hass_metadata.py+++ b/src/hi/services/hass/hass_metadata.py@@ -8,4 +8,5 @@ HassMetaData = IntegrationMetaData(label = 'Home Assistant',attribute_type = HassAttributeType,allow_entity_deletion = False,+ logo_static_path = 'img/integrations/home-assistant.png',)diff --git a/src/hi/services/hass/templates/hass/panes/hass_manage.html b/src/hi/services/hass/templates/hass/panes/hass_manage.htmlindex 685ae368..bb137c77 100644--- a/src/hi/services/hass/templates/hass/panes/hass_manage.html+++ b/src/hi/services/hass/templates/hass/panes/hass_manage.html@@ -3,9 +3,9 @@<div class="d-flex justify-content-between"><div class="h3 integration-title"><img class="img-fluid"- src="{% static 'img/integrations/home-assistant.png' %}"- alt="Home Assistant Logo" \>- Home Assistant+ src="{% static core.integration_data.integration_metadata.logo_static_path %}"+ alt="{{ core.integration_data.integration_metadata.label }} Logo">+ {{ core.integration_data.integration_metadata.label }}</div><div class=""><form action="{% url 'hass_sync' %}"diff --git a/src/hi/services/homebox/hb_metadata.py b/src/hi/services/homebox/hb_metadata.pyindex d7c41969..69e2e26f 100644--- a/src/hi/services/homebox/hb_metadata.py+++ b/src/hi/services/homebox/hb_metadata.py@@ -9,4 +9,5 @@ HbMetaData = IntegrationMetaData(attribute_type = HbAttributeType,allow_entity_deletion = False,can_add_custom_attributes = False,+ logo_static_path = 'img/integrations/homebox.svg',)diff --git a/src/hi/services/homebox/templates/homebox/panes/hb_manage.html b/src/hi/services/homebox/templates/homebox/panes/hb_manage.htmlindex 2e1817e3..149cd29c 100644--- a/src/hi/services/homebox/templates/homebox/panes/hb_manage.html+++ b/src/hi/services/homebox/templates/homebox/panes/hb_manage.html@@ -4,9 +4,9 @@<div class="d-flex justify-content-between"><div class="h3 integration-title"><img class="img-fluid"- src="{% static 'img/integrations/homebox.svg' %}"- alt="HomeBox Logo">- HomeBox+ src="{% static core.integration_data.integration_metadata.logo_static_path %}"+ alt="{{ core.integration_data.integration_metadata.label }} Logo">+ {{ core.integration_data.integration_metadata.label }}</div><div class=""><form action="{% url 'hb_sync' %}"diff --git a/src/hi/services/zoneminder/templates/zoneminder/panes/zm_manage.html b/src/hi/services/zoneminder/templates/zoneminder/panes/zm_manage.htmlindex 47a7b8cd..44377224 100644--- a/src/hi/services/zoneminder/templates/zoneminder/panes/zm_manage.html+++ b/src/hi/services/zoneminder/templates/zoneminder/panes/zm_manage.html@@ -4,9 +4,9 @@<div class="d-flex justify-content-between"><div class="h3 integration-title"><img class="img-fluid"- src="{% static 'img/integrations/zoneminder.png' %}"- alt="ZoneMinder Logo" \>- ZoneMinder+ src="{% static core.integration_data.integration_metadata.logo_static_path %}"+ alt="{{ core.integration_data.integration_metadata.label }} Logo">+ {{ core.integration_data.integration_metadata.label }}</div><div class=""><form action="{% url 'zm_sync' %}"diff --git a/src/hi/services/zoneminder/zm_metadata.py b/src/hi/services/zoneminder/zm_metadata.pyindex df1ff4dd..006caae4 100644--- a/src/hi/services/zoneminder/zm_metadata.py+++ b/src/hi/services/zoneminder/zm_metadata.py@@ -8,4 +8,5 @@ ZmMetaData = IntegrationMetaData(label = 'ZoneMinder',attribute_type = ZmAttributeType,allow_entity_deletion = False,+ logo_static_path = 'img/integrations/zoneminder.png',)diff --git a/src/hi/static/img/integrations/default.svg b/src/hi/static/img/integrations/default.svgnew file mode 100644index 00000000..29782cd7--- /dev/null+++ b/src/hi/static/img/integrations/default.svg@@ -0,0 +1,3 @@+<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="#6c757d" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round">+ <path d="M14.7 6.3a1 1 0 0 0 0 1.4l1.6 1.6a1 1 0 0 0 1.4 0l3.77-3.77a6 6 0 0 1-7.94 7.94l-6.91 6.91a2.12 2.12 0 0 1-3-3l6.91-6.91a6 6 0 0 1 7.94-7.94l-3.76 3.76z"/>+</svg>