"use strict"; import { LitElement, html, css } from "lit-element"; import { state } from "../state.js"; import { pad, formatDate, round, get } from "../util.js"; import { archive } from "../archive.js"; import "@authentic/mwc-icon"; import "../card.js"; import "../spinner.js"; class TemperatureLive extends LitElement { constructor() { super(...arguments); this._cachedDayArchive = {}; state.subscribe(this.requestUpdate.bind(this)); archive.subscribe(this.requestUpdate.bind(this)); } render() { const config = state.config.views.filter(view => view.url == this.viewid)[0]; return html` ${state.data[config.sensors[0].device] ? html`
${state.connected ? html`

cloud_queue Connected

` : html`

cloud_off Disconnected

last updated ${formatDate(state.data.lastUpdated)}

`}
Name
Temperature
Humidity
${config.sensors.map(d => html`
${d.name}${state.data[d.device].weakBattery ? html` battery_alert` : html``}
${round(state.data[d.device].temperature, 2)}°C
${(state.data[d.device].humidity != -1 ) ? html`${round(state.data[d.device].humidity, 2)}%` : html`-` }
`)}
` : html` Trying to connect... `} `; } static get styles() { return css` :host { display: flex; flex-direction: column; --mdc-theme-on-primary: white; --mdc-theme-primary: #43a047; --mdc-theme-on-secondary: white; --mdc-theme-secondary: #616161; } #connection-status mwc-icon { padding-right: .5em; } #connection-status { display: flex; flex-direction: column; justify-content: center; align-items: center; } #connection-status>p { display: flex; flex-direction: row; justify-content: center; align-items: center; } #connection-status>p.lastupdate { font-size: 1em; } .table { display: flex; flex-direction: column; } .table-row { display: flex; flex-direction: row; width: 100%; } .table-column { padding: 1em; height: 1em; display: flex; flex-direction: column; justify-content: center; } .table-row { background-color: #ddd; } .table-row:nth-child(2n) { background-color: #fff; } @media (min-width: 600px) { #connection-status { margin-top: 20px; } } `; } static get properties() { return { viewid: { type: String } }; } } customElements.define("smarthome-temperature-live", TemperatureLive);