+
${this.renderPage(this._activeCard)}
- `}renderPage(e){switch(e){case"base":default:return this.renderBaseMoonData();case"calendar":return this.renderCalendar()}}renderBaseMoonData(){return C` ${this.renderMoonImage()} ${this.renderMoonData()} `}renderHeader(){if(!this.config.compact_view||"base"!==this._activeCard)return C`
+ `:D``}renderPage(e){switch(e){case"base":default:return this.renderBaseCard();case"calendar":return this.renderCalendar()}}renderBaseCard(){return D` ${this.renderMoonImage()} ${this.renderMoonData()} `}renderHeader(){if(!this.config.compact_view||"base"!==this._activeCard)return D`
- `}renderMoonImage(){const e=this._getMoonImageData(),i={transform:`rotate(${e.rotateDeg}deg)`,marginBottom:""+(this.config.compact_view?"":"2rem")};return C`
-
-
`}renderMoonData(){const e=this.config.compact_view&&"base"===this._activeCard;return C`
- ${e?this.renderCompactView():C`
`}
- `}renderCompactView(){const{moonFraction:e,moonRise:i,moonSet:t,moonAge:s}=this._baseMoonData||{};return e&&i&&t&&s?C`
+ `}renderMoonImage(){const e=this._isCalendar?"calc(30% - 1px)":"calc(25% - 1px)",{moonImage:t,rotateDeg:i}=this._baseMoonData.moonImage;return D`
+
+
`}renderMoonData(){const e=this.config.compact_view&&"base"===this._activeCard;return D`
+ ${e?this.renderCompactView():D`
`}
+ `}renderCompactView(){const{moonFraction:e,moonRise:t,moonSet:i,moonAge:s}=this._baseMoonData,n=(e,t,i,s)=>D`
+
+
+
+ ${t} ${i}
+
+
${s}
+
+ `;return D`
@@ -1192,28 +1204,20 @@ button.swiper-pagination-bullet {
${this._moonPhaseName}
${e.value} ${e.unit} Illuminated
- ${this.renderCompactItem("mdi:progress-clock",s.value,s.unit,s.label)}
- ${this.renderCompactItem("mdi:weather-sunset-up",i.value,"",i.label)}
- ${this.renderCompactItem("mdi:weather-sunset-down",t.value,"",t.label)}
-
-
- `:C`
Loading...
`}renderCompactItem(e,i,t,s){return C`
-
-
-
- ${i} ${t}
+ ${n("mdi:progress-clock",s.value,s.unit,s.label)}
+ ${n("mdi:weather-moonset-up",t.value,"",t.label)}
+ ${n("mdi:weather-moonset",i.value,"",i.label)}
-
${s}
- `}renderCalendar(){const e=C`
-
-
-
-
-
`;return C`
+ `}renderCalendar(){if("base"===this._activeCard)return;this.selectedDate||(this.selectedDate=this._today);const e=Ne(this.selectedDate),t=D`
+
+
+
+
+
`;return D`
${this.renderMoonImage()}
-
${e}${this.renderMoonData()}
- `}updateDate(e){const i=new Date(this.selectedDate||this._today);"next"===e?i.setDate(i.getDate()+1):"prev"===e?i.setDate(i.getDate()-1):i.setDate(this._today.getDate()),this.selectedDate=i.toISOString().split("T")[0],this.fetchBaseMoonData()}_handleDateChange(e){const i=e.target;this.selectedDate=i.value,this.fetchBaseMoonData()}togglePage(){this._activeCard="base"===this._activeCard?"calendar":"base"}_getMoonImageData(){const e=this._moonIllumination,i=Math.round(16*e.phaseValue)%16;return{moonImage:$e[i],moonPhaseName:e.phase.name,rotateDeg:180-180*this._moonPosition.parallacticAngle/Math.PI}}_getBaseMoonData(){const{rise:e,set:i,highest:t}=this._moonTimes,{phaseValue:s,fraction:n}=this._moonIllumination,{fullMoon:r,newMoon:a}=this._moonIllumination.next,l=this._moonIllumination.phase.name,{distance:c,azimuthDegrees:o,altitudeDegrees:d}=this._moonPosition,m=e=>new Date(e).toISOString(),p=(e,i,t="",s="")=>({label:e,value:i,secondValue:t,unit:s});return{moonFraction:p("Illumination",(100*n).toFixed(2),"","%"),moonAge:p("Moon Age",(29.5*s).toFixed(2),"","days"),moonRise:p("Moonrise",Ke(m(e)),ve(m(e))),moonSet:p("Moonset",Ke(m(i)),ve(m(i))),moonHighest:p("Moon Highest",Ke(m(t||"")),ve(m(t||"")),""),distance:p("Distance",c.toFixed(2),"","km"),azimuthDegress:p("Moon Azimuth",o.toFixed(2),"","°"),altitudeDegrees:p("Moon Altitude",d.toFixed(2),"","°"),nextFullMoon:p("Next Full Moon",new Date(r.date).toDateString(),"",""),nextNewMoon:p("Next New Moon",new Date(a.date).toDateString(),"",""),phaseName:p("Phase Name",l,"","")}}_getMoonIllumination(e){return qe.getMoonIllumination(e)}_getMoonPosition(e,i,t){return qe.getMoonPosition(e,i,t)}_computeClasses(){return Ve({"--background":this._showBackground})}_setBackgroundCss(){this.style.setProperty("--lunar-background-image",`url(${_e})`)}static get styles(){return[ii]}getCardSize(){return 4}};os.getStubConfig=()=>Object.assign({},Ye),e([xe({attribute:!1})],os.prototype,"hass",void 0),e([xe({type:Object})],os.prototype,"config",void 0),e([Re()],os.prototype,"_activeCard",void 0),e([Re()],os.prototype,"_baseMoonData",void 0),e([Re()],os.prototype,"latitude",void 0),e([Re()],os.prototype,"longitude",void 0),e([Re()],os.prototype,"selectedDate",void 0),os=e([pe("lunar-phase-card")],os),window.customCards=window.customCards||[],window.customCards.push({type:"lunar-phase-card",name:"Lunar Phase Card",description:"A custom card to display the current lunar phase."});let ds=class extends de{setConfig(e){this._config=e,this._config.entity&&(this._config.use_default=!1)}get _entity(){var e;return(null===(e=this._config)||void 0===e?void 0:e.entity)||""}get _use_default(){var e;return(null===(e=this._config)||void 0===e?void 0:e.use_default)||!0}get _show_background(){var e;return(null===(e=this._config)||void 0===e?void 0:e.show_background)||!1}get _compact_view(){var e;return(null===(e=this._config)||void 0===e?void 0:e.compact_view)||!1}render(){if(!this.hass)return C``;const e=Object.keys(this.hass.states).filter((e=>e.startsWith("sensor")&&e.endsWith("_moon_phase"))).sort();return C`
+
${t}${this.renderMoonData()}
+ `}updateDate(e){const t=new Date(this.selectedDate||this._today);"next"===e?t.setDate(t.getDate()+1):"prev"===e&&t.setDate(t.getDate()-1),this.selectedDate=t,this.fetchBaseMoonData()}_handleDateChange(e){const t=e.target;this.selectedDate=new Date(t.value),this.fetchBaseMoonData()}togglePage(){this._activeCard="base"===this._activeCard?"calendar":"base"}_getBaseMoonData(){const{rise:e,set:t,highest:i}=this._moonTimes,{phaseValue:s,fraction:n}=this._moonIllumination,{fullMoon:r,newMoon:a}=this._moonIllumination.next,l=this._moonPosition.parallacticAngle,c=this._moonIllumination.phase.name,{distance:d,azimuthDegrees:o,altitudeDegrees:z}=this._moonPosition,p=Math.round(16*s)%16,m=l?180-180*l/Math.PI:0,u=e=>new Date(e).toISOString(),x=(e,t,i="",s="")=>({label:e,value:t,secondValue:i,unit:s});return{moonFraction:x("Illumination",(100*n).toFixed(2),"","%"),moonAge:x("Moon Age",(29.5*s).toFixed(2),"","days"),moonRise:x("Moonrise",Ge(u(e)),Ye(u(e))),moonSet:x("Moonset",Ge(u(t)),Ye(u(t))),moonHighest:x("Moon Highest",Ge(u(i||"")),Ye(u(i||"")),""),distance:x("Distance",d.toFixed(2),"","km"),azimuthDegress:x("Azimuth",o.toFixed(2),"","°"),altitudeDegrees:x("Altitude",z.toFixed(2),"","°"),nextFullMoon:x("Full Moon",new Date(r.date).toLocaleDateString("en-US",{weekday:"short",month:"short",day:"numeric"}),"",""),nextNewMoon:x("New Moon",new Date(a.date).toLocaleDateString("en-US",{weekday:"short",month:"short",day:"numeric"}),"",""),phaseName:x("Phase Name",c,"",""),moonImage:((e,t,i)=>({moonImage:e,moonPhaseName:t,rotateDeg:i}))(tt[p],c,m)}}_getMoonIllumination(e){return Oe.getMoonIllumination(e)}_getMoonPosition(e,t,i){return Oe.getMoonPosition(e,t,i)}_computeClasses(){return Ve({"--background":this._showBackground})}_setBackgroundCss(){const e=this.config.custom_background||et;this.style.setProperty("--lunar-background-image",`url(${e})`)}static get styles(){return[st]}};zs.getStubConfig=()=>Object.assign({},ye),e([xe({attribute:!1})],zs.prototype,"hass",void 0),e([xe({type:Object})],zs.prototype,"config",void 0),e([Re()],zs.prototype,"_activeCard",void 0),e([Re()],zs.prototype,"_baseMoonData",void 0),e([Re()],zs.prototype,"latitude",void 0),e([Re()],zs.prototype,"longitude",void 0),e([Re()],zs.prototype,"selectedDate",void 0),e([Re()],zs.prototype,"_connected",void 0),e([Re()],zs.prototype,"_refreshInterval",void 0),zs=e([pe("lunar-phase-card")],zs),window.customCards=window.customCards||[],window.customCards.push({type:"lunar-phase-card",name:"Lunar Phase Card",preview:!0,description:"A custom card to display the current lunar phase."});let ps=class extends oe{constructor(){super(...arguments),this.selectedOption="url"}setConfig(e){this._config=e}get _entity(){var e;return(null===(e=this._config)||void 0===e?void 0:e.entity)||""}get _use_default(){var e;return(null===(e=this._config)||void 0===e?void 0:e.use_default)||!0}get _show_background(){var e;return(null===(e=this._config)||void 0===e?void 0:e.show_background)||!1}get _compact_view(){var e;return(null===(e=this._config)||void 0===e?void 0:e.compact_view)||!1}get _latitude(){var e;return(null===(e=this._config)||void 0===e?void 0:e.latitude)||0}get _longitude(){var e;return(null===(e=this._config)||void 0===e?void 0:e.longitude)||0}get _custom_background(){var e;return(null===(e=this._config)||void 0===e?void 0:e.custom_background)||""}connectedCallback(){super.connectedCallback()}disconnectedCallback(){super.disconnectedCallback()}shouldUpdate(e){return!(!this._config||!this.hass)&&super.shouldUpdate(e)}render(){if(!this.hass)return D``;const e=Object.keys(this.hass.states).filter((e=>e.startsWith("sensor")&&e.endsWith("_moon_phase")&&!e.endsWith("_next_moon_phase"))).sort();return D`
e.stopPropagation()}
>
- ${e.map((e=>C`${e}`))}
+ ${e.map((e=>{const t=this.hass.states[e].attributes.friendly_name;return D` ${`${t?`${t} (${e})`:e} `}`}))}
- ${this.renderCustomLatLon()} ${this.renderSwitches()}
+ ${this.renderImageUpload()} ${this.renderCustomLatLon()} ${this.renderSwitches()}
+
+
Version: ${_e}
+ `}renderImageUpload(){const e=D`
+
+
+ ${this._custom_background?D`
+
+
+
+ `:D`
+
+ `}
-
Version: ${Be}
- `}renderSwitches(){var e;return C`
+ `;return this.panelTemplate("Custom Background","Set a custom background image","mdi:image",e)}async _handleFilePicked(e){const t=e.target;if(!t.files||0===t.files.length)return;const i=t.files[0],s=new FormData;s.append("file",i);try{const e=await fetch("/api/image/upload",{method:"POST",body:s,headers:{Authorization:`Bearer ${this.hass.auth.data.access_token}`}});if(!e.ok)throw new Error("Failed to upload image");const t=(await e.json()).id;if(!t)throw new Error("Image ID is missing in the response");const i=`/api/image/serve/${t}/original`;this._config&&(this._config=Object.assign(Object.assign({},this._config),{custom_background:i}),we(this,"config-changed",{config:this._config}),this.requestUpdate())}catch(e){}}handleRemoveBackground(){this._config&&(this._config=Object.assign(Object.assign({},this._config),{custom_background:void 0}),we(this,"config-changed",{config:this._config}),this.requestUpdate())}renderSwitches(){var e,t,i;const s=!!((null===(e=this._config)||void 0===e?void 0:e.entity)||(null===(t=this._config)||void 0===t?void 0:t.latitude)&&(null===(i=this._config)||void 0===i?void 0:i.longitude));return D`
- `}renderCustomLatLon(){var e,i;const t=C`
+ `}renderCustomLatLon(){var e,t,i;const s=!!(null===(e=this._config)||void 0===e?void 0:e.entity),n=D`
+
${"If entity is set, latitude and longitude won't be used."}
- `;return this.panelTemplate("Latitude & Longitude","Set custom latitude and longitude","mdi:map-marker",t)}panelTemplate(e,i,t,s){return C`
+ `;return this.panelTemplate("Latitude & Longitude","Set custom latitude and longitude","mdi:map-marker",n)}panelTemplate(e,t,i,s){return D`
- `}_valueChanged(e){if(!this._config||!this.hass)return;const i=e.target;if(this[`_${i.configValue}`]!==i.value){if(i.configValue)if(""===i.value){const e=Object.assign({},this._config);delete e[i.configValue],this._config=e}else this._config=Object.assign(Object.assign({},this._config),{[i.configValue]:void 0!==i.checked?i.checked:i.value});Ee(this,"config-changed",{config:this._config})}}};ds.styles=l`
+ `}_valueChanged(e){if(!this._config||!this.hass)return;const t=e.target,i=t.configValue;if(this[`_${i}`]===t.value)return;let s;if(["latitude","longitude"].includes(i))s=Number(t.value),this._config=Object.assign(Object.assign({},this._config),{[i]:s});else if(s&&0===s.length){const e=Object.assign({},this._config);delete e[i],this._config=e}else s=void 0!==t.checked?t.checked:t.value,this._config=Object.assign(Object.assign({},this._config),{[i]:s});if(s&&0===s.length){const e=Object.assign({},this._config);delete e[i],this._config=e}we(this,"config-changed",{config:this._config})}};ps.styles=l`
.card-config {
width: 100%;
margin-block: 0.5rem;
@@ -1297,7 +1328,6 @@ button.swiper-pagination-bullet {
}
ha-select,
ha-textfield {
- margin-bottom: 16px;
display: block;
width: 100%;
}
@@ -1314,10 +1344,32 @@ button.swiper-pagination-bullet {
}
.right-icon {
padding-inline: 0.5rem;
+ cursor: pointer;
}
+ .custom-background-wrapper {
+ display: inline-flex;
+ align-items: center;
+ gap: 1rem;
+ text-wrap: nowrap;
+ }
+ .file-input {
+ display: none;
+ }
+ .file-upload {
+ cursor: pointer;
+ display: inline-block;
+ padding: 0.5rem 1rem;
+ border: 1px solid var(--divider-color);
+ border-radius: 8px;
+ color: var(--primary-text-color);
+ }
+ .file-upload:hover {
+ background-color: var(--primary-color);
+ }
+
.version {
margin-top: 1rem;
color: var(--secondary-text-color);
text-align: start;
}
- `,e([xe({attribute:!1})],ds.prototype,"hass",void 0),e([Re()],ds.prototype,"_config",void 0),ds=e([pe("lunar-phase-card-editor")],ds);var ms=Object.freeze({__proto__:null,get LunarPhaseCardEditor(){return ds}});export{os as LunarPhaseCard};
+ `,e([xe({attribute:!1})],ps.prototype,"hass",void 0),e([Re()],ps.prototype,"_config",void 0),e([xe({type:String})],ps.prototype,"selectedOption",void 0),ps=e([pe("lunar-phase-card-editor")],ps);var ms=Object.freeze({__proto__:null,get LunarPhaseCardEditor(){return ps}});export{zs as LunarPhaseCard};
diff --git a/docs/README.md b/docs/README.md
index c199a8e..d63b4dd 100644
--- a/docs/README.md
+++ b/docs/README.md
@@ -37,13 +37,13 @@ https://github.com/ngocjohn/hass-config/assets/96962827/acc1a4db-b92e-4ab1-ac9d-
- 34,035 |
+ 34,028 |
31 |
186 |
37 |
52 |
35 |
- 1098 |
+ 1104 |
168 |
38 |
@@ -96,7 +96,6 @@ https://github.com/ngocjohn/hass-config/assets/96962827/acc1a4db-b92e-4ab1-ac9d-
- [Govee](https://github.com/LaggAt/hacs-govee)
- [HACS](https://github.com/hacs/integration)
- [Hass Favicon](https://github.com/thomasloven/hass-favicon)
-- [Lunar Phase](https://github.com/ngocjohn/lunar-phase)
- [Mercedesme 2020](https://github.com/ReneNulschDE/mbapi2020)
- [Music Assistant](https://github.com/music-assistant/hass-music-assistant)
- [Node Red Companion](https://github.com/zachowj/hass-node-red)