Resolves #165 Hide controls for unavailable lights

This commit is contained in:
Yegor Vialov 2018-11-04 23:13:25 +02:00
parent 9f7444eae0
commit 6d79487219
2 changed files with 31 additions and 27 deletions

View File

@ -98,7 +98,7 @@ class _LightControlsWidgetState extends State<LightControlsWidget> {
} }
Widget _buildBrightnessControl(LightEntity entity) { Widget _buildBrightnessControl(LightEntity entity) {
if ((entity.supportBrightness) && (_tmpBrightness != null)) { if ((entity.supportBrightness) && (_tmpBrightness != null) && (entity.state != "unavailable")) {
return Column( return Column(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[ children: <Widget>[

View File

@ -30,15 +30,22 @@ class _SwitchStateWidgetState extends State<SwitchStateWidget> {
final entityModel = EntityModel.of(context); final entityModel = EntityModel.of(context);
final entity = entityModel.entity; final entity = entityModel.entity;
Widget result; Widget result;
if ((entity.attributes["assumed_state"] == null) || (entity.attributes["assumed_state"] == false)) { if (entity.state == "unavailable") {
result = Switch( return SimpleEntityState();
} else if ((entity.attributes["assumed_state"] == null) || (entity.attributes["assumed_state"] == false)) {
return SizedBox(
height: 32.0,
child: Switch(
value: entity.assumedState == 'on', value: entity.assumedState == 'on',
onChanged: ((switchState) { onChanged: ((switchState) {
_setNewState(switchState, entity); _setNewState(switchState, entity);
}), }),
)
); );
} else { } else {
result = Row( return SizedBox(
height: 32.0,
child: Row(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[ children: <Widget>[
IconButton( IconButton(
@ -54,11 +61,8 @@ class _SwitchStateWidgetState extends State<SwitchStateWidget> {
iconSize: Entity.iconSize iconSize: Entity.iconSize
) )
], ],
),
); );
} }
return SizedBox(
height: 32.0,
child: result,
);
} }
} }