diff --git a/CHANGELOG.md b/CHANGELOG.md index 7d93f87..705a763 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,9 @@ # Changelog All notable changes to this project will be documented in this file. +## v3.0.3 +- fix + ## v3.0.2 - rename the version with 'v' diff --git a/body-miscale-card.js b/body-miscale-card.js index acca1b2..2754389 100644 --- a/body-miscale-card.js +++ b/body-miscale-card.js @@ -354,7 +354,7 @@ input.divcheck + div { } input.divcheck:checked + div { display:block; -}`;customElements.get("ha-icon-button")||customElements.define("ha-icon-button",class extends(customElements.get("paper-icon-button")){});const Ie={status:{key:"status",icon:"mdi:scale-bathroom"},problem:{key:"problem",icon:"mdi:alert"}},Ue={weight:{key:"weight",label:je("attributes.Weight: "),unit:" kg"},impedance:{key:"impedance",label:je("attributes.Impedance: "),unit:" ohm"},height:{key:"height",label:je("attributes.Height: "),unit:" cm"},age:{key:"age",label:je("attributes.Age: "),unit:je("unit. years")},gender:{key:"gender",label:je("attributes.Gender: ")}},Ye={water:{key:"Water",label:je("body.Water"),icon:"file:water",unit:" %"},visceral_fat:{key:"Visceral fat",label:je("body.Visceral fat"),icon:"file:visceral_fat"},body_fat:{key:"Body fat",label:je("body.Body fat"),icon:"file:body_fat",unit:" %"},bmi:{key:"BMI",label:je("body.BMI"),icon:"file:bmi"},muscle_mass:{key:"Muscle mass",label:je("body.Muscle mass"),icon:"file:muscle_mass",unit:" kg"},protein:{key:"Protein",label:je("body.Protein"),icon:"file:protein",unit:" %"},basal_metabolism:{key:"Basal metabolism",label:je("body.Basal metabolism"),icon:"file:basal_metabolism",unit:" kcal"},bone_mass:{key:"Bone mass",label:je("body.Bone mass"),icon:"file:bone_mass",unit:" kg"},metabolic_age:{key:"Metabolic age",label:je("body.Metabolic age"),icon:"file:metabolic_age",unit:" years"},ideal:{key:"Ideal",label:je("body.Ideal"),icon:"file:ideal",unit:" kg"},body_type:{key:"Body type",label:je("body.Body type"),icon:"file:body_type"}},He={user1:{label:"User1",icon:"mdi:alpha-u-circle"},user2:{show:!1,label:"User2",icon:"mdi:alpha-u-circle"},user3:{show:!1,label:"User3",icon:"mdi:alpha-u-circle"},user4:{show:!1,label:"User4",icon:"mdi:alpha-u-circle"},user5:{show:!1,label:"User5",icon:"mdi:alpha-u-circle"}},Re={miscale:{buttons:{user1:{show:!1}},attributes:{weight:{key:"weight"},impedance:!1,height:{key:"height"},age:{key:"age"},gender:{key:"gender"}}},"181D":{state:{status:{key:"state"}},attributes:{weight:{key:"weight"},impedance:!1,height:{key:"height"},age:{key:"age"},gender:{key:"gender"}},body:{water:!1,visceral_fat:{key:"Visceral fat"},body_fat:!1,bmi:{key:"BMI"},muscle_mass:!1,protein:!1,basal_metabolism:{key:"Basal metabolism"},bone_mass:!1,metabolic_age:!1,ideal:{key:"Ideal"},body_type:{key:"Body type"}}},"181B":{state:{status:{key:"state"}},attributes:{weight:{key:"weight"},impedance:{key:"impedance"},height:{key:"height"},age:{key:"age"},gender:{key:"gender"}},body:{water:{key:"Water"},visceral_fat:{key:"Visceral fat"},body_fat:{key:"Body fat"},bmi:{key:"BMI"},muscle_mass:{key:"Muscle mass"},protein:{key:"Protein"},basal_metabolism:{key:"Basal metabolism"},bone_mass:{key:"Bone mass"},metabolic_age:{key:"Metabolic age"},ideal:{key:"Ideal"},body_type:{key:"Body type"}}}};customElements.define("body*miscale-card",class extends K{static get properties(){return{_hass:{},config:{},stateObj:{}}}static get styles(){return De}static async getConfigElement(){return document.createElement("body-miscale-card-editor")}static getStubConfig(e,t){const[s]=t.filter((e=>"bodymiscale"===e.substr(0,e.indexOf("."))));return{entity:s||""}}get entity(){return this.hass.states[this.config.entity]}get showName(){return void 0===this.config.show.name||this.config.show.name}get showState(){return void 0===this.config.show.state||this.config.show.state}get showAttributes(){return void 0===this.config.show.attributes||this.config.show.attributes}get showBody(){return void 0===this.config.show.body||this.config.show.body}get showButtons(){return void 0===this.config.show.buttons||this.config.show.buttons}get showToolbar(){return void 0===this.config.show_toolbar||this.config.show_toolbar}setConfig(e){if(!e.entity)throw new Error("Please define an entity.");if("bodymiscale"!==e.entity.split(".")[0])throw new Error("Please define a bodymiscale entity.");if(e.model&&!e.model in Re)throw new Error("Please define a valid model.");const t=Re[e.model]||Re.miscale;this.config={name:e.name,entity:e.entity,show:{name:!1!==e.show_name,state:!1!==e.show_state,body:!1!==e.show_body,attributes:!1!==e.show_attributes,buttons:!1!==e.show_buttons},buttons:this.deepMerge(He,t.buttons,e.buttons),state:this.deepMerge(Ie,t.state,e.state),body:this.deepMerge(Ye,t.body,e.body),attributes:this.deepMerge(Ue,t.attributes,e.attributes),styles:{background:e.image?`background-image: url('${e.image}'); color: white; text-shadow: 0 0 10px black;`:"",icon:`color: ${e.image?"white":"var(--paper-item-icon-color)"};`,content:`padding: ${!1!==e.name?"8px":"16px"} 16px ${!1!==e.buttons?"8px":"16px"};`}}}set hass(e){e&&this.config&&(this.stateObj=this.config.entity in e.states?e.states[this.config.entity]:null),this._hass=e}getCardSize(){return this.config.show.name&&this.config.show.buttons?4:this.config.show.name||this.config.show.buttons?3:2}shouldUpdate(e){return e.has("stateObj")}handleChange(e,t){const s=e.target.getAttribute("value");this.callService("bodymiscale.set_"+t,{entity_id:this.stateObj.entity_id,[t]:s})}callService(e,t={entity_id:this.stateObj.entity_id}){const[s,i]=e.split(".");this._hass.callService(s,i,t)}fireEvent(e,t={}){const s=new Event(e,{bubbles:t.bubbles||!0,cancelable:t.cancelable||!0,composed:t.composed||!0});s.detail={entityId:this.stateObj.entity_id},this.dispatchEvent(s)}deepMerge(...e){const t=e=>e&&"object"==typeof e,s={};return e.filter((e=>t(e))).forEach((e=>{Object.keys(e).forEach((i=>{const o=s[i],n=e[i];Array.isArray(o)&&Array.isArray(n)?s[i]=o.concat(n):t(o)&&t(n)?s[i]=this.deepMerge(Object.assign({},o),n):s[i]=n}))})),s}renderName(){return this.showName?V`
${this.config.name||this.stateObj.attributes.friendly_name}
`:V``}renderState(e){if(!this.showState)return V``;const t=e.compute||(e=>e),s=e&&e.key in this.stateObj.attributes,i=e&&e.key in this.stateObj,o=s?t(this.stateObj.attributes[e.key])+(e.unit||""):i?t(this.stateObj[e.key])+(e.unit||""):this._hass.localize("state.default.unavailable"),n=V`
${e.icon&&this.renderIcon(e)}${(e.label||"")+je("state."+o)}
`;return e.key+"_list"in this.stateObj.attributes&&(s||i)?this.renderDropdown(n,e.key):n}renderAttribute(e){if(!this.showAttributes)return V``;const t=e.compute||(e=>e),s=e&&e.key in this.stateObj.attributes,i=e&&e.key in this.stateObj,o=s?t(this.stateObj.attributes[e.key])+(e.unit||""):i?t(this.stateObj[e.key])+(e.unit||""):this._hass.localize("state.default.unavailable"),n=V`
${e.icon&&this.renderIcon(e)}${(e.label||"")+o}
`;return e.key+"_list"in this.stateObj.attributes&&(s||i)?this.renderDropdown(n,e.key):n}renderBody(e){if(!this.showBody)return V``;const t=e.compute||(e=>e),s=e&&e.key in this.stateObj.attributes,i=e&&e.key in this.stateObj,o=s?t(this.stateObj.attributes[e.key])+(e.unit||""):i?t(this.stateObj[e.key])+(e.unit||""):this._hass.localize("state.default.unavailable"),n=V`
+}`;customElements.get("ha-icon-button")||customElements.define("ha-icon-button",class extends(customElements.get("paper-icon-button")){});const Ie={status:{key:"status",icon:"mdi:scale-bathroom"},problem:{key:"problem",icon:"mdi:alert"}},Ue={weight:{key:"weight",label:je("attributes.Weight: "),unit:" kg"},impedance:{key:"impedance",label:je("attributes.Impedance: "),unit:" ohm"},height:{key:"height",label:je("attributes.Height: "),unit:" cm"},age:{key:"age",label:je("attributes.Age: "),unit:je("unit. years")},gender:{key:"gender",label:je("attributes.Gender: ")}},Ye={water:{key:"Water",label:je("body.Water"),icon:"file:water",unit:" %"},visceral_fat:{key:"Visceral fat",label:je("body.Visceral fat"),icon:"file:visceral_fat"},body_fat:{key:"Body fat",label:je("body.Body fat"),icon:"file:body_fat",unit:" %"},bmi:{key:"BMI",label:je("body.BMI"),icon:"file:bmi"},muscle_mass:{key:"Muscle mass",label:je("body.Muscle mass"),icon:"file:muscle_mass",unit:" kg"},protein:{key:"Protein",label:je("body.Protein"),icon:"file:protein",unit:" %"},basal_metabolism:{key:"Basal metabolism",label:je("body.Basal metabolism"),icon:"file:basal_metabolism",unit:" kcal"},bone_mass:{key:"Bone mass",label:je("body.Bone mass"),icon:"file:bone_mass",unit:" kg"},metabolic_age:{key:"Metabolic age",label:je("body.Metabolic age"),icon:"file:metabolic_age",unit:" years"},ideal:{key:"Ideal",label:je("body.Ideal"),icon:"file:ideal",unit:" kg"},body_type:{key:"Body type",label:je("body.Body type"),icon:"file:body_type"}},He={user1:{label:"User1",icon:"mdi:alpha-u-circle"},user2:{show:!1,label:"User2",icon:"mdi:alpha-u-circle"},user3:{show:!1,label:"User3",icon:"mdi:alpha-u-circle"},user4:{show:!1,label:"User4",icon:"mdi:alpha-u-circle"},user5:{show:!1,label:"User5",icon:"mdi:alpha-u-circle"}},Re={miscale:{buttons:{user1:{show:!1}},attributes:{weight:{key:"weight"},impedance:!1,height:{key:"height"},age:{key:"age"},gender:{key:"gender"}}},"181D":{state:{status:{key:"state"}},attributes:{weight:{key:"weight"},impedance:!1,height:{key:"height"},age:{key:"age"},gender:{key:"gender"}},body:{water:!1,visceral_fat:{key:"Visceral fat"},body_fat:!1,bmi:{key:"BMI"},muscle_mass:!1,protein:!1,basal_metabolism:{key:"Basal metabolism"},bone_mass:!1,metabolic_age:!1,ideal:{key:"Ideal"},body_type:{key:"Body type"}}},"181B":{state:{status:{key:"state"}},attributes:{weight:{key:"weight"},impedance:{key:"impedance"},height:{key:"height"},age:{key:"age"},gender:{key:"gender"}},body:{water:{key:"Water"},visceral_fat:{key:"Visceral fat"},body_fat:{key:"Body fat"},bmi:{key:"BMI"},muscle_mass:{key:"Muscle mass"},protein:{key:"Protein"},basal_metabolism:{key:"Basal metabolism"},bone_mass:{key:"Bone mass"},metabolic_age:{key:"Metabolic age"},ideal:{key:"Ideal"},body_type:{key:"Body type"}}}};customElements.define("body-miscale-card",class extends K{static get properties(){return{_hass:{},config:{},stateObj:{}}}static get styles(){return De}static async getConfigElement(){return document.createElement("body-miscale-card-editor")}static getStubConfig(e,t){const[s]=t.filter((e=>"bodymiscale"===e.substr(0,e.indexOf("."))));return{entity:s||""}}get entity(){return this.hass.states[this.config.entity]}get showName(){return void 0===this.config.show.name||this.config.show.name}get showState(){return void 0===this.config.show.state||this.config.show.state}get showAttributes(){return void 0===this.config.show.attributes||this.config.show.attributes}get showBody(){return void 0===this.config.show.body||this.config.show.body}get showButtons(){return void 0===this.config.show.buttons||this.config.show.buttons}get showToolbar(){return void 0===this.config.show_toolbar||this.config.show_toolbar}setConfig(e){if(!e.entity)throw new Error("Please define an entity.");if("bodymiscale"!==e.entity.split(".")[0])throw new Error("Please define a bodymiscale entity.");if(e.model&&!e.model in Re)throw new Error("Please define a valid model.");const t=Re[e.model]||Re.miscale;this.config={name:e.name,entity:e.entity,show:{name:!1!==e.show_name,state:!1!==e.show_state,body:!1!==e.show_body,attributes:!1!==e.show_attributes,buttons:!1!==e.show_buttons},buttons:this.deepMerge(He,t.buttons,e.buttons),state:this.deepMerge(Ie,t.state,e.state),body:this.deepMerge(Ye,t.body,e.body),attributes:this.deepMerge(Ue,t.attributes,e.attributes),styles:{background:e.image?`background-image: url('${e.image}'); color: white; text-shadow: 0 0 10px black;`:"",icon:`color: ${e.image?"white":"var(--paper-item-icon-color)"};`,content:`padding: ${!1!==e.name?"8px":"16px"} 16px ${!1!==e.buttons?"8px":"16px"};`}}}set hass(e){e&&this.config&&(this.stateObj=this.config.entity in e.states?e.states[this.config.entity]:null),this._hass=e}getCardSize(){return this.config.show.name&&this.config.show.buttons?4:this.config.show.name||this.config.show.buttons?3:2}shouldUpdate(e){return e.has("stateObj")}handleChange(e,t){const s=e.target.getAttribute("value");this.callService("bodymiscale.set_"+t,{entity_id:this.stateObj.entity_id,[t]:s})}callService(e,t={entity_id:this.stateObj.entity_id}){const[s,i]=e.split(".");this._hass.callService(s,i,t)}fireEvent(e,t={}){const s=new Event(e,{bubbles:t.bubbles||!0,cancelable:t.cancelable||!0,composed:t.composed||!0});s.detail={entityId:this.stateObj.entity_id},this.dispatchEvent(s)}deepMerge(...e){const t=e=>e&&"object"==typeof e,s={};return e.filter((e=>t(e))).forEach((e=>{Object.keys(e).forEach((i=>{const o=s[i],n=e[i];Array.isArray(o)&&Array.isArray(n)?s[i]=o.concat(n):t(o)&&t(n)?s[i]=this.deepMerge(Object.assign({},o),n):s[i]=n}))})),s}renderName(){return this.showName?V`
${this.config.name||this.stateObj.attributes.friendly_name}
`:V``}renderState(e){if(!this.showState)return V``;const t=e.compute||(e=>e),s=e&&e.key in this.stateObj.attributes,i=e&&e.key in this.stateObj,o=s?t(this.stateObj.attributes[e.key])+(e.unit||""):i?t(this.stateObj[e.key])+(e.unit||""):this._hass.localize("state.default.unavailable"),n=V`
${e.icon&&this.renderIcon(e)}${(e.label||"")+je("state."+o)}
`;return e.key+"_list"in this.stateObj.attributes&&(s||i)?this.renderDropdown(n,e.key):n}renderAttribute(e){if(!this.showAttributes)return V``;const t=e.compute||(e=>e),s=e&&e.key in this.stateObj.attributes,i=e&&e.key in this.stateObj,o=s?t(this.stateObj.attributes[e.key])+(e.unit||""):i?t(this.stateObj[e.key])+(e.unit||""):this._hass.localize("state.default.unavailable"),n=V`
${e.icon&&this.renderIcon(e)}${(e.label||"")+o}
`;return e.key+"_list"in this.stateObj.attributes&&(s||i)?this.renderDropdown(n,e.key):n}renderBody(e){if(!this.showBody)return V``;const t=e.compute||(e=>e),s=e&&e.key in this.stateObj.attributes,i=e&&e.key in this.stateObj,o=s?t(this.stateObj.attributes[e.key])+(e.unit||""):i?t(this.stateObj[e.key])+(e.unit||""):this._hass.localize("state.default.unavailable"),n=V`
${e.icon&&this.renderIcon(e)}
diff --git a/tracker.json b/tracker.json index 3c8b230..a7736d3 100644 --- a/tracker.json +++ b/tracker.json @@ -1,7 +1,7 @@ { "body-miscale-card": { "updated_at": "2021-05-26", - "version": "v3.0.2", + "version": "v3.0.3", "remote_location": "https://raw.githubusercontent.com/dckiller51/lovelace-body-miscale-card/master/body-miscale-card.js", "visit_repo": "https://github.com/dckiller51/lovelace-body-miscale-card", "changelog": "https://github.com/dckiller51/lovelace-body-miscale-card/blob/master/CHANGELOG.md"