frontend/hassio/system/hassio-host-info.html

129 lines
3.2 KiB
HTML

<link rel="import" href="../../bower_components/polymer/polymer-element.html">
<link rel="import" href="../../bower_components/paper-card/paper-card.html">
<link rel="import" href="../../src/components/buttons/ha-call-api-button.html">
<dom-module id="hassio-host-info">
<template>
<style include="iron-flex ha-style">
paper-card {
display: inline-block;
width: 350px;
}
.card-content {
height: 110px;
}
@media screen and (max-width: 730px) {
paper-card {
margin-top: 8px;
width: 100%;
height: 100%;
}
.card-content {
height: 100%;
}
}
.info {
width: 100%;
}
.info td:nth-child(2) {
text-align: right;
}
.errors {
color: var(--google-red-500);
margin-top: 16px;
}
</style>
<paper-card heading="Host system">
<div class="card-content">
<table class='info'>
<tr>
<td>Type</td>
<td>[[data.type]] ([[data.os]])</td>
</tr>
<tr>
<td>Host controller version</td>
<td>[[data.version]]</td>
</tr>
<tr>
<td>Latest version</td>
<td>[[data.last_version]]</td>
</tr>
</table>
<template is='dom-if' if='[[errors]]'>
<div class='errors'>Error: [[errors]]</div>
</template>
</div>
<div class="card-actions">
<template is='dom-if' if='[[computeUpdateAvailable(data)]]'>
<ha-call-api-button
hass='[[hass]]'
path="hassio/host/update"
>Update</ha-call-api-button>
</template>
<template is='dom-if' if='[[computeRebootAvailable(data)]]'>
<ha-call-api-button
class='warning'
hass='[[hass]]'
path="hassio/host/reboot"
>Reboot</ha-call-api-button>
</template>
<template is='dom-if' if='[[computeShutdownAvailable(data)]]'>
<ha-call-api-button
class='warning'
hass='[[hass]]'
path="hassio/host/shutdown"
>Shutdown</ha-call-api-button>
</template>
</div>
</paper-card>
</template>
</dom-module>
<script>
class HassioHostInfo extends Polymer.Element {
static get is() { return 'hassio-host-info'; }
static get properties() {
return {
hass: Object,
data: Object,
errors: String,
};
}
ready() {
super.ready();
this.addEventListener('hass-api-called', ev => this.apiCalled(ev));
}
apiCalled(ev) {
if (ev.detail.success) {
this.errors = null;
return;
}
var response = ev.detail.response;
if (typeof response.body === 'object') {
this.errors = response.body.message || 'Unknown error';
} else {
this.errors = response.body;
}
}
computeUpdateAvailable(data) {
return data.version !== data.last_version;
}
computeRebootAvailable(data) {
return data.features && data.features.includes('reboot');
}
computeShutdownAvailable(data) {
return data.features && data.features.includes('shutdown');
}
}
customElements.define(HassioHostInfo.is, HassioHostInfo);
</script>