Home Information - Your home, your data, organized.
Python
Improved styling and layout for events and sensor/controller history.
Anthony Cassandra9ca6ebc39088
diff --git a/src/hi/apps/attribute/templates/attribute/panes/attribute_form_new.html b/src/hi/apps/attribute/templates/attribute/panes/attribute_form_new.htmlindex 25770da7..570fe3dd 100644--- a/src/hi/apps/attribute/templates/attribute/panes/attribute_form_new.html+++ b/src/hi/apps/attribute/templates/attribute/panes/attribute_form_new.html@@ -1,10 +1,12 @@+{% load common_template_helpers %}+{% generate_uuid as unique_id %}<div class="my-2">- <a class="" data-toggle="collapse" href="#hi-attribute-new"- role="button" aria-expanded="false" aria-controls="hi-attribute-new">+ <a class="" data-toggle="collapse" href="#hi-attribute-new-{{ unique_id }}"+ role="button" aria-expanded="false" aria-controls="hi-attribute-new-{{ unique_id }}"><span class="plus-icon">+</span> Add New Attribute</a></div>-<div class="collapse my-2" id="hi-attribute-new">+<div class="collapse my-2" id="hi-attribute-new-{{ unique_id }}">{% for hidden in attribute_form.hidden_fields %}{{ hidden }}diff --git a/src/hi/apps/config/context_processors.py b/src/hi/apps/config/context_processors.pyindex bbbdffb3..d189fd06 100644--- a/src/hi/apps/config/context_processors.py+++ b/src/hi/apps/config/context_processors.py@@ -1,9 +1,13 @@from hi.apps.console.console_manager import ConsoleManager+from hi.apps.console.settings import ConsoleSetting++from .settings_manager import SettingsManagerdef settings_context(request):console_manager = ConsoleManager()return {+ 'USER_TIMEZONE': SettingsManager().get_setting_value( ConsoleSetting.TIMEZONE ),'CONSOLE_AUDIO_MAP': console_manager.get_console_audio_map(),'SLEEP_OVERLAY_OPACITY': console_manager.get_sleep_overlay_opacity(),}diff --git a/src/hi/apps/control/templates/control/panes/controller_history_list.html b/src/hi/apps/control/templates/control/panes/controller_history_list.htmlindex 1130f853..bd9fe27e 100644--- a/src/hi/apps/control/templates/control/panes/controller_history_list.html+++ b/src/hi/apps/control/templates/control/panes/controller_history_list.html@@ -1,13 +1,16 @@+{% load tz %}+{% timezone USER_TIMEZONE %}<ul>{% for controller_history in controller_history_list %}<li>- Response[{{ controller_history.id }}]: {{ controller_history.value }} [{{ controller_history.created_datetime }}]+ {{ controller_history.created_datetime|localtime }} : {{ controller_history.value }}</li>{% empty %}- <div><em>No controller history</em></div>+ <div><em>No history.</em></div>{% endfor %}{% if show_all_link and controller_history_list %}<a href="{% url 'control_controller_history' controller_id=controller.id %}"- data-async="true">All History</a>+ data-async="true">>> See All</a>{% endif %}</ul>+{% endtimezone %}diff --git a/src/hi/apps/entity/enums.py b/src/hi/apps/entity/enums.pyindex bff382d2..3fb15ce4 100644--- a/src/hi/apps/entity/enums.py+++ b/src/hi/apps/entity/enums.py@@ -152,6 +152,10 @@ class EntityStateType(LabeledEnum):@propertydef suppress_display_name(self):return bool( self in { EntityStateType.VIDEO_STREAM })++ @property+ def suppress_history(self):+ return bool( self in { EntityStateType.VIDEO_STREAM })class EntityStateValue(LabeledEnum):diff --git a/src/hi/apps/entity/templates/entity/modals/entity_edit.html b/src/hi/apps/entity/templates/entity/modals/entity_edit.htmlindex d7fcd1ff..2b5c5417 100644--- a/src/hi/apps/entity/templates/entity/modals/entity_edit.html+++ b/src/hi/apps/entity/templates/entity/modals/entity_edit.html@@ -1,4 +1,4 @@-{% extends "modals/action_done.html" %}+{% extends "modals/base.html" %}{% block title_text %}{{ entity.name }}: Edit@@ -11,3 +11,31 @@</div>{% endblock %}++{% block footer %}++{% if entity.states.exists %}+<div class="align-self-center">+ <a class="btn btn-primary"+ href="{% url 'entity_status' entity_id=entity.id %}"+ data-async="modal">+ STATUS+ </a>+</div>+{% endif %}++{% if entity.states.exists %}+<div class="align-self-center">+ <a class="btn btn-primary"+ href="{% url 'entity_state_history' entity_id=entity.id %}"+ data-async="modal">+ HISTORY+ </a>+</div>+{% endif %}++<div class="align-self-center">+ <a id="hi-modal-done" role="button" {% if autofocus %}autofocus="autofocus"{% endif %}+ class="btn btn-lg btn-secondary" href="#" data-dismiss="modal">DONE</a>+</div>+{% endblock %}diff --git a/src/hi/apps/entity/templates/entity/modals/entity_state_history.html b/src/hi/apps/entity/templates/entity/modals/entity_state_history.htmlindex b5686bca..76da06be 100644--- a/src/hi/apps/entity/templates/entity/modals/entity_state_history.html+++ b/src/hi/apps/entity/templates/entity/modals/entity_state_history.html@@ -1,32 +1,57 @@-{% extends "modals/action_done.html" %}+{% extends "modals/action_3.html" %}{% load common_template_helpers %}{% block title_text %}-{{ entity.name }}+{{ entity.name }}: History{% endblock %}{% block body %}-<h5>Sensor History</h5>-<ul>+{% if sensor_history_list_map %}+<div>{% for sensor, sensor_history_list in sensor_history_list_map.items %}- <li>Sensor: {{ sensor.name }}+ {% if not sensor.entity_state.entity_state_type.suppress_history %}+ <div>+ <div class="h5">{{ sensor.name }} <small class="text-muted">[sensor]</small></div>{% include "sense/panes/sensor_history_list.html" with sensor_history_list=sensor_history_list show_all_link=True %}- </li>- {% empty %}- <div><em>No sensors</em></div>+ </div>+ {% endif %}{% endfor %}-</ul>+</div>+{% endif %}-<h5>Controller History</h5>-<ul>+{% if controller_history_list_map %}+<div>{% for controller, controller_history_list in controller_history_list_map.items %}- <li>Controller: {{ controller.name }}+ {% if not controller.entity_state.entity_state_type.suppress_history %}+ <div>+ <div class="h5">{{ controller.name }} <small class="text-muted">[controller]</small></div>{% include "control/panes/controller_history_list.html" with controller_history_list=controller_history_list show_all_link=True %}- </li>- {% empty %}- <div><em>No controllers</em></div>+ </div>+ {% endif %}{% endfor %}-</ul>+</div>+{% endif %}{% endblock %}++{% block action_left %}+<a class="btn btn-primary"+ href="{% url 'entity_edit' entity_id=entity.id %}"+ data-async="modal">+ EDIT+</a>+{% endblock %}++{% block action_center %}+<a class="btn btn-primary"+ href="{% url 'entity_status' entity_id=entity.id %}"+ data-async="modal">+ STATUS+</a>+{% endblock %}++{% block action_right %}+<a id="hi-modal-done" role="button" {% if autofocus %}autofocus="autofocus"{% endif %}+ class="btn btn-lg btn-secondary" href="#" data-dismiss="modal">DONE</a>+{% endblock %}diff --git a/src/hi/apps/event/edit/forms.py b/src/hi/apps/event/edit/forms.pyindex 5d1e7d8c..c43e3189 100644--- a/src/hi/apps/event/edit/forms.py+++ b/src/hi/apps/event/edit/forms.py@@ -52,6 +52,8 @@ class EventClauseForm( forms.ModelForm, EntityStateSelectModelFormMixin ):value_field_name = 'value',entity_state = entity_state,)+ self.fields['entity_state'].widget.attrs.update({ 'class': 'custom-select' })+ self.fields['value'].widget.attrs.update({ 'class': 'custom-select' })return@@ -102,6 +104,7 @@ class ControlActionForm( forms.ModelForm, EntityStateSelectModelFormMixin ):value_field_name = 'value',entity_state = entity_state,)+ self.fields['controller'].widget.attrs.update({ 'class': 'custom-select' })returndiff --git a/src/hi/apps/event/templates/event/edit/panes/alarm_action_form.html b/src/hi/apps/event/templates/event/edit/panes/alarm_action_form.htmlindex 97f22f13..1a2ab5c4 100644--- a/src/hi/apps/event/templates/event/edit/panes/alarm_action_form.html+++ b/src/hi/apps/event/templates/event/edit/panes/alarm_action_form.html@@ -1,11 +1,13 @@+{% load common_template_helpers %}+{% generate_uuid as unique_id %}{% if not alarm_action_form.instance.pk %}<div class="my-3">- <a class="" data-toggle="collapse" href="#hi-alarm-action-new"- role="button" aria-expanded="false" aria-controls="hi-alarm-action-new">+ <a class="" data-toggle="collapse" href="#hi-alarm-action-new-{{ unique_id }}"+ role="button" aria-expanded="false" aria-controls="hi-alarm-action-new-{{ unique_id }}"><span class="plus-icon">+</span> Add Alarm Action</a></div>-<div class="collapse my-2" id="hi-alarm-action-new">+<div class="collapse my-2" id="hi-alarm-action-new-{{ unique_id }}">{% else %}<div class="my-3">{% endif %}@@ -32,7 +34,7 @@</div>{% endif %}- <div class="input-group mb-2 mr-sm-2">+ <div class="input-group mb-2 mr-sm-2 w-100"><div class="input-group-prepend" ><label for="{{ alarm_action_form.security.id_for_label }}"class="input-group-text" >{{ alarm_action_form.security_level_str.label }}</label>@@ -41,7 +43,7 @@</div></div>- <div class="input-group mb-2 mr-sm-2">+ <div class="input-group mb-2 mr-sm-2 w-100"><div class="input-group-prepend" ><label for="{{ alarm_action_form.alarm.id_for_label }}"class="input-group-text" >{{ alarm_action_form.alarm_level_str.label }}</label>diff --git a/src/hi/apps/event/templates/event/edit/panes/control_action_form.html b/src/hi/apps/event/templates/event/edit/panes/control_action_form.htmlindex 9604e512..15062145 100644--- a/src/hi/apps/event/templates/event/edit/panes/control_action_form.html+++ b/src/hi/apps/event/templates/event/edit/panes/control_action_form.html@@ -1,11 +1,13 @@+{% load common_template_helpers %}+{% generate_uuid as unique_id %}{% if not control_action_form.instance.pk %}<div class="my-3">- <a class="" data-toggle="collapse" href="#hi-control-action-new"- role="button" aria-expanded="false" aria-controls="hi-control-action-new">+ <a class="" data-toggle="collapse" href="#hi-control-action-new-{{ unique_id }}"+ role="button" aria-expanded="false" aria-controls="hi-control-action-new-{{ unique_id }}"><span class="plus-icon">+</span> Add Control Action</a></div>-<div class="collapse my-2" id="hi-control-action-new">+<div class="collapse my-2" id="hi-control-action-new-{{ unique_id }}">{% else %}<div class="my-3">{% endif %}@@ -32,7 +34,7 @@</div>{% endif %}- <div class="input-group mb-2 mr-sm-2">+ <div class="input-group mb-2 mr-sm-2 w-100"><div class="input-group-prepend" ><label for="{{ control_action_form.controller.id_for_label }}"class="input-group-text" >{{ control_action_form.controller.label }}</label>@@ -41,7 +43,7 @@</div></div>- <div class="input-group mb-2 mr-sm-2">+ <div class="input-group mb-2 mr-sm-2 w-100"><div class="input-group-prepend" ><label for="{{ control_action_form.value.id_for_label }}"class="input-group-text" >{{ control_action_form.value.label }}</label>diff --git a/src/hi/apps/event/templates/event/edit/panes/event_clause_form.html b/src/hi/apps/event/templates/event/edit/panes/event_clause_form.htmlindex 9e75eca2..b3808943 100644--- a/src/hi/apps/event/templates/event/edit/panes/event_clause_form.html+++ b/src/hi/apps/event/templates/event/edit/panes/event_clause_form.html@@ -1,11 +1,13 @@+{% load common_template_helpers %}+{% generate_uuid as unique_id %}{% if not event_clause_form.instance.pk %}<div class="my-3">- <a class="" data-toggle="collapse" href="#hi-event-clause-new"- role="button" aria-expanded="false" aria-controls="hi-event-clause-new">+ <a class="" data-toggle="collapse" href="#hi-event-clause-new-{{ unique_id }}"+ role="button" aria-expanded="false" aria-controls="hi-event-clause-new-{{ unique_id }}"><span class="plus-icon">+</span> Add New Clause</a></div>-<div class="collapse my-2" id="hi-event-clause-new">+<div class="collapse my-2" id="hi-event-clause-new-{{ unique_id }}">{% else %}<div class="my-3">{% endif %}@@ -32,7 +34,7 @@</div>{% endif %}- <div class="input-group mb-2 mr-sm-2">+ <div class="input-group mb-2 mr-sm-2 w-100"><div class="input-group-prepend" ><label for="{{ event_clause_form.entity.id_for_label }}"class="input-group-text" >{{ event_clause_form.entity_state.label }}</label>@@ -41,7 +43,7 @@</div></div>- <div class="input-group mb-2 mr-sm-2">+ <div class="input-group mb-2 mr-sm-2 w-100"><div class="input-group-prepend" ><label for="{{ event_clause_form.value.id_for_label }}"class="input-group-text" >{{ event_clause_form.value.label }}</label>diff --git a/src/hi/apps/event/templates/event/panes/event_history_list.html b/src/hi/apps/event/templates/event/panes/event_history_list.htmlindex 88d8294a..576f16ba 100644--- a/src/hi/apps/event/templates/event/panes/event_history_list.html+++ b/src/hi/apps/event/templates/event/panes/event_history_list.html@@ -1,3 +1,5 @@+{% load tz %}+{% timezone USER_TIMEZONE %}<div><div class="table-responsive"><table class="table table-striped">@@ -11,7 +13,7 @@{% for event_history in event_history_list %}<tr><td>- {{ event_history.event_datetime }}+ {{ event_history.event_datetime|localtime }}</td><td>{{ event_history.event_definition.name }}@@ -24,3 +26,4 @@</table></div></div>+{% endtimezone %}diff --git a/src/hi/apps/sense/sensor_response_manager.py b/src/hi/apps/sense/sensor_response_manager.pyindex cb6c5a0c..0b97cc4b 100644--- a/src/hi/apps/sense/sensor_response_manager.py+++ b/src/hi/apps/sense/sensor_response_manager.py@@ -208,10 +208,6 @@ class SensorResponseManager( Singleton, SensorHistoryMixin, EventMixin ):sensor_response.sensor = await sync_to_async( self._get_sensor )(integration_key = sensor_response.integration_key,)- if sensor_response.sensor and sensor_response.detail_attrs:- sensor_response.detail_attrs['Sensor Name'] = sensor_response.sensor.name- elif sensor_response.sensor:- sensor_response.detail_attrs = { 'Sensor Name': sensor_response.sensor.name }continuereturndiff --git a/src/hi/apps/sense/templates/sense/modals/sensor_history_details.html b/src/hi/apps/sense/templates/sense/modals/sensor_history_details.htmlindex d17e8b11..f868164b 100644--- a/src/hi/apps/sense/templates/sense/modals/sensor_history_details.html+++ b/src/hi/apps/sense/templates/sense/modals/sensor_history_details.html@@ -6,18 +6,23 @@ Sensor Response Details{% block body %}<div>+ <div class="h4">{{ sensor_history.sensor.name }}</div>{% if sensor_history.image_url %}<div><img class="img-fluid" src="{{ sensor_history.image_url }}" alt="{{ alarm.title }}"></div>{% endif %}- <div>- {% for label, value in sensor_history.detail_attrs.items %}- <div class="row">- <div class="col-3 text-right">{{ label }}</div>- <div class="col-9-">{{ value }}</div>- </div>- {% endfor %}+ <div class="table-responsive">+ <table class="table table-striped">+ <tbody>+ {% for label, value in sensor_history.detail_attrs.items %}+ <tr>+ <th class="text-right">{{ label }}</th>+ <td>{{ value }}</td>+ </tr>+ {% endfor %}+ </tbody>+ </table></div></div>{% endblock %}diff --git a/src/hi/apps/sense/templates/sense/panes/sensor_history_list.html b/src/hi/apps/sense/templates/sense/panes/sensor_history_list.htmlindex f347ec84..4fb022f9 100644--- a/src/hi/apps/sense/templates/sense/panes/sensor_history_list.html+++ b/src/hi/apps/sense/templates/sense/panes/sensor_history_list.html@@ -1,17 +1,23 @@+{% load tz %}+{% timezone USER_TIMEZONE %}<ul>{% for sensor_history in sensor_history_list %}<li>- Response[{{ sensor_history.id }}]: {{ sensor_history.value }} [{{ sensor_history.response_datetime }}]{% if sensor_history.details %}<a href="{% url 'sense_sensor_history_details' sensor_history_id=sensor_history.id %}"- data-async="true">Details</a>+ data-async="true">+ {{ sensor_history.response_datetime|localtime }} : {{ sensor_history.value }}+ </a>+ {% else %}+ {{ sensor_history.response_datetime|localtime }} : {{ sensor_history.value }}{% endif %}</li>{% empty %}- <div><em>No sensor history</em></div>+ <div><em>No history.</em></div>{% endfor %}{% if show_all_link and sensor_history_list %}<a href="{% url 'sense_sensor_history' sensor_id=sensor.id %}"- data-async="true">All History</a>+ data-async="true">>> See All</a>{% endif %}</ul>+{% endtimezone %}