From 6d79487219dc2cc9a6e5b4f4966bc1ca77242b1c Mon Sep 17 00:00:00 2001 From: Yegor Vialov Date: Sun, 4 Nov 2018 23:13:25 +0200 Subject: [PATCH] Resolves #165 Hide controls for unavailable lights --- .../controls/light_controls.dart | 2 +- lib/entity_widgets/state/switch_state.dart | 56 ++++++++++--------- 2 files changed, 31 insertions(+), 27 deletions(-) diff --git a/lib/entity_widgets/controls/light_controls.dart b/lib/entity_widgets/controls/light_controls.dart index 6ce600a..aedfaa1 100644 --- a/lib/entity_widgets/controls/light_controls.dart +++ b/lib/entity_widgets/controls/light_controls.dart @@ -98,7 +98,7 @@ class _LightControlsWidgetState extends State { } Widget _buildBrightnessControl(LightEntity entity) { - if ((entity.supportBrightness) && (_tmpBrightness != null)) { + if ((entity.supportBrightness) && (_tmpBrightness != null) && (entity.state != "unavailable")) { return Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ diff --git a/lib/entity_widgets/state/switch_state.dart b/lib/entity_widgets/state/switch_state.dart index 641e44a..702b989 100644 --- a/lib/entity_widgets/state/switch_state.dart +++ b/lib/entity_widgets/state/switch_state.dart @@ -30,35 +30,39 @@ class _SwitchStateWidgetState extends State { final entityModel = EntityModel.of(context); final entity = entityModel.entity; Widget result; - if ((entity.attributes["assumed_state"] == null) || (entity.attributes["assumed_state"] == false)) { - result = Switch( - value: entity.assumedState == 'on', - onChanged: ((switchState) { - _setNewState(switchState, entity); - }), + if (entity.state == "unavailable") { + 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', + onChanged: ((switchState) { + _setNewState(switchState, entity); + }), + ) ); } else { - result = Row( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - IconButton( - onPressed: () => _setNewState(false, entity), - icon: Icon(MaterialDesignIcons.createIconDataFromIconName("mdi:flash-off")), - color: entity.assumedState == 'on' ? Colors.black : Colors.blue, - iconSize: Entity.iconSize, - ), - IconButton( - onPressed: () => _setNewState(true, entity), - icon: Icon(MaterialDesignIcons.createIconDataFromIconName("mdi:flash")), - color: entity.assumedState == 'on' ? Colors.blue : Colors.black, - iconSize: Entity.iconSize - ) - ], + return SizedBox( + height: 32.0, + child: Row( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + IconButton( + onPressed: () => _setNewState(false, entity), + icon: Icon(MaterialDesignIcons.createIconDataFromIconName("mdi:flash-off")), + color: entity.assumedState == 'on' ? Colors.black : Colors.blue, + iconSize: Entity.iconSize, + ), + IconButton( + onPressed: () => _setNewState(true, entity), + icon: Icon(MaterialDesignIcons.createIconDataFromIconName("mdi:flash")), + color: entity.assumedState == 'on' ? Colors.blue : Colors.black, + iconSize: Entity.iconSize + ) + ], + ), ); } - return SizedBox( - height: 32.0, - child: result, - ); } } \ No newline at end of file