Resloves #133 Light support

This commit is contained in:
Yegor Vialov
2018-10-18 23:47:55 +03:00
parent c71ee568b0
commit ba09c36bd2
4 changed files with 47 additions and 34 deletions

View File

@ -518,9 +518,7 @@ class LightEntity extends Entity {
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;
List<String> get effectList => _getEffectList();
LightEntity(Map rawData) : super(rawData);
@ -537,6 +535,15 @@ class LightEntity extends Entity {
}
}
List<String> _getEffectList() {
if (attributes["effect_list"] != null) {
List<String> result = (attributes["effect_list"] as List).cast<String>();
return result;
} else {
return null;
}
}
@override
Widget _buildStatePart(BuildContext context) {
return SwitchStateWidget();

View File

@ -780,11 +780,15 @@ class _LightControlsWidgetState extends State<LightControlsWidget> {
int _tmpColorTemp;
Color _tmpColor;
bool _changedHere = false;
String _tmpEffect;
String _tmpFlash;
void _resetState(LightEntity entity) {
_tmpBrightness = entity.brightness;
_tmpColorTemp = entity.colorTemp;
_tmpColor = entity.color;
_tmpEffect = null;
_tmpFlash = null;
}
void _setBrightness(LightEntity entity, double value) {
@ -830,6 +834,30 @@ class _LightControlsWidgetState extends State<LightControlsWidget> {
});
}
void _setEffect(LightEntity entity, String value) {
setState(() {
_tmpEffect = value;
_changedHere = true;
if (_tmpEffect != null) {
eventBus.fire(new ServiceCallEvent(
entity.domain, "turn_on", entity.entityId,
{"effect": "$value"}));
}
});
}
void _setFlash(LightEntity entity, String value) {
setState(() {
_tmpFlash = value;
_changedHere = true;
if (_tmpFlash != null) {
eventBus.fire(new ServiceCallEvent(
entity.domain, "turn_on", entity.entityId,
{"flash": "$value"}));
}
});
}
@override
Widget build(BuildContext context) {
final entityModel = EntityModel.of(context);
@ -845,10 +873,7 @@ class _LightControlsWidgetState extends State<LightControlsWidget> {
_buildBrightnessControl(entity),
_buildColorTempControl(entity),
_buildColorControl(entity),
_buildEffectControl(entity),
_buildFlashControl(entity),
_buildTransitionControl(entity),
_buildWhiteValueControl(entity)
_buildEffectControl(entity)
],
);
}
@ -990,31 +1015,12 @@ class _LightControlsWidgetState extends State<LightControlsWidget> {
Widget _buildEffectControl(LightEntity entity) {
if (entity.supportEffect) {
return Text("Effect is not supported yet =(");
} else {
return Container(width: 0.0, height: 0.0);
}
}
Widget _buildFlashControl(LightEntity entity) {
if (entity.supportFlash) {
return Text("Flash is not supported yet =(");
} else {
return Container(width: 0.0, height: 0.0);
}
}
Widget _buildTransitionControl(LightEntity entity) {
if (entity.supportTransition) {
return Text("Transition is not supported yet =(");
} else {
return Container(width: 0.0, height: 0.0);
}
}
Widget _buildWhiteValueControl(LightEntity entity) {
if (entity.supportWhiteValue) {
return Text("White value is not supported yet =(");
return ModeSelectorWidget(
onChange: (effect) => _setEffect(entity, effect),
caption: "Effect",
options: entity.effectList,
value: _tmpEffect
);
} else {
return Container(width: 0.0, height: 0.0);
}

View File

@ -711,13 +711,14 @@ class ModeSelectorWidget extends StatelessWidget {
child: ButtonTheme(
alignedDropdown: true,
child: DropdownButton<String>(
value: "$value",
value: value,
iconSize: 30.0,
isExpanded: true,
style: TextStyle(
fontSize: valueFontSize ?? Entity.largeFontSize,
color: Colors.black,
),
hint: Text("Select ${caption.toLowerCase()}"),
items: options.map((String value) {
return new DropdownMenuItem<String>(
value: value,

View File

@ -31,7 +31,6 @@ class ViewBuilder{
Map<String, List<String>> userGroupsList = entityCollection.getDefaultViewTopLevelEntities();
List<Entity> entitiesForView = [];
userGroupsList["userGroups"].forEach((groupId){
TheLogger.log("Debug","----User defined group: $groupId");
Entity en = entityCollection.get(groupId);
if (en.isGroup) {
en.childEntities = entityCollection.getAll(en.childEntityIds);