Merge branch 'master' into release/0.3.1
This commit is contained in:
@ -83,7 +83,18 @@ class Entity {
|
||||
} else if (temp1 is double) {
|
||||
return temp1;
|
||||
} else {
|
||||
return null;
|
||||
return double.tryParse("$temp1");
|
||||
}
|
||||
}
|
||||
|
||||
int _getIntAttributeValue(String attributeName) {
|
||||
var temp1 = attributes["$attributeName"];
|
||||
if (temp1 is int) {
|
||||
return temp1;
|
||||
} else if (temp1 is double) {
|
||||
return temp1.round();
|
||||
} else {
|
||||
return int.tryParse("$temp1");
|
||||
}
|
||||
}
|
||||
|
||||
@ -178,7 +189,7 @@ class SwitchEntity extends Entity {
|
||||
|
||||
@override
|
||||
Widget _buildStatePart(BuildContext context) {
|
||||
return SwitchControlWidget();
|
||||
return SwitchStateWidget();
|
||||
}
|
||||
}
|
||||
|
||||
@ -187,7 +198,7 @@ class ButtonEntity extends Entity {
|
||||
|
||||
@override
|
||||
Widget _buildStatePart(BuildContext context) {
|
||||
return ButtonControlWidget();
|
||||
return ButtonStateWidget();
|
||||
}
|
||||
}
|
||||
|
||||
@ -202,7 +213,7 @@ class TextEntity extends Entity {
|
||||
|
||||
@override
|
||||
Widget _buildStatePart(BuildContext context) {
|
||||
return TextControlWidget();
|
||||
return TextInputStateWidget();
|
||||
}
|
||||
}
|
||||
|
||||
@ -224,7 +235,7 @@ class SliderEntity extends Entity {
|
||||
//width: 200.0,
|
||||
child: Row(
|
||||
children: <Widget>[
|
||||
SliderControlWidget(
|
||||
SliderStateWidget(
|
||||
expanded: true,
|
||||
),
|
||||
SimpleEntityState(),
|
||||
@ -240,7 +251,7 @@ class SliderEntity extends Entity {
|
||||
|
||||
@override
|
||||
Widget _buildAdditionalControlsForPage(BuildContext context) {
|
||||
return SliderControlWidget(
|
||||
return SliderStateWidget(
|
||||
expanded: false,
|
||||
);
|
||||
}
|
||||
@ -468,3 +479,76 @@ class CoverEntity extends Entity {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
bool get supportBrightness => ((attributes["supported_features"] &
|
||||
LightEntity.SUPPORT_BRIGHTNESS) ==
|
||||
LightEntity.SUPPORT_BRIGHTNESS);
|
||||
bool get supportColorTemp => ((attributes["supported_features"] &
|
||||
LightEntity.SUPPORT_COLOR_TEMP) ==
|
||||
LightEntity.SUPPORT_COLOR_TEMP);
|
||||
bool get supportEffect => ((attributes["supported_features"] &
|
||||
LightEntity.SUPPORT_EFFECT) ==
|
||||
LightEntity.SUPPORT_EFFECT);
|
||||
bool get supportFlash => ((attributes["supported_features"] &
|
||||
LightEntity.SUPPORT_FLASH) ==
|
||||
LightEntity.SUPPORT_FLASH);
|
||||
bool get supportColor => ((attributes["supported_features"] &
|
||||
LightEntity.SUPPORT_COLOR) ==
|
||||
LightEntity.SUPPORT_COLOR);
|
||||
bool get supportTransition => ((attributes["supported_features"] &
|
||||
LightEntity.SUPPORT_TRANSITION) ==
|
||||
LightEntity.SUPPORT_TRANSITION);
|
||||
bool get supportWhiteValue => ((attributes["supported_features"] &
|
||||
LightEntity.SUPPORT_WHITE_VALUE) ==
|
||||
LightEntity.SUPPORT_WHITE_VALUE);
|
||||
|
||||
int get brightness => _getIntAttributeValue("brightness");
|
||||
int get colorTemp => _getIntAttributeValue("color_temp");
|
||||
double get maxMireds => _getDoubleAttributeValue("max_mireds");
|
||||
double get minMireds => _getDoubleAttributeValue("min_mireds");
|
||||
Color get color => _getColor();
|
||||
bool get isAdditionalControls => ((attributes["supported_features"] != null) && (attributes["supported_features"] != 0));
|
||||
List<String> get effectList => attributes["effect_list"] != null
|
||||
? (attributes["effect_list"] as List).cast<String>()
|
||||
: null;
|
||||
|
||||
LightEntity(Map rawData) : super(rawData);
|
||||
|
||||
Color _getColor() {
|
||||
List rgb = attributes["rgb_color"];
|
||||
try {
|
||||
if ((rgb != null) && (rgb.length > 0)) {
|
||||
return Color.fromARGB(255, rgb[0], rgb[1], rgb[2]);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
} catch (e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget _buildStatePart(BuildContext context) {
|
||||
return SwitchStateWidget();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget _buildAdditionalControlsForPage(BuildContext context) {
|
||||
if (!isAdditionalControls) {
|
||||
return Container(height: 0.0, width: 0.0);
|
||||
} else {
|
||||
return LightControlsWidget();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user