Skip to content

Commit de2c146

Browse files
committed
fix(color-changing-light-bulb): Prefix color_hex attribute with #-sign; Fixes #17
1 parent a149790 commit de2c146

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

device-types.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -139,11 +139,13 @@ const color_cmyk = (val) => {
139139
}
140140

141141
const color_hex = (val) => {
142-
if (!/^([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/.test(val)) {
142+
const match = `${val}`.match(/^#?([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/)
143+
144+
if (!match) {
143145
return false
144146
}
145147

146-
const hsb = convert.hex.hsv(val)
148+
const hsb = convert.hex.hsv(match[1])
147149

148150
return {
149151
key: 'color',
@@ -292,11 +294,13 @@ const colorChangingLightDecorator = ({
292294
localState.color.brightness * 100
293295
)
294296

295-
localState['color_hex'] = convert.hsv.hex(
296-
localState.color.hue,
297-
localState.color.saturation * 100,
298-
localState.color.brightness * 100
299-
)
297+
localState['color_hex'] =
298+
'#' +
299+
convert.hsv.hex(
300+
localState.color.hue,
301+
localState.color.saturation * 100,
302+
localState.color.brightness * 100
303+
)
300304

301305
localState['color_cmyk'] = convert.hsv.cmyk(
302306
localState.color.hue,

virtual-device.html

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,10 @@ <h4>Color Changing Light Bulb</h4>
312312
payload.color_hex
313313
<span class="property-type">string</span>
314314
</dt>
315-
<dd>Hexadecimal representation of <code>payload.color</code></dd>
315+
<dd>
316+
Hexadecimal representation of <code>payload.color</code>, e.g.
317+
&quot;#FF00AA&quot;
318+
</dd>
316319
<dt>
317320
payload.color_cmyk
318321
<span class="property-type">array(4)</span>

0 commit comments

Comments
 (0)