2018-10-27 14:27:41 +03:00
|
|
|
part of '../main.dart';
|
|
|
|
|
|
|
|
class LightEntity extends Entity {
|
|
|
|
|
|
|
|
static const SUPPORT_BRIGHTNESS = 1;
|
|
|
|
static const SUPPORT_COLOR_TEMP = 2;
|
|
|
|
static const SUPPORT_EFFECT = 4;
|
|
|
|
static const SUPPORT_FLASH = 8;
|
|
|
|
static const SUPPORT_COLOR = 16;
|
|
|
|
static const SUPPORT_TRANSITION = 32;
|
|
|
|
static const SUPPORT_WHITE_VALUE = 128;
|
|
|
|
|
2019-02-17 13:52:24 +02:00
|
|
|
bool get supportBrightness => ((supportedFeatures &
|
2018-10-27 14:27:41 +03:00
|
|
|
LightEntity.SUPPORT_BRIGHTNESS) ==
|
|
|
|
LightEntity.SUPPORT_BRIGHTNESS);
|
2019-02-17 13:52:24 +02:00
|
|
|
bool get supportColorTemp => ((supportedFeatures &
|
2018-10-27 14:27:41 +03:00
|
|
|
LightEntity.SUPPORT_COLOR_TEMP) ==
|
|
|
|
LightEntity.SUPPORT_COLOR_TEMP);
|
2019-02-17 13:52:24 +02:00
|
|
|
bool get supportEffect => ((supportedFeatures &
|
2018-10-27 14:27:41 +03:00
|
|
|
LightEntity.SUPPORT_EFFECT) ==
|
|
|
|
LightEntity.SUPPORT_EFFECT);
|
2019-02-17 13:52:24 +02:00
|
|
|
bool get supportFlash => ((supportedFeatures &
|
2018-10-27 14:27:41 +03:00
|
|
|
LightEntity.SUPPORT_FLASH) ==
|
|
|
|
LightEntity.SUPPORT_FLASH);
|
2019-02-17 13:52:24 +02:00
|
|
|
bool get supportColor => ((supportedFeatures &
|
2018-10-27 14:27:41 +03:00
|
|
|
LightEntity.SUPPORT_COLOR) ==
|
|
|
|
LightEntity.SUPPORT_COLOR);
|
2019-02-17 13:52:24 +02:00
|
|
|
bool get supportTransition => ((supportedFeatures &
|
2018-10-27 14:27:41 +03:00
|
|
|
LightEntity.SUPPORT_TRANSITION) ==
|
|
|
|
LightEntity.SUPPORT_TRANSITION);
|
2019-02-17 13:52:24 +02:00
|
|
|
bool get supportWhiteValue => ((supportedFeatures &
|
2018-10-27 14:27:41 +03:00
|
|
|
LightEntity.SUPPORT_WHITE_VALUE) ==
|
|
|
|
LightEntity.SUPPORT_WHITE_VALUE);
|
|
|
|
|
|
|
|
int get brightness => _getIntAttributeValue("brightness");
|
2019-01-24 12:26:38 +02:00
|
|
|
String get effect => attributes["effect"];
|
2018-10-27 14:27:41 +03:00
|
|
|
int get colorTemp => _getIntAttributeValue("color_temp");
|
|
|
|
double get maxMireds => _getDoubleAttributeValue("max_mireds");
|
|
|
|
double get minMireds => _getDoubleAttributeValue("min_mireds");
|
2019-02-10 17:15:52 +02:00
|
|
|
HSVColor get color => _getColor();
|
2019-02-17 13:52:24 +02:00
|
|
|
bool get isAdditionalControls => ((supportedFeatures != null) && (supportedFeatures != 0));
|
2018-11-23 14:11:34 +02:00
|
|
|
List<String> get effectList => getStringListAttributeValue("effect_list");
|
2018-10-27 14:27:41 +03:00
|
|
|
|
|
|
|
LightEntity(Map rawData) : super(rawData);
|
|
|
|
|
2019-02-10 17:15:52 +02:00
|
|
|
HSVColor _getColor() {
|
|
|
|
List hs = attributes["hs_color"];
|
2018-10-27 14:27:41 +03:00
|
|
|
try {
|
2019-02-10 17:15:52 +02:00
|
|
|
if ((hs != null) && (hs.length > 0)) {
|
|
|
|
double sat = hs[1]/100;
|
|
|
|
String ssat = sat.toStringAsFixed(2);
|
|
|
|
return HSVColor.fromAHSV(1.0, hs[0], double.parse(ssat), 1.0);
|
2018-10-27 14:27:41 +03:00
|
|
|
} else {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
} catch (e) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget _buildStatePart(BuildContext context) {
|
|
|
|
return SwitchStateWidget();
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget _buildAdditionalControlsForPage(BuildContext context) {
|
2019-02-10 19:06:07 +02:00
|
|
|
if (!isAdditionalControls || state == EntityState.unavailable) {
|
2018-10-27 14:27:41 +03:00
|
|
|
return Container(height: 0.0, width: 0.0);
|
|
|
|
} else {
|
|
|
|
return LightControlsWidget();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|