1919import shutil
2020import html as html_module
2121import time
22- from web_helper import get_header_html , get_plan_css , get_editor_js , get_editor_css , get_log_css , get_charts_css , get_apps_css , get_html_config_css , get_apps_js , get_components_css , get_logfile_js
22+ from web_helper import get_header_html , get_plan_css , get_editor_js , get_editor_css , get_log_css , get_charts_css , get_apps_css , get_html_config_css , get_apps_js , get_components_css , get_logfile_js , get_entity_toggle_js , get_entity_control_css
2323
2424from utils import calc_percent_limit , str2time , dp0 , dp2
2525from config import TIME_FORMAT , TIME_FORMAT_DAILY
@@ -815,37 +815,8 @@ def get_entity_control_html(self, entity_id, days):
815815 html = '<div class="entity-edit-container" style="margin-top: 15px; padding: 15px; border: 1px solid var(--border-color, #ddd); border-radius: 5px; background-color: var(--background-secondary, #f9f9f9);">'
816816
817817 # Add CSS for dark mode support
818- html += """
819- <style>
820- .entity-edit-container {
821- --border-color: #ddd;
822- --background-secondary: #f9f9f9;
823- --text-color: #333;
824- --text-secondary: #666;
825- --input-background: #fff;
826- }
818+ html += get_entity_control_css ()
827819
828- body.dark-mode .entity-edit-container {
829- --border-color: #555;
830- --background-secondary: #2d2d2d;
831- --text-color: #e0e0e0;
832- --text-secondary: #bbb;
833- --input-background: #3d3d3d;
834- color: var(--text-color);
835- }
836-
837- body.dark-mode .entity-edit-container input[type="number"],
838- body.dark-mode .entity-edit-container select {
839- background-color: var(--input-background) !important;
840- border-color: var(--border-color) !important;
841- color: var(--text-color) !important;
842- }
843-
844- body.dark-mode .entity-edit-container span {
845- color: var(--text-color) !important;
846- }
847- </style>
848- """
849820 html += f'<form method="post" action="./entity" style="display: flex; align-items: center; gap: 10px;">'
850821 html += f'<input type="hidden" name="entity_id" value="{ entity_id } ">'
851822 html += f'<input type="hidden" name="days" value="{ days } ">'
@@ -860,37 +831,7 @@ def get_entity_control_html(self, entity_id, days):
860831 html += f"</div>"
861832
862833 # Add JavaScript for toggle functionality
863- html += f"""
864- <script>
865- function toggleEntitySwitch(button, entityId, days) {{
866- // Toggle the visual state
867- button.classList.toggle('active');
868-
869- // Determine the new value
870- const newValue = button.classList.contains('active') ? 'on' : 'off';
871-
872- // Create form data
873- const formData = new FormData();
874- formData.append('entity_id', entityId);
875- formData.append('days', days);
876- formData.append('value', newValue);
877-
878- // Submit the form
879- fetch('./entity', {{
880- method: 'POST',
881- body: formData
882- }}).then(response => {{
883- if (response.redirected) {{
884- window.location.href = response.url;
885- }}
886- }}).catch(error => {{
887- console.error('Error:', error);
888- // Revert the toggle on error
889- button.classList.toggle('active');
890- }});
891- }}
892- </script>
893- """
834+ html += get_entity_toggle_js ()
894835
895836 elif control_type == "number" :
896837 min_val = self .base .get_state_wrapper (entity_id = entity_id , attribute = "min" , default = None )
@@ -1118,11 +1059,15 @@ async def html_api_get_log(self, request):
11181059 """
11191060 try :
11201061 logfile = "predbat.log"
1062+ logfile_1 = "predbat.1.log"
11211063 logdata = ""
11221064
11231065 if os .path .exists (logfile ):
11241066 with open (logfile , "r" ) as f :
11251067 logdata = f .read ()
1068+ if os .path .exists (logfile_1 ):
1069+ with open (logfile_1 , "r" ) as f :
1070+ logdata = f .read () + "\n " + logdata
11261071
11271072 # Get query parameters
11281073 args = request .query
0 commit comments