Resolves #501 Entities card header toggle

This commit is contained in:
Yegor Vialov 2020-02-19 10:17:08 +00:00
parent 710de9f2b8
commit 14c272af92
6 changed files with 38 additions and 5 deletions

View File

@ -10,6 +10,7 @@ class HACard {
bool showName;
bool showState;
bool showEmpty;
bool showHeaderToggle;
int columnsCount;
List stateFilter;
List states;
@ -26,6 +27,7 @@ class HACard {
this.linkedEntityWrapper,
this.columnsCount: 4,
this.showName: true,
this.showHeaderToggle: true,
this.showState: true,
this.stateFilter: const [],
this.showEmpty: true,

View File

@ -132,7 +132,33 @@ class CardWidget extends StatelessWidget {
return Container(height: 0.0, width: 0.0,);
}
List<Widget> body = [];
body.add(CardHeader(name: card.name));
Widget headerSwitch;
if (card.showHeaderToggle) {
bool headerToggleVal = entitiesToShow.any((EntityWrapper en){ return en.entity.state == EntityState.on; });
List<String> entitiesToToggle = entitiesToShow.where((EntityWrapper enw) {
return <String>["switch", "light", "automation", "input_boolean"].contains(enw.entity.domain);
}).map((EntityWrapper en) {
return en.entity.entityId;
}).toList();
headerSwitch = Switch(
value: headerToggleVal,
onChanged: (val) {
if (entitiesToToggle.isNotEmpty) {
ConnectionManager().callService(
domain: "homeassistant",
service: val ? "turn_on" : "turn_off",
entityId: entitiesToToggle
);
}
},
);
}
body.add(
CardHeader(
name: card.name,
trailing: headerSwitch
)
);
entitiesToShow.forEach((EntityWrapper entity) {
body.add(
Padding(
@ -329,7 +355,11 @@ class CardWidget extends StatelessWidget {
Widget _buildUnsupportedCard(BuildContext context) {
List<Widget> body = [];
body.add(CardHeader(name: card.name ?? ""));
body.add(
CardHeader(
name: card.name ?? ""
)
);
List<Widget> result = [];
if (card.linkedEntityWrapper != null) {
result.addAll(<Widget>[

View File

@ -221,6 +221,7 @@ class HomeAssistant {
type: rawCardInfo['type'] ?? CardType.ENTITIES,
columnsCount: rawCardInfo['columns'] ?? 4,
showName: (rawCardInfo['show_name'] ?? rawCard['show_name']) ?? true,
showHeaderToggle: (rawCardInfo['show_header_toggle'] ?? rawCard['show_header_toggle']) ?? true,
showState: (rawCardInfo['show_state'] ?? rawCard['show_state']) ?? true,
showEmpty: (rawCardInfo['show_empty'] ?? rawCard['show_empty']) ?? true,
stateFilter: (rawCard['state_filter'] ?? rawCardInfo['state_filter']) ?? [],

View File

@ -352,7 +352,7 @@ class ConnectionManager {
_currentMessageId += 1;
}
Future callService({@required String domain, @required String service, String entityId, Map data}) {
Future callService({@required String domain, @required String service, entityId, Map data}) {
eventBus.fire(NotifyServiceCallEvent(domain, service, entityId));
Logger.d("Service call: $domain.$service, $entityId, $data");
Completer completer = Completer();

View File

@ -278,7 +278,7 @@ class _MainPageState extends State<MainPage> with WidgetsBindingObserver, Ticker
);
}
void _notifyServiceCalled(String domain, String service, String entityId) {
void _notifyServiceCalled(String domain, String service, entityId) {
_showInfoBottomBar(
message: "Calling $domain.$service",
duration: Duration(seconds: 4)

View File

@ -36,7 +36,7 @@ class StartAuthEvent {
class NotifyServiceCallEvent {
String domain;
String service;
String entityId;
var entityId;
NotifyServiceCallEvent(this.domain, this.service, this.entityId);
}