@@ -195,6 +195,26 @@ class SwissArmyKnifeCard extends LitElement {
195
195
:host {
196
196
cursor: default;
197
197
font-size: ${ FONT_SIZE } px;
198
+ --sak-ref-palette-gray-platinum: #e9e9ea;
199
+ --sak-ref-palette-gray-french-gray: #d1d1d6;
200
+ --sak-ref-palette-gray-taupe-gray: #8e8e93;
201
+ --sak-ref-palette-gray-cool-gray: #919bb4;
202
+
203
+ --sak-ref-palette-yellow-sunglow: #F7ce46;
204
+ --sak-ref-palette-yellow-jonquil: #ffcc01;
205
+ --sak-ref-palette-yellow-Amber: #f6b90b;
206
+
207
+ --sak-ref-palette-orange-xanthous: #F3b530;
208
+ --sak-ref-palette-orange-princeton-orange: #ff9500;
209
+ --sak-ref-palette-orange-orange : #F46c36;
210
+
211
+ --sak-ref-palette-red-indian-red: #ed5254;
212
+ --sak-ref-palette-red-japser: #d85140;
213
+ --sak-ref-palette-red-cinnabar: #ff3b2f;
214
+
215
+ --sak-ref-palette-purple-amethyst: #Af52de;
216
+ --sak-ref-palette-purple-tropical-indigo: #8d82ef;
217
+ --sak-ref-palette-purple-slate-blue: #5f5dd1;
198
218
}
199
219
200
220
/* Default settings for the card */
@@ -543,6 +563,7 @@ class SwissArmyKnifeCard extends LitElement {
543
563
this . theme . modeChanged = ( hass . themes . darkMode !== this . theme . darkMode ) ;
544
564
if ( this . theme . modeChanged ) {
545
565
this . theme . darkMode = hass . themes . darkMode ;
566
+ Colors . colorCache = { } ;
546
567
}
547
568
548
569
// Process theme if specified and does exist, otherwise ignore
@@ -789,7 +810,7 @@ class SwissArmyKnifeCard extends LitElement {
789
810
const thisMe = this ;
790
811
function findTemplate ( key , value ) {
791
812
// Filtering out properties
792
- // console.log(" findTemplate, key=" , key, " value=" , value);
813
+ // console.log(' findTemplate, key=' , key, ' value=' , value);
793
814
if ( value ?. template ) {
794
815
const template = thisMe . lovelace . config . sak_user_templates . templates [ value . template . name ] ;
795
816
if ( ! template ) {
@@ -861,7 +882,7 @@ class SwissArmyKnifeCard extends LitElement {
861
882
}
862
883
if ( this . dev . debug ) console . log ( 'card::setConfig - got toolsetCfg toolid' , tool , index , toolT , indexT , tool ) ;
863
884
}
864
- cfgobj [ toolidx ] . tools [ indexT ] = Templates . getJsTemplateOrValueConfig ( cfgobj [ toolidx ] . tools [ indexT ] , Merge . mergeDeep ( cfgobj [ toolidx ] . tools [ indexT ] ) ) ;
885
+ cfgobj [ toolidx ] . tools [ indexT ] = Templates . getJsTemplateOrValueConfig ( cfgobj [ toolidx ] . tools [ indexT ] , this . config . entities , Merge . mergeDeep ( cfgobj [ toolidx ] . tools [ indexT ] ) ) ;
865
886
return found ;
866
887
} ) ;
867
888
if ( ! found ) toolAdd = toolAdd . concat ( toolsetCfg . tools [ index ] ) ;
@@ -1149,7 +1170,7 @@ class SwissArmyKnifeCard extends LitElement {
1149
1170
clearInterval ( this . interval ) ;
1150
1171
this . interval = setInterval (
1151
1172
( ) => this . updateOnInterval ( ) ,
1152
- this . _hass ? this . entityHistory . update_interval * 1000 : 1000 ,
1173
+ this . _hass ? this . entityHistory . update_interval * 1000 : 100 ,
1153
1174
) ;
1154
1175
}
1155
1176
if ( this . dev . debug ) console . log ( 'ConnectedCallback' , this . cardId ) ;
@@ -1295,15 +1316,15 @@ class SwissArmyKnifeCard extends LitElement {
1295
1316
if ( this . dev . debug ) console . log ( 'all the tools in renderTools' , this . tools ) ;
1296
1317
1297
1318
return svg `
1298
- <g id="toolsets" class="toolsets__group"
1299
- >
1300
- ${ this . toolsets . map ( ( toolset ) => toolset . render ( ) ) }
1301
- </g>
1302
-
1303
- <defs>
1304
- ${ this . _renderSakSvgDefinitions ( ) }
1305
- ${ this . _renderUserSvgDefinitions ( ) }
1306
- </defs>
1319
+ <g id="toolsets" class="toolsets__group"
1320
+ >
1321
+ ${ this . toolsets . map ( ( toolset ) => toolset . render ( ) ) }
1322
+ </g>
1323
+
1324
+ <defs>
1325
+ ${ this . _renderSakSvgDefinitions ( ) }
1326
+ ${ this . _renderUserSvgDefinitions ( ) }
1327
+ </defs>
1307
1328
` ;
1308
1329
}
1309
1330
@@ -1368,6 +1389,7 @@ class SwissArmyKnifeCard extends LitElement {
1368
1389
const toolsetsSvg = this . _RenderToolsets ( ) ;
1369
1390
1370
1391
svgItems . push ( svg `
1392
+ <!-- SAK Card SVG Render -->
1371
1393
<svg id="rootsvg" xmlns="http://www/w3.org/2000/svg" xmlns:xlink="http://www/w3.org/1999/xlink"
1372
1394
class="${ cardFilter } "
1373
1395
style="${ styleMap ( this . themeIsDarkMode ( )
@@ -1668,10 +1690,13 @@ _buildStateString(inState, entityConfig) {
1668
1690
if ( this . dev . debug ) console . log ( 'UpdateOnInterval - NO hass, returning' ) ;
1669
1691
return ;
1670
1692
}
1671
- if ( this . stateChanged && ! this . entityHistory . updating ) {
1693
+ // console.log('updateOnInterval', new Date(Date.now()).toString());
1694
+ // eslint-disable-next-line no-constant-condition
1695
+ if ( true ) { // (this.stateChanged && !this.entityHistory.updating) {
1672
1696
// 2020.10.24
1673
1697
// Leave true, as multiple entities can be fetched. fetch every 5 minutes...
1674
1698
// this.stateChanged = false;
1699
+ // console.log('updateOnInterval - updateData', new Date(Date.now()).toString());
1675
1700
this . updateData ( ) ;
1676
1701
// console.log("*RC* updateOnInterval -> updateData", this.entityHistory);
1677
1702
}
@@ -1686,7 +1711,7 @@ _buildStateString(inState, entityConfig) {
1686
1711
window . clearInterval ( this . interval ) ;
1687
1712
this . interval = setInterval (
1688
1713
( ) => this . updateOnInterval ( ) ,
1689
- // 5 * 1000);
1714
+ // 30 * 1000,
1690
1715
this . entityHistory . update_interval * 1000 ,
1691
1716
) ;
1692
1717
// console.log("*RC* updateOnInterval -> start timer", this.entityHistory, this.interval);
@@ -1700,8 +1725,6 @@ _buildStateString(inState, entityConfig) {
1700
1725
if ( end ) url += `&end_time=${ end . toISOString ( ) } ` ;
1701
1726
if ( skipInitialState ) url += '&skip_initial_state' ;
1702
1727
url += '&minimal_response' ;
1703
-
1704
- // console.log('fetchRecent - call is', entityId, start, end, skipInitialState, url);
1705
1728
return this . _hass . callApi ( 'GET' , url ) ;
1706
1729
}
1707
1730
@@ -1722,14 +1745,32 @@ _buildStateString(inState, entityConfig) {
1722
1745
// add to list...
1723
1746
this . toolsets . map ( ( toolset , k ) => {
1724
1747
toolset . tools . map ( ( item , i ) => {
1725
- if ( item . type === 'bar' ) {
1748
+ if ( ( item . type === 'bar' )
1749
+ || ( item . type === 'sparkline' ) ) {
1750
+ if ( item . tool . config ?. period ?. type === 'real_time' ) return true ;
1726
1751
const end = new Date ( ) ;
1727
1752
const start = new Date ( ) ;
1728
- start . setHours ( end . getHours ( ) - item . tool . config . hours ) ;
1753
+ if ( item . tool . config . period ?. calendar ?. period === 'day' ) {
1754
+ start . setHours ( 0 , 0 , 0 , 0 ) ;
1755
+ start . setHours ( start . getHours ( ) + item . tool . config . period . calendar . offset * 24 ) ;
1756
+ // For now assume 24 hours always, so if offset != 0, set end...
1757
+ if ( item . tool . config . period . calendar . offset !== 0 ) end . setHours ( 0 , 0 , 0 , 0 ) ;
1758
+ } else {
1759
+ start . setHours ( end . getHours ( )
1760
+ - ( item . tool . config . period ?. rolling_window ?. duration ?. hour || item . tool . config . hours ) ) ;
1761
+ }
1729
1762
const attr = this . config . entities [ item . tool . config . entity_index ] . attribute ? this . config . entities [ item . tool . config . entity_index ] . attribute : null ;
1730
1763
1731
1764
entityList [ j ] = ( {
1732
- tsidx : k , entityIndex : item . tool . config . entity_index , entityId : this . entities [ item . tool . config . entity_index ] . entity_id , attrId : attr , start, end, type : 'bar' , idx : i ,
1765
+ tsidx : k ,
1766
+ entityIndex : item . tool . config . entity_index ,
1767
+ entityId : this . entities [ item . tool . config . entity_index ] . entity_id ,
1768
+ attrId : attr ,
1769
+ start,
1770
+ end,
1771
+ type : item . type ,
1772
+ idx : i ,
1773
+ // tsidx: k, entityIndex: item.tool.config.entity_index, entityId: this.entities[item.tool.config.entity_index].entity_id, attrId: attr, start, end, type: 'bar', idx: i,
1733
1774
} ) ;
1734
1775
j += 1 ;
1735
1776
}
@@ -1753,6 +1794,7 @@ _buildStateString(inState, entityConfig) {
1753
1794
} finally {
1754
1795
this . entityHistory . updating = false ;
1755
1796
}
1797
+ this . entityHistory . updating = false ;
1756
1798
}
1757
1799
1758
1800
async updateEntity ( entity , index , initStart , end ) {
@@ -1762,10 +1804,17 @@ _buildStateString(inState, entityConfig) {
1762
1804
1763
1805
// Get history for this entity and/or attribute.
1764
1806
let newStateHistory = await this . fetchRecent ( entity . entityId , start , end , skipInitialState ) ;
1807
+ // console.log('update, updateEntity, newStateHistory', entity.entityId, start, end, newStateHistory);
1765
1808
1766
1809
// Now we have some history, check if it has valid data and filter out either the entity state or
1767
1810
// the entity attribute. Ain't that nice!
1768
1811
1812
+ // Hack for state mapping...
1813
+ if ( entity . type === 'sparkline' ) {
1814
+ // console.log('pushing stateHistory into Graph!!!!', stateHistory);
1815
+ this . toolsets [ entity . tsidx ] . tools [ entity . idx ] . tool . processStateMap ( newStateHistory ) ;
1816
+ }
1817
+
1769
1818
let theState ;
1770
1819
1771
1820
if ( newStateHistory [ 0 ] && newStateHistory [ 0 ] . length > 0 ) {
@@ -1783,7 +1832,15 @@ _buildStateString(inState, entityConfig) {
1783
1832
1784
1833
stateHistory = [ ...stateHistory , ...newStateHistory ] ;
1785
1834
1786
- this . uppdate ( entity , stateHistory ) ;
1835
+ // console.log('Got new stateHistory', entity);
1836
+ if ( entity . type === 'sparkline' ) {
1837
+ // console.log('pushing stateHistory into Graph!!!!', stateHistory);
1838
+ this . toolsets [ entity . tsidx ] . tools [ entity . idx ] . tool . data = entity . entityIndex ;
1839
+ this . toolsets [ entity . tsidx ] . tools [ entity . idx ] . tool . series = [ ...stateHistory ] ;
1840
+ this . requestUpdate ( ) ;
1841
+ } else {
1842
+ this . uppdate ( entity , stateHistory ) ;
1843
+ }
1787
1844
}
1788
1845
1789
1846
uppdate ( entity , hist ) {
@@ -1804,7 +1861,8 @@ _buildStateString(inState, entityConfig) {
1804
1861
let hours = 24 ;
1805
1862
let barhours = 2 ;
1806
1863
1807
- if ( entity . type === 'bar' ) {
1864
+ if ( ( entity . type === 'bar' )
1865
+ || ( entity . type === 'sparkline' ) ) {
1808
1866
if ( this . dev . debug ) console . log ( 'entity.type == bar' , entity ) ;
1809
1867
1810
1868
hours = this . toolsets [ entity . tsidx ] . tools [ entity . idx ] . tool . config . hours ;
@@ -1852,7 +1910,8 @@ _buildStateString(inState, entityConfig) {
1852
1910
theData = coords . map ( ( item ) => getAvg ( item , 'state' ) ) ;
1853
1911
1854
1912
// now push data into object...
1855
- if ( entity . type === 'bar' ) {
1913
+ if ( [ 'bar' ] . includes ( entity . type ) ) {
1914
+ // if (entity.type === 'bar') {
1856
1915
this . toolsets [ entity . tsidx ] . tools [ entity . idx ] . tool . series = [ ...theData ] ;
1857
1916
}
1858
1917
0 commit comments