(Tentative) support for zwave light colors

This commit is contained in:
Fabio Manganiello 2023-01-02 12:50:01 +01:00
parent 4f75cbc8b4
commit b0671354ea
Signed by untrusted user: blacklight
GPG key ID: D90FBA7F76362774
2 changed files with 44 additions and 7 deletions

View file

@ -88,12 +88,16 @@ export default {
if (this.value.meta?.icon?.color) if (this.value.meta?.icon?.color)
return this.value.meta.icon.color return this.value.meta.icon.color
if (this.value.red && this.value.green && this.value.blue)
return ['red', 'green', 'blue'].map((c) => this.value[c])
if (!this.colorConverter)
return
if ( if (
!this.colorConverter || (
this.value.hue == null && this.value.hue == null &&
(this.value.x == null || this.value.y == null) (this.value.x == null || this.value.y == null)
) )
)
return return
if (this.value.x && this.value.y) if (this.value.x && this.value.y)
@ -150,11 +154,18 @@ export default {
const rgb = this.colorConverter.hexToRgb(attrs.color) const rgb = this.colorConverter.hexToRgb(attrs.color)
if (this.value.x != null && this.value.y != null) { if (this.value.x != null && this.value.y != null) {
attrs.xy = this.colorConverter.rgbToXY(...rgb) attrs.xy = this.colorConverter.rgbToXY(...rgb)
delete attrs.color
} else if (this.value.hue != null) { } else if (this.value.hue != null) {
[attrs.hue, attrs.saturation, attrs.brightness] = this.colorConverter.rgbToHsl(...rgb) [attrs.hue, attrs.saturation, attrs.brightness] = this.colorConverter.rgbToHsl(...rgb)
delete attrs.color } else if (
this.value.red != null && this.value.green != null && this.value.blue != null
) {
[attrs.red, attrs.green, attrs.blue] = [rgb.red, rgb.green, rgb.blue]
} else {
console.warn('Unrecognized color format')
console.warn(attrs.color)
} }
delete attrs.color
} }
this.execute({ this.execute({

View file

@ -30,6 +30,7 @@ from platypush.entities.electricity import (
) )
from platypush.entities.humidity import HumiditySensor from platypush.entities.humidity import HumiditySensor
from platypush.entities.illuminance import IlluminanceSensor from platypush.entities.illuminance import IlluminanceSensor
from platypush.entities.lights import Light
from platypush.entities.sensors import BinarySensor, EnumSensor, NumericSensor from platypush.entities.sensors import BinarySensor, EnumSensor, NumericSensor
from platypush.entities.switches import EnumSwitch, Switch from platypush.entities.switches import EnumSwitch, Switch
from platypush.entities.temperature import TemperatureSensor from platypush.entities.temperature import TemperatureSensor
@ -588,6 +589,16 @@ class ZwaveMqttPlugin(MqttPlugin, ZwaveBasePlugin):
def _is_enum_switch(cls, value: Mapping): def _is_enum_switch(cls, value: Mapping):
return value.get('type') == 'List' and not value.get('is_read_only') return value.get('type') == 'List' and not value.get('is_read_only')
@classmethod
def _is_light(cls, value: Mapping):
return (
cls._matches_classes(value, 'color')
and not {'red', 'green', 'blue'}.difference(
set(value.get('value', {}).keys())
)
and not value.get('is_read_only')
)
@classmethod @classmethod
def _get_sensor_args( def _get_sensor_args(
cls, value: Mapping cls, value: Mapping
@ -689,7 +700,13 @@ class ZwaveMqttPlugin(MqttPlugin, ZwaveBasePlugin):
entity_args = self._to_entity_args(value) entity_args = self._to_entity_args(value)
sensor_type, sensor_args = self._get_sensor_args(value) sensor_type, sensor_args = self._get_sensor_args(value)
if self._is_dimmer(value): if self._is_light(value):
entity_type = Light
color = value['value']
entity_args['red'] = color['red']
entity_args['green'] = color['green']
entity_args['blue'] = color['blue']
elif self._is_dimmer(value):
entity_type = Dimmer entity_type = Dimmer
entity_args['value'] = value['data'] entity_args['value'] = value['data']
entity_args['min'] = value['min'] entity_args['min'] = value['min']
@ -1486,6 +1503,15 @@ class ZwaveMqttPlugin(MqttPlugin, ZwaveBasePlugin):
**kwargs, **kwargs,
) )
@action
def set_lights(self, lights, **kwargs):
"""
Set the state for one or more Z-Wave lights.
"""
lights = [lights] if isinstance(lights, str) else lights
for light in lights:
self.set_value(light, kwargs)
@action @action
def set_value_label(self, **_): def set_value_label(self, **_):
""" """