2022-05-01 15:35:20 +02:00
|
|
|
<template>
|
|
|
|
<div class="entity light-container">
|
|
|
|
<div class="head" :class="{expanded: expanded}">
|
|
|
|
<div class="col-1 icon">
|
2022-05-30 09:23:05 +02:00
|
|
|
<EntityIcon :icon="icon" :hasColorFill="true"
|
|
|
|
:loading="loading" :error="error" />
|
2022-05-01 15:35:20 +02:00
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class="col-s-8 col-m-9 label">
|
|
|
|
<div class="name" v-text="value.name" />
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class="col-s-3 col-m-2 buttons pull-right">
|
2022-05-30 09:23:05 +02:00
|
|
|
<ToggleSwitch :value="value.on" @input="toggle"
|
|
|
|
@click.stop :disabled="loading || value.is_read_only" />
|
|
|
|
|
2022-05-01 15:35:20 +02:00
|
|
|
<button @click.stop="expanded = !expanded">
|
|
|
|
<i class="fas"
|
|
|
|
:class="{'fa-angle-up': expanded, 'fa-angle-down': !expanded}" />
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class="body" v-if="expanded" @click.stop="prevent">
|
|
|
|
<div class="row" v-if="cssColor">
|
|
|
|
<div class="icon">
|
|
|
|
<i class="fas fa-palette" />
|
|
|
|
</div>
|
|
|
|
<div class="input">
|
|
|
|
<input type="color" :value="cssColor" @change="setLight({color: $event.target.value})" />
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class="row" v-if="value.brightness">
|
|
|
|
<div class="icon">
|
|
|
|
<i class="fas fa-sun" />
|
|
|
|
</div>
|
|
|
|
<div class="input">
|
|
|
|
<Slider :range="[value.brightness_min, value.brightness_max]"
|
|
|
|
:value="value.brightness" @input="setLight({brightness: $event.target.value})" />
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class="row" v-if="value.saturation">
|
|
|
|
<div class="icon">
|
|
|
|
<i class="fas fa-droplet" />
|
|
|
|
</div>
|
|
|
|
<div class="input">
|
|
|
|
<Slider :range="[value.saturation_min, value.saturation_max]"
|
|
|
|
:value="value.saturation" @input="setLight({saturation: $event.target.value})" />
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class="row" v-if="value.temperature">
|
|
|
|
<div class="icon">
|
|
|
|
<i class="fas fa-temperature-half" />
|
|
|
|
</div>
|
|
|
|
<div class="input">
|
|
|
|
<Slider :range="[value.temperature_min, value.temperature_max]"
|
|
|
|
:value="value.temperature" @input="setLight({temperature: $event.target.value})"/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
import Slider from "@/components/elements/Slider"
|
|
|
|
import ToggleSwitch from "@/components/elements/ToggleSwitch"
|
|
|
|
import EntityMixin from "./EntityMixin"
|
|
|
|
import EntityIcon from "./EntityIcon"
|
|
|
|
import {ColorConverter} from "@/components/panels/Light/color";
|
|
|
|
|
|
|
|
export default {
|
|
|
|
name: 'Light',
|
|
|
|
components: {ToggleSwitch, Slider, EntityIcon},
|
|
|
|
mixins: [EntityMixin],
|
|
|
|
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
expanded: false,
|
|
|
|
colorConverter: null,
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
computed: {
|
|
|
|
rgbColor() {
|
2022-05-30 09:23:05 +02:00
|
|
|
if (this.value.meta?.icon?.color)
|
|
|
|
return this.value.meta.icon.color
|
|
|
|
|
2022-05-01 15:35:20 +02:00
|
|
|
if (
|
2022-05-30 09:23:05 +02:00
|
|
|
!this.colorConverter || (
|
|
|
|
this.value.hue == null &&
|
|
|
|
(this.value.x == null || this.value.y == null)
|
|
|
|
)
|
2022-05-01 15:35:20 +02:00
|
|
|
)
|
|
|
|
return
|
|
|
|
|
|
|
|
if (this.value.x && this.value.y)
|
|
|
|
return this.colorConverter.xyToRgb(
|
|
|
|
this.value.x,
|
|
|
|
this.value.y,
|
|
|
|
this.value.brightness
|
|
|
|
)
|
|
|
|
|
|
|
|
return this.colorConverter.hslToRgb(
|
|
|
|
this.value.hue,
|
|
|
|
this.value.saturation,
|
|
|
|
this.value.brightness
|
|
|
|
)
|
|
|
|
},
|
|
|
|
|
|
|
|
cssColor() {
|
|
|
|
const rgb = this.rgbColor
|
|
|
|
if (rgb)
|
|
|
|
return this.colorConverter.rgbToHex(rgb)
|
|
|
|
return null
|
|
|
|
},
|
|
|
|
|
|
|
|
icon() {
|
|
|
|
const icon = {...(this.value.meta?.icon || {})}
|
|
|
|
if (!icon.color && this.cssColor)
|
|
|
|
icon.color = this.cssColor
|
|
|
|
return icon
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
methods: {
|
|
|
|
prevent(event) {
|
|
|
|
event.stopPropagation()
|
|
|
|
return false
|
|
|
|
},
|
|
|
|
|
|
|
|
async toggle(event) {
|
|
|
|
event.stopPropagation()
|
|
|
|
this.$emit('loading', true)
|
|
|
|
|
|
|
|
try {
|
|
|
|
await this.request('entities.execute', {
|
|
|
|
id: this.value.id,
|
|
|
|
action: 'toggle',
|
|
|
|
})
|
|
|
|
} finally {
|
|
|
|
this.$emit('loading', false)
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
async setLight(attrs) {
|
|
|
|
if (attrs.color) {
|
|
|
|
const rgb = this.colorConverter.hexToRgb(attrs.color)
|
|
|
|
if (this.value.x != null && this.value.y != null) {
|
|
|
|
attrs.xy = this.colorConverter.rgbToXY(...rgb)
|
|
|
|
delete attrs.color
|
|
|
|
} else if (this.value.hue != null) {
|
|
|
|
[attrs.hue, attrs.saturation, attrs.brightness] = this.colorConverter.rgbToHsl(...rgb)
|
|
|
|
delete attrs.color
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
this.execute({
|
|
|
|
type: 'request',
|
|
|
|
action: this.value.plugin + '.set_lights',
|
|
|
|
args: {
|
|
|
|
lights: [this.value.external_id],
|
|
|
|
...attrs,
|
|
|
|
}
|
|
|
|
})
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
mounted() {
|
|
|
|
const ranges = {}
|
|
|
|
if (this.value.hue)
|
|
|
|
ranges.hue = [this.value.hue_min, this.value.hue_max]
|
|
|
|
if (this.value.saturation)
|
|
|
|
ranges.sat = [this.value.saturation_min, this.value.saturation_max]
|
|
|
|
if (this.value.brightness)
|
|
|
|
ranges.bri = [this.value.brightness_min, this.value.brightness_max]
|
|
|
|
if (this.value.temperature)
|
|
|
|
ranges.ct = [this.value.temperature_min, this.value.temperature_max]
|
|
|
|
|
|
|
|
this.colorConverter = new ColorConverter(ranges)
|
|
|
|
},
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
@import "common";
|
|
|
|
|
|
|
|
.light-container {
|
2022-05-30 09:23:05 +02:00
|
|
|
.head {
|
|
|
|
.buttons {
|
|
|
|
button {
|
|
|
|
margin-right: 0.5em;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-01 15:35:20 +02:00
|
|
|
.body {
|
|
|
|
.row {
|
|
|
|
display: flex;
|
|
|
|
|
|
|
|
.icon {
|
|
|
|
width: 2em;
|
|
|
|
text-align: center;
|
|
|
|
}
|
|
|
|
|
|
|
|
.input {
|
|
|
|
width: calc(100% - 2em);
|
|
|
|
|
|
|
|
[type=color] {
|
|
|
|
width: 100%;
|
|
|
|
}
|
|
|
|
|
|
|
|
:deep(.slider) {
|
|
|
|
margin-top: 0.5em;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|