Resolves #186 Switch for group with same domain antities
This commit is contained in:
43
lib/entity_class/group_entity.class.dart
Normal file
43
lib/entity_class/group_entity.class.dart
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
part of '../main.dart';
|
||||||
|
|
||||||
|
class GroupEntity extends Entity {
|
||||||
|
GroupEntity(Map rawData) : super(rawData);
|
||||||
|
|
||||||
|
final List<String> _domainsForSwitchableGroup = ["switch", "light", "automation", "input_boolean"];
|
||||||
|
String mutualDomain;
|
||||||
|
bool switchable = false;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget _buildStatePart(BuildContext context) {
|
||||||
|
if (switchable) {
|
||||||
|
return SwitchStateWidget(
|
||||||
|
domainForService: "homeassistant",
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
return super._buildStatePart(context);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void update(Map rawData) {
|
||||||
|
super.update(rawData);
|
||||||
|
if (_isOneDomain()) {
|
||||||
|
mutualDomain = attributes['entity_id'][0].split(".")[0];
|
||||||
|
switchable = _domainsForSwitchableGroup.contains(mutualDomain);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool _isOneDomain() {
|
||||||
|
bool result = false;
|
||||||
|
if (attributes['entity_id'] != null && attributes['entity_id'] is List && attributes['entity_id'].isNotEmpty) {
|
||||||
|
String firstChildDomain = attributes['entity_id'][0].split(".")[0];
|
||||||
|
result = true;
|
||||||
|
attributes['entity_id'].forEach((childEntityId){
|
||||||
|
if (childEntityId.split(".")[0] != firstChildDomain) {
|
||||||
|
result = false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
@ -55,6 +55,9 @@ class EntityCollection {
|
|||||||
case "light": {
|
case "light": {
|
||||||
return LightEntity(rawEntityData);
|
return LightEntity(rawEntityData);
|
||||||
}
|
}
|
||||||
|
case "group": {
|
||||||
|
return GroupEntity(rawEntityData);
|
||||||
|
}
|
||||||
case "script":
|
case "script":
|
||||||
case "scene": {
|
case "scene": {
|
||||||
return ButtonEntity(rawEntityData);
|
return ButtonEntity(rawEntityData);
|
||||||
|
@ -1,6 +1,11 @@
|
|||||||
part of '../../main.dart';
|
part of '../../main.dart';
|
||||||
|
|
||||||
class SwitchStateWidget extends StatefulWidget {
|
class SwitchStateWidget extends StatefulWidget {
|
||||||
|
|
||||||
|
final String domainForService;
|
||||||
|
|
||||||
|
const SwitchStateWidget({Key key, this.domainForService}) : super(key: key);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
_SwitchStateWidgetState createState() => _SwitchStateWidgetState();
|
_SwitchStateWidgetState createState() => _SwitchStateWidgetState();
|
||||||
}
|
}
|
||||||
@ -27,8 +32,14 @@ class _SwitchStateWidgetState extends State<SwitchStateWidget> {
|
|||||||
//TheLogger.debug("Timer@!!");
|
//TheLogger.debug("Timer@!!");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
String domain;
|
||||||
|
if (widget.domainForService != null) {
|
||||||
|
domain = widget.domainForService;
|
||||||
|
} else {
|
||||||
|
domain = entity.domain;
|
||||||
|
}
|
||||||
eventBus.fire(new ServiceCallEvent(
|
eventBus.fire(new ServiceCallEvent(
|
||||||
entity.domain, (newValue as bool) ? "turn_on" : "turn_off", entity.entityId, null));
|
domain, (newValue as bool) ? "turn_on" : "turn_off", entity.entityId, null));
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -30,6 +30,7 @@ part 'entity_class/other_entity.class.dart';
|
|||||||
part 'entity_class/slider_entity.dart';
|
part 'entity_class/slider_entity.dart';
|
||||||
part 'entity_class/media_player_entity.class.dart';
|
part 'entity_class/media_player_entity.class.dart';
|
||||||
part 'entity_class/lock_entity.class.dart';
|
part 'entity_class/lock_entity.class.dart';
|
||||||
|
part 'entity_class/group_entity.class.dart';
|
||||||
part 'entity_widgets/common/badge.dart';
|
part 'entity_widgets/common/badge.dart';
|
||||||
part 'entity_widgets/model_widgets.dart';
|
part 'entity_widgets/model_widgets.dart';
|
||||||
part 'entity_widgets/default_entity_container.dart';
|
part 'entity_widgets/default_entity_container.dart';
|
||||||
|
Reference in New Issue
Block a user