Resloves #133 Light support
This commit is contained in:
@ -518,9 +518,7 @@ class LightEntity extends Entity {
|
|||||||
double get minMireds => _getDoubleAttributeValue("min_mireds");
|
double get minMireds => _getDoubleAttributeValue("min_mireds");
|
||||||
Color get color => _getColor();
|
Color get color => _getColor();
|
||||||
bool get isAdditionalControls => ((attributes["supported_features"] != null) && (attributes["supported_features"] != 0));
|
bool get isAdditionalControls => ((attributes["supported_features"] != null) && (attributes["supported_features"] != 0));
|
||||||
List<String> get effectList => attributes["effect_list"] != null
|
List<String> get effectList => _getEffectList();
|
||||||
? (attributes["effect_list"] as List).cast<String>()
|
|
||||||
: null;
|
|
||||||
|
|
||||||
LightEntity(Map rawData) : super(rawData);
|
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
|
@override
|
||||||
Widget _buildStatePart(BuildContext context) {
|
Widget _buildStatePart(BuildContext context) {
|
||||||
return SwitchStateWidget();
|
return SwitchStateWidget();
|
||||||
|
@ -780,11 +780,15 @@ class _LightControlsWidgetState extends State<LightControlsWidget> {
|
|||||||
int _tmpColorTemp;
|
int _tmpColorTemp;
|
||||||
Color _tmpColor;
|
Color _tmpColor;
|
||||||
bool _changedHere = false;
|
bool _changedHere = false;
|
||||||
|
String _tmpEffect;
|
||||||
|
String _tmpFlash;
|
||||||
|
|
||||||
void _resetState(LightEntity entity) {
|
void _resetState(LightEntity entity) {
|
||||||
_tmpBrightness = entity.brightness;
|
_tmpBrightness = entity.brightness;
|
||||||
_tmpColorTemp = entity.colorTemp;
|
_tmpColorTemp = entity.colorTemp;
|
||||||
_tmpColor = entity.color;
|
_tmpColor = entity.color;
|
||||||
|
_tmpEffect = null;
|
||||||
|
_tmpFlash = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
void _setBrightness(LightEntity entity, double value) {
|
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
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final entityModel = EntityModel.of(context);
|
final entityModel = EntityModel.of(context);
|
||||||
@ -845,10 +873,7 @@ class _LightControlsWidgetState extends State<LightControlsWidget> {
|
|||||||
_buildBrightnessControl(entity),
|
_buildBrightnessControl(entity),
|
||||||
_buildColorTempControl(entity),
|
_buildColorTempControl(entity),
|
||||||
_buildColorControl(entity),
|
_buildColorControl(entity),
|
||||||
_buildEffectControl(entity),
|
_buildEffectControl(entity)
|
||||||
_buildFlashControl(entity),
|
|
||||||
_buildTransitionControl(entity),
|
|
||||||
_buildWhiteValueControl(entity)
|
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -990,31 +1015,12 @@ class _LightControlsWidgetState extends State<LightControlsWidget> {
|
|||||||
|
|
||||||
Widget _buildEffectControl(LightEntity entity) {
|
Widget _buildEffectControl(LightEntity entity) {
|
||||||
if (entity.supportEffect) {
|
if (entity.supportEffect) {
|
||||||
return Text("Effect is not supported yet =(");
|
return ModeSelectorWidget(
|
||||||
} else {
|
onChange: (effect) => _setEffect(entity, effect),
|
||||||
return Container(width: 0.0, height: 0.0);
|
caption: "Effect",
|
||||||
}
|
options: entity.effectList,
|
||||||
}
|
value: _tmpEffect
|
||||||
|
);
|
||||||
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 =(");
|
|
||||||
} else {
|
} else {
|
||||||
return Container(width: 0.0, height: 0.0);
|
return Container(width: 0.0, height: 0.0);
|
||||||
}
|
}
|
||||||
|
@ -711,13 +711,14 @@ class ModeSelectorWidget extends StatelessWidget {
|
|||||||
child: ButtonTheme(
|
child: ButtonTheme(
|
||||||
alignedDropdown: true,
|
alignedDropdown: true,
|
||||||
child: DropdownButton<String>(
|
child: DropdownButton<String>(
|
||||||
value: "$value",
|
value: value,
|
||||||
iconSize: 30.0,
|
iconSize: 30.0,
|
||||||
isExpanded: true,
|
isExpanded: true,
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
fontSize: valueFontSize ?? Entity.largeFontSize,
|
fontSize: valueFontSize ?? Entity.largeFontSize,
|
||||||
color: Colors.black,
|
color: Colors.black,
|
||||||
),
|
),
|
||||||
|
hint: Text("Select ${caption.toLowerCase()}"),
|
||||||
items: options.map((String value) {
|
items: options.map((String value) {
|
||||||
return new DropdownMenuItem<String>(
|
return new DropdownMenuItem<String>(
|
||||||
value: value,
|
value: value,
|
||||||
|
@ -31,7 +31,6 @@ class ViewBuilder{
|
|||||||
Map<String, List<String>> userGroupsList = entityCollection.getDefaultViewTopLevelEntities();
|
Map<String, List<String>> userGroupsList = entityCollection.getDefaultViewTopLevelEntities();
|
||||||
List<Entity> entitiesForView = [];
|
List<Entity> entitiesForView = [];
|
||||||
userGroupsList["userGroups"].forEach((groupId){
|
userGroupsList["userGroups"].forEach((groupId){
|
||||||
TheLogger.log("Debug","----User defined group: $groupId");
|
|
||||||
Entity en = entityCollection.get(groupId);
|
Entity en = entityCollection.get(groupId);
|
||||||
if (en.isGroup) {
|
if (en.isGroup) {
|
||||||
en.childEntities = entityCollection.getAll(en.childEntityIds);
|
en.childEntities = entityCollection.getAll(en.childEntityIds);
|
||||||
|
Reference in New Issue
Block a user