Skip to content

Commit

Permalink
Auto-minify and merge JS files
Browse files Browse the repository at this point in the history
  • Loading branch information
GitHub Actions committed Jan 27, 2025
1 parent 323fa34 commit c62f078
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion dist/ha-public-transport-connection-card.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,4 +190,4 @@ function delayToMinutes(delay){if(typeof delay==="number"){return delay}if(typeo
.ptc-theme-homeassistant h1 {
color: var(--ha-card-header-color, --primary-text-color);
}
`}}class MultiPublicTransportConnectionCard extends AbstractConnectionListCard{static getConfigForm(){return{schema:[{name:"entity",required:true,selector:{entity:{domain:"sensor"}}},{name:"title",selector:{text:{}}},{name:"icon",selector:{icon:{}}},{name:"departure_station",selector:{text:{}}},{name:"arrival_station",selector:{text:{}}},{name:"connections_attribute",required:true,selector:{attribute:{entity_id:""}},context:{filter_entity:"entity"}},{name:"connection_properties",type:"grid",schema:[{name:"description",selector:{text:{}}},{name:"departure_time",selector:{text:{}}},{name:"departure_delay",selector:{text:{}}},{name:"arrival_time",selector:{text:{}}},{name:"arrival_delay",selector:{text:{}}}]},{name:"displayed_connections",selector:{number:{min:1}}},{name:"theme",selector:{select:{options:AbstractConnectionListCard.AVAILABLE_THEMES,custom_value:true}}}]}}static getStubConfig(hass,unusedEntities,allEntities){const defaultAttributes={connections:["departures","connections"],departureStation:["start","origin"],arrivalStation:["goal","destination"]};function getAttributeName(entityId,defaultAttributes){const entity=hass.states[entityId]??{attributes:{}};for(const attribute of defaultAttributes){if(entity.attributes[attribute]!==undefined){return attribute}}return undefined}function getAttribute(entityId,defaultAttributes,defaultValue=undefined){const entity=hass.states[entityId]??{attributes:{}};const attributeName=getAttributeName(entityId,defaultAttributes);if(attributeName===undefined){return defaultValue}else{return entity.attributes[attributeName]}}function isPublicTransportSensor(entityId){if(entityId.split(".")[0]!=="sensor"){return false}return getAttributeName(entityId,defaultAttributes.connections)!==undefined}let entityId=unusedEntities.find(isPublicTransportSensor);if(!entityId){entityId=allEntities.find(isPublicTransportSensor)||""}return{...AbstractConnectionListCard.getStubConfig(hass,unusedEntities,allEntities),departure_station:getAttribute(entityId,defaultAttributes.departureStation,""),arrival_station:getAttribute(entityId,defaultAttributes.arrivalStation,""),connections_attribute:getAttributeName(entityId,defaultAttributes.connections),connection_properties:{description:"products",departure_time:"departure",departure_delay:"delay",arrival_time:"arrival",arrival_delay:"delay_arrival"},displayed_connections:3}}getConnections(entityId,stateObj){const connections=[];const nextConnections=stateObj.attributes[this.config.connections_attribute]||[];for(let i=0;i<this.config.displayed_connections&&i<nextConnections.length;i++){const nextConnection=nextConnections[i];if(nextConnection===undefined){continue}const nextDescription=nextConnection[this.config.connection_properties.description]||"";connections.push({description:Array.isArray(nextDescription)?nextDescription.join(", "):nextDescription,departure:{time:timeToStr(nextConnection[this.config.connection_properties.departure_time]),delay:delayToMinutes(nextConnection[this.config.connection_properties.departure_delay]),station:nextConnection[this.config.connection_properties.departure_station]||this.config.departure_station||""},arrival:{time:timeToStr(nextConnection[this.config.connection_properties.arrival_time]),delay:delayToMinutes(nextConnection[this.config.connection_properties.arrival_delay]),station:nextConnection[this.config.connection_properties.arrival_station]||this.config.arrival_station||""}})}return connections}checkConfig(config){if(!config.displayed_connections||config.displayed_connections<1){throw new Error("displayed_connections must be set to 1 or higher")}if(!config.connections_attribute){throw new Error("You must define the connections_attribute")}if(!config.connection_properties.departure_time){throw new Error("You must define the departure_time property for connection entries")}if(!config.connection_properties.arrival_time){throw new Error("You must define the arrival_time property for connection entries")}}}customElements.define("public-transport-connections-card",MultiPublicTransportConnectionCard);window.customCards=window.customCards||[];window.customCards.push({type:"public-transport-connections-card",name:"Public Transport Connections",preview:true,description:"Display your next connections via public transportation.",documentationURL:"https://github.com/silviokennecke/ha-public-transport-connection-card/wiki/Public-Transport-Connection-Card#multiple-connections"});class SinglePublicTransportConnectionCard extends AbstractConnectionListCard{static getConfigForm(){return{schema:[{name:"entity",required:true,selector:{entity:{domain:"sensor"}}},{name:"title",selector:{text:{}}},{name:"icon",selector:{icon:{}}},{name:"departure_station",selector:{text:{}}},{name:"arrival_station",selector:{text:{}}},{name:"attributes",type:"grid",schema:[{name:"description",selector:{attribute:{entity_id:""}},context:{filter_entity:"entity"}},{name:"departure_time",required:true,selector:{attribute:{entity_id:""}},context:{filter_entity:"entity"}},{name:"departure_delay",selector:{attribute:{entity_id:""}},context:{filter_entity:"entity"}},{name:"departure_station",selector:{attribute:{entity_id:""}},context:{filter_entity:"entity"}},{name:"arrival_time",required:true,selector:{attribute:{entity_id:""}},context:{filter_entity:"entity"}},{name:"arrival_delay",selector:{attribute:{entity_id:""}},context:{filter_entity:"entity"}},{name:"arrival_station",selector:{attribute:{entity_id:""}},context:{filter_entity:"entity"}},{name:"next_departure_time",selector:{attribute:{entity_id:""}},context:{filter_entity:"entity"}},{name:"next_departure_delay",selector:{attribute:{entity_id:""}},context:{filter_entity:"entity"}},{name:"next_departure_station",selector:{attribute:{entity_id:""}},context:{filter_entity:"entity"}},{name:"next_arrival_time",selector:{attribute:{entity_id:""}},context:{filter_entity:"entity"}},{name:"next_arrival_delay",selector:{attribute:{entity_id:""}},context:{filter_entity:"entity"}},{name:"next_arrival_station",selector:{attribute:{entity_id:""}},context:{filter_entity:"entity"}}]},{name:"theme",selector:{select:{options:AbstractConnectionListCard.AVAILABLE_THEMES,custom_value:true}}}]}}static getStubConfig(hass,unusedEntities,allEntities){return{...AbstractConnectionListCard.getStubConfig(hass,unusedEntities,allEntities),attributes:{description:"",departure_time:"",departure_delay:"",departure_station:"",arrival_time:"",arrival_delay:"",arrival_station:"",next_departure_time:"",next_departure_delay:"",next_departure_station:"",next_arrival_time:"",next_arrival_delay:"",next_arrival_station:""}}}getConnections(entityId,stateObj){const connections=[];const description=stateObj.attributes[this.config.attributes.description]||"";connections.push({description:Array.isArray(description)?description.join(", "):description,departure:{time:timeToStr(stateObj.attributes[this.config.attributes.departure_time]),delay:delayToMinutes(stateObj.attributes[this.config.attributes.departure_delay]),station:stateObj.attributes[this.config.attributes.departure_station]||this.config.departure_station||""},arrival:{time:timeToStr(stateObj.attributes[this.config.attributes.arrival_time]),delay:delayToMinutes(stateObj.attributes[this.config.attributes.arrival_delay]),station:stateObj.attributes[this.config.attributes.arrival_station]||this.config.arrival_station||""}});if(this.config.attributes.next_departure_time&&this.config.attributes.next_arrival_time){const nextDescription=stateObj.attributes[this.config.attributes.next_description]||"";connections.push([{description:Array.isArray(nextDescription)?nextDescription.join(", "):nextDescription,departure:{time:timeToStr(stateObj.attributes[this.config.attributes.next_departure_time]),delay:delayToMinutes(stateObj.attributes[this.config.attributes.next_departure_delay]),station:stateObj.attributes[this.config.attributes.next_departure_station]||this.config.departure_station||""},arrival:{time:timeToStr(stateObj.attributes[this.config.attributes.next_arrival_time]),delay:delayToMinutes(stateObj.attributes[this.config.attributes.next_arrival_delay]),station:stateObj.attributes[this.config.attributes.next_arrival_station]||this.config.arrival_station||""}}])}return connections}checkConfig(config){if(!config.attributes.departure_time){throw new Error("You need to define the departure attribute")}if(!config.attributes.arrival_time){throw new Error("You need to define the arrival attribute")}if(config.attributes.next_departure_time&&!config.attributes.next_arrival_time){throw new Error("If you define the next_departure attribute, you need to also define the next_arrival attribute")}}}customElements.define("public-transport-connections-attributes-card",SinglePublicTransportConnectionCard);window.customCards=window.customCards||[];window.customCards.push({type:"public-transport-connections-attributes-card",name:"Public Transport Connections (via Attributes)",preview:false,description:"Display your current and next connection via public transportation.",documentationURL:"https://github.com/silviokennecke/ha-public-transport-connection-card/wiki/Public-Transport-Connection-Card#single-connection"});
`}}class MultiPublicTransportConnectionCard extends AbstractConnectionListCard{static getConfigForm(){return{schema:[{name:"entity",required:true,selector:{entity:{domain:"sensor"}}},{name:"title",selector:{text:{}}},{name:"icon",selector:{icon:{}}},{name:"departure_station",selector:{text:{}}},{name:"arrival_station",selector:{text:{}}},{name:"connections_attribute",required:true,selector:{attribute:{entity_id:""}},context:{filter_entity:"entity"}},{name:"connection_properties",type:"grid",schema:[{name:"description",selector:{text:{}}},{name:"departure_time",selector:{text:{}}},{name:"departure_delay",selector:{text:{}}},{name:"arrival_time",selector:{text:{}}},{name:"arrival_delay",selector:{text:{}}}]},{name:"displayed_connections",selector:{number:{min:1}}},{name:"theme",selector:{select:{options:AbstractConnectionListCard.AVAILABLE_THEMES,custom_value:true}}}]}}static getStubConfig(hass,unusedEntities,allEntities){const defaultAttributes={connections:["departures","connections"],departureStation:["start","origin"],arrivalStation:["goal","destination"]};function getAttributeName(entityId,defaultAttributes){const entity=hass.states[entityId]??{attributes:{}};for(const attribute of defaultAttributes){if(entity.attributes[attribute]!==undefined){return attribute}}return undefined}function getAttribute(entityId,defaultAttributes,defaultValue=undefined){const entity=hass.states[entityId]??{attributes:{}};const attributeName=getAttributeName(entityId,defaultAttributes);if(attributeName===undefined){return defaultValue}else{return entity.attributes[attributeName]}}function isPublicTransportSensor(entityId){if(entityId.split(".")[0]!=="sensor"){return false}return getAttributeName(entityId,defaultAttributes.connections)!==undefined}let entityId=unusedEntities.find(isPublicTransportSensor);if(!entityId){entityId=allEntities.find(isPublicTransportSensor)||""}return{...AbstractConnectionListCard.getStubConfig(hass,unusedEntities,allEntities),departure_station:getAttribute(entityId,defaultAttributes.departureStation,""),arrival_station:getAttribute(entityId,defaultAttributes.arrivalStation,""),connections_attribute:getAttributeName(entityId,defaultAttributes.connections),connection_properties:{description:"products",departure_time:"departure",departure_delay:"delay",arrival_time:"arrival",arrival_delay:"delay_arrival"},displayed_connections:3}}getConnections(entityId,stateObj){const connections=[];const nextConnections=stateObj.attributes[this.config.connections_attribute]||[];for(let i=0;i<this.config.displayed_connections&&i<nextConnections.length;i++){const nextConnection=nextConnections[i];if(nextConnection===undefined){continue}const nextDescription=nextConnection[this.config.connection_properties.description]||"";connections.push({description:Array.isArray(nextDescription)?nextDescription.join(", "):nextDescription,departure:{time:timeToStr(nextConnection[this.config.connection_properties.departure_time]),delay:delayToMinutes(nextConnection[this.config.connection_properties.departure_delay]),station:nextConnection[this.config.connection_properties.departure_station]||this.config.departure_station||""},arrival:{time:timeToStr(nextConnection[this.config.connection_properties.arrival_time]),delay:delayToMinutes(nextConnection[this.config.connection_properties.arrival_delay]),station:nextConnection[this.config.connection_properties.arrival_station]||this.config.arrival_station||""}})}return connections}checkConfig(config){if(!config.displayed_connections||config.displayed_connections<1){throw new Error("displayed_connections must be set to 1 or higher")}if(!config.connections_attribute){throw new Error("You must define the connections_attribute")}if(!config.connection_properties.departure_time){throw new Error("You must define the departure_time property for connection entries")}if(!config.connection_properties.arrival_time){throw new Error("You must define the arrival_time property for connection entries")}}}customElements.define("public-transport-connections-card",MultiPublicTransportConnectionCard);window.customCards=window.customCards||[];window.customCards.push({type:"public-transport-connections-card",name:"Public Transport Connections",preview:true,description:"Display your next connections via public transportation.",documentationURL:"https://github.com/silviokennecke/ha-public-transport-connection-card/wiki/Public-Transport-Connection-Card#multiple-connections"});class SinglePublicTransportConnectionCard extends AbstractConnectionListCard{static getConfigForm(){return{schema:[{name:"entity",required:true,selector:{entity:{domain:"sensor"}}},{name:"title",selector:{text:{}}},{name:"icon",selector:{icon:{}}},{name:"departure_station",selector:{text:{}}},{name:"arrival_station",selector:{text:{}}},{name:"attributes",type:"grid",schema:[{name:"description",selector:{attribute:{entity_id:""}},context:{filter_entity:"entity"}},{name:"departure_time",required:true,selector:{attribute:{entity_id:""}},context:{filter_entity:"entity"}},{name:"departure_delay",selector:{attribute:{entity_id:""}},context:{filter_entity:"entity"}},{name:"departure_station",selector:{attribute:{entity_id:""}},context:{filter_entity:"entity"}},{name:"arrival_time",required:true,selector:{attribute:{entity_id:""}},context:{filter_entity:"entity"}},{name:"arrival_delay",selector:{attribute:{entity_id:""}},context:{filter_entity:"entity"}},{name:"arrival_station",selector:{attribute:{entity_id:""}},context:{filter_entity:"entity"}},{name:"next_departure_time",selector:{attribute:{entity_id:""}},context:{filter_entity:"entity"}},{name:"next_departure_delay",selector:{attribute:{entity_id:""}},context:{filter_entity:"entity"}},{name:"next_departure_station",selector:{attribute:{entity_id:""}},context:{filter_entity:"entity"}},{name:"next_arrival_time",selector:{attribute:{entity_id:""}},context:{filter_entity:"entity"}},{name:"next_arrival_delay",selector:{attribute:{entity_id:""}},context:{filter_entity:"entity"}},{name:"next_arrival_station",selector:{attribute:{entity_id:""}},context:{filter_entity:"entity"}}]},{name:"theme",selector:{select:{options:AbstractConnectionListCard.AVAILABLE_THEMES,custom_value:true}}}]}}static getStubConfig(hass,unusedEntities,allEntities){return{...AbstractConnectionListCard.getStubConfig(hass,unusedEntities,allEntities),attributes:{description:"",departure_time:"",departure_delay:"",departure_station:"",arrival_time:"",arrival_delay:"",arrival_station:"",next_departure_time:"",next_departure_delay:"",next_departure_station:"",next_arrival_time:"",next_arrival_delay:"",next_arrival_station:""}}}getConnections(entityId,stateObj){const connections=[];const description=stateObj.attributes[this.config.attributes.description]||"";connections.push({description:Array.isArray(description)?description.join(", "):description,departure:{time:timeToStr(stateObj.attributes[this.config.attributes.departure_time]),delay:delayToMinutes(stateObj.attributes[this.config.attributes.departure_delay]),station:stateObj.attributes[this.config.attributes.departure_station]||this.config.departure_station||""},arrival:{time:timeToStr(stateObj.attributes[this.config.attributes.arrival_time]),delay:delayToMinutes(stateObj.attributes[this.config.attributes.arrival_delay]),station:stateObj.attributes[this.config.attributes.arrival_station]||this.config.arrival_station||""}});if(this.config.attributes.next_departure_time&&this.config.attributes.next_arrival_time){const nextDescription=stateObj.attributes[this.config.attributes.next_description]||"";connections.push([{description:Array.isArray(nextDescription)?nextDescription.join(", "):nextDescription,departure:{time:timeToStr(stateObj.attributes[this.config.attributes.next_departure_time]),delay:delayToMinutes(stateObj.attributes[this.config.attributes.next_departure_delay]),station:stateObj.attributes[this.config.attributes.next_departure_station]||this.config.departure_station||""},arrival:{time:timeToStr(stateObj.attributes[this.config.attributes.next_arrival_time]),delay:delayToMinutes(stateObj.attributes[this.config.attributes.next_arrival_delay]),station:stateObj.attributes[this.config.attributes.next_arrival_station]||this.config.arrival_station||""}}])}return connections}checkConfig(config){if(!config.attributes.departure_time){throw new Error("You need to define the departure attribute")}if(!config.attributes.arrival_time){throw new Error("You need to define the arrival attribute")}if(config.attributes.next_departure_time&&!config.attributes.next_arrival_time){throw new Error("If you define the next_departure attribute, you need to also define the next_arrival attribute")}}}customElements.define("public-transport-connections-attributes-card",SinglePublicTransportConnectionCard);window.customCards=window.customCards||[];window.customCards.push({type:"public-transport-connections-attributes-card",name:"Public Transport Connections (via Attributes)",preview:false,description:"Display your current and next connection via public transportation.",documentationURL:"https://github.com/silviokennecke/ha-public-transport-connection-card/wiki/Public-Transport-Connection-Card#single-connection"});

0 comments on commit c62f078

Please sign in to comment.