Get color from rgb_color if there is no hsv_color attribute

This commit is contained in:
estevez-dev
2019-02-22 14:20:01 +02:00
parent eb7d17d147
commit 0615073ec4
3 changed files with 6 additions and 3 deletions

View File

@ -45,11 +45,14 @@ class LightEntity extends Entity {
HSVColor _getColor() {
List hs = attributes["hs_color"];
List rgb = attributes["rgb_color"];
try {
if ((hs != null) && (hs.length > 0)) {
if (hs != null && hs.isNotEmpty) {
double sat = hs[1]/100;
String ssat = sat.toStringAsFixed(2);
return HSVColor.fromAHSV(1.0, hs[0], double.parse(ssat), 1.0);
} else if (rgb != null && rgb.isNotEmpty) {
return HSVColor.fromColor(Color.fromARGB(255, rgb[0], rgb[1], rgb[2]));
} else {
return null;
}