Skip to content

Commit

Permalink
view updates and split out defaults from theme updater
Browse files Browse the repository at this point in the history
  • Loading branch information
snootched committed Aug 28, 2024
1 parent 765dfc3 commit 54b65a3
Show file tree
Hide file tree
Showing 4 changed files with 126 additions and 53 deletions.
34 changes: 0 additions & 34 deletions cb-lcars/cb-lcars-defs.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
cb-lcars-defs:
template:
- cb-lcars-functions
triggers_update:
- '[[[ return variables.___helpers.alert_condition ]]]'

variables:
___helpers:
Expand Down Expand Up @@ -279,41 +277,9 @@ cb-lcars-defs:
document.head.appendChild(link);
]]]
colors: |
[[[
const themes = variables.__defs.themes;
let alertCondition = 'green'; // Default to 'green'
if (variables.___helpers && variables.___helpers.alert_condition) {
const entityState = states[variables.___helpers.alert_condition];
if (entityState) {
alertCondition = entityState.state.toLowerCase();
} else {
variables.__cblcarsLog('error', `Entity ${variables.___helpers.alert_condition} does not exist - defaulting to condition ${alertCondition}!`);
}
}
const selectedTheme = themes[`${alertCondition}_alert`];
//console.debug(variables.__defs.debug_title,'Setting alert condition ${alertCondition}');
variables.__cblcarsLog('info',`Setting alert condition ${alertCondition}`);
const colors = selectedTheme.colors;
for (const [colorGroup, colorValues] of Object.entries(colors)) {
for (const [colorName, colorValue] of Object.entries(colorValues)) {
const cssVarName = `--${colorName}`;
//if (getComputedStyle(document.documentElement).getPropertyValue(cssVarName).trim()) {
//console.debug(variables.__defs.debug_title,`Setting ${cssVarName}=${colorValue}`);
variables.__cblcarsLog('debug',`Setting ${cssVarName}=${colorValue}`);
document.documentElement.style.setProperty(cssVarName, colorValue);
//}
}
}
]]]
styles:
custom_fields:
font:
- height: 0
- width: 0
- visibility: hidden
colors:
- height: 0
- width: 0
- visibility: hidden
43 changes: 43 additions & 0 deletions cb-lcars/cb-lcars-theme.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
cb-lcars-theme:
template:
- cb-lcars-functions
- cb-lcars-defs
triggers_update:
- '[[[ return variables.___helpers.alert_condition ]]]'


custom_fields:
colors: |
[[[
const themes = variables.__defs.themes;
let alertCondition = 'green'; // Default to 'green'
if (variables.___helpers && variables.___helpers.alert_condition) {
const entityState = states[variables.___helpers.alert_condition];
if (entityState) {
alertCondition = entityState.state.toLowerCase();
} else {
variables.__cblcarsLog('error', `Entity ${variables.___helpers.alert_condition} does not exist - defaulting to condition ${alertCondition}!`);
}
}
const selectedTheme = themes[`${alertCondition}_alert`];
//console.debug(variables.__defs.debug_title,'Setting alert condition ${alertCondition}');
variables.__cblcarsLog('info',`Setting alert condition ${alertCondition}`);
const colors = selectedTheme.colors;
for (const [colorGroup, colorValues] of Object.entries(colors)) {
for (const [colorName, colorValue] of Object.entries(colorValues)) {
const cssVarName = `--${colorName}`;
//if (getComputedStyle(document.documentElement).getPropertyValue(cssVarName).trim()) {
//console.debug(variables.__defs.debug_title,`Setting ${cssVarName}=${colorValue}`);
variables.__cblcarsLog('debug',`Setting ${cssVarName}=${colorValue}`);
document.documentElement.style.setProperty(cssVarName, colorValue);
//}
}
}
]]]
styles:
custom_fields:
colors:
- height: 0
- width: 0
- visibility: hidden
100 changes: 82 additions & 18 deletions dist/cb-lcars-airlock.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,21 +39,20 @@ sections:
content: >-
# GREETINGS CAPTAIN
### Welcome aboard to **CB-LCARS** for Home Assistant
**CB-LCARS** is a framework of card templates for building
LCARS interfaces in Home Assistant - based on
[custom-button-card](https://github.com/custom-cards/button-card).
LCARS interfaces in Home Assistant - based on <a
href="https://github.com/custom-cards/button-card"
style="color:#37a6d1 !important;">custom-button-card</a>.
Please enjoy using CB-LCARS to create, personalize, and
tinker with your LCARS interface.
For more information see the [CB-LCARS
Repository](https://github.com/snootched/cb-lcars)
For more information see the <a
href="https://github.com/snootched/cb-lcars" style="color:
var(--picard-blue);">CB-LCARS Repository</a>
styles:
card:
- null
Expand Down Expand Up @@ -104,11 +103,6 @@ sections:
- cb-lcars-card-base
- cb-lcars-actions-disable
- cb-lcars-defs
triggers_update:
- input_boolean.lcars_sound
- input_boolean.lcars_texture
- input_boolean.lcars_ui_debug
- input_select.lcars_ui_alert_condition
variables:
___debug: true
___debug_hass: true
Expand All @@ -126,7 +120,7 @@ sections:
my_slider_v2: my-slider-v2
layout_card: layout-card
grid_layout: grid-layout
hue_like_light_card: hue_like_light_card
hue_like_light_card: hue-like-light-card
themes:
ha_lcars: (DO NOT USE/MODIFY)=== Base customizations
cb_lcars: LCARS Picard [cb-lcars]
Expand Down Expand Up @@ -184,6 +178,12 @@ sections:
[[[ return
hass.themes.themes.hasOwnProperty(variables.___reqs.themes.cb_lcars)
]]]
is_cb_lcars_sys_default: >-
[[[ return hass.themes.default_dark_theme ===
variables.___reqs.themes.cb_lcars ]]]
is_cb_lcars_active: >-
[[[ return hass.themes.theme ===
variables.___reqs.themes.cb_lcars ]]]
styles:
card:
- width: 70vw
Expand Down Expand Up @@ -239,13 +239,77 @@ sections:
- text-align: left
- width: 190px
- top: 550px
theme_set_default:
- position: absolute
- left: 1055px
- top: 350px
- z-index: 10
theme_set_user:
- position: absolute
- left: 1225px
- top: 350px
- z-index: 10
custom_fields:
log_reqs: '[[[ variables.__cblcarsLog("debug",variables.reqs_status); ]]]'
theme_set_default:
card:
type: custom:button-card
triggers_update: all
template:
- cb-lcars-button-lozenge
label: sys default
variables:
card:
width: 145px
height: 45px
color:
background:
inactive: >-
[[[ return
(variables.reqs_status.themes.is_cb_lcars_sys_default)
? "var(--picard-light-blue)" :
"var(--picard-orange)" ]]]
tap_action:
action: call-service
service: frontend.set_theme
service_data:
mode: dark
name: '[[[ return variables.___reqs.themes.cb_lcars ]]]'
confirmation:
text: >-
[[[ return "Set [" + variables.___reqs.themes.cb_lcars +
"] as the system default theme?" ]]]
theme_set_user:
card:
type: custom:button-card
triggers_update: all
template:
- cb-lcars-button-lozenge
label: set in profile
variables:
card:
width: 145px
height: 45px
color:
background:
inactive: >-
[[[ return
(variables.reqs_status.themes.is_cb_lcars_active) ?
"var(--picard-light-blue)" : "var(--picard-orange)"
]]]
tap_action:
action: navigate
navigation_path: /profile/general
confirmation:
text: >-
[[[ return "Navigate to your profile and set your theme
to [" + variables.___reqs.themes.cb_lcars + "] (or to
the system default if you set that)" ]]]
helpers_text:
card:
type: markdown
content: >-
## Helpers and Themes
## Themes and Helpers
CB-LCARS and HA-LCARS can utilize input helpers to control
functionality. Please ensure to create the input helpers per
Expand Down Expand Up @@ -882,7 +946,7 @@ sections:
- label: >-
[[[ return
(variables.reqs_status.custom_cards.hue_like_light_card)
? "online" : "offline" ]]]
? "online" : "optional" ]]]
variables:
card:
width: 240px
Expand All @@ -899,7 +963,7 @@ sections:
[[[ return
(variables.reqs_status.custom_cards.hue_like_light_card)
? 'var(--picard-medium-light-blue)' :
'var(--picard-medium-light-orange)' ]]]
'var(--picard-medium-dark-yellow)' ]]]
custom_cards_header:
card:
type: custom:button-card
Expand Down Expand Up @@ -929,10 +993,10 @@ sections:
bottom:
size: 25px
- type: custom:button-card
template: cb-lcars-defs
template: cb-lcars-theme
- type: grid
cards: []
- type: grid
cards: []
icon: 'mdi:rocket-launch'
icon: ''
cards: []
2 changes: 1 addition & 1 deletion dist/cb-lcars-gallery.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ sections:
size: 40px
color: var(--picard-dark-gray)
- type: custom:button-card
template: cb-lcars-defs
template: cb-lcars-theme
- type: entities
entities:
- input_select.lcars_ui_alert_condition
Expand Down

0 comments on commit 54b65a3

Please sign in to comment.