Resolves #416 Vacuum support
This commit is contained in:
parent
abd23e27ea
commit
3387ab2850
@ -67,11 +67,29 @@ class VacuumEntity extends Entity {
|
||||
String get status => getAttribute("status");
|
||||
int get batteryLevel => _getIntAttributeValue("battery_level");
|
||||
String get batteryIcon => getAttribute("battery_icon");
|
||||
double get cleanedArea => _getDoubleAttributeValue("cleaned_area");
|
||||
|
||||
/*@override
|
||||
@override
|
||||
Widget _buildStatePart(BuildContext context) {
|
||||
return SwitchStateWidget();
|
||||
}*/
|
||||
if (supportTurnOn || supportTurnOff) {
|
||||
return SwitchStateWidget(
|
||||
domainForService: "vacuum",
|
||||
);
|
||||
} else {
|
||||
return SimpleEntityState();
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget _buildStatePartForPage(BuildContext context) {
|
||||
return EntityModel(
|
||||
entityWrapper: EntityWrapper(
|
||||
entity: this
|
||||
),
|
||||
child: VacuumStateButton(),
|
||||
handleTap: false,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget _buildAdditionalControlsForPage(BuildContext context) {
|
||||
|
@ -11,7 +11,9 @@ class VacuumControls extends StatelessWidget {
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: <Widget>[
|
||||
_buildStatusAndBattery(entity),
|
||||
_buildCommands(entity)
|
||||
_buildCommands(entity),
|
||||
_buildFanSpeed(entity),
|
||||
_buildAdditionalInfo(entity)
|
||||
],
|
||||
),
|
||||
);
|
||||
@ -56,7 +58,7 @@ class VacuumControls extends StatelessWidget {
|
||||
}
|
||||
|
||||
return Padding(
|
||||
padding: EdgeInsets.only(bottom: Sizes.rowPadding),
|
||||
padding: EdgeInsets.only(bottom: Sizes.doubleRowPadding),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
mainAxisSize: MainAxisSize.max,
|
||||
@ -69,36 +71,162 @@ class VacuumControls extends StatelessWidget {
|
||||
Widget _buildCommands(VacuumEntity entity) {
|
||||
List<Widget> commandButtons = [];
|
||||
double iconSize = 32;
|
||||
if (entity.supportPause) {
|
||||
if (entity.supportStart) {
|
||||
commandButtons.add(
|
||||
IconButton(
|
||||
icon: Icon(MaterialDesignIcons.getIconDataFromIconName("mdi:play")),
|
||||
iconSize: iconSize,
|
||||
onPressed: () => ConnectionManager().callService(
|
||||
domain: "vacuum",
|
||||
entityId: entity.entityId,
|
||||
service: "start"
|
||||
),
|
||||
)
|
||||
);
|
||||
}
|
||||
if (entity.supportPause && !entity.supportStart) {
|
||||
commandButtons.add(
|
||||
IconButton(
|
||||
icon: Icon(MaterialDesignIcons.getIconDataFromIconName("mdi:play-pause")),
|
||||
iconSize: iconSize,
|
||||
onPressed: () => Logger.d("[VACUUM] pause"),
|
||||
onPressed: () => ConnectionManager().callService(
|
||||
domain: "vacuum",
|
||||
entityId: entity.entityId,
|
||||
service: "start_pause"
|
||||
),
|
||||
)
|
||||
);
|
||||
} else if (entity.supportPause) {
|
||||
commandButtons.add(
|
||||
IconButton(
|
||||
icon: Icon(MaterialDesignIcons.getIconDataFromIconName("mdi:pause")),
|
||||
iconSize: iconSize,
|
||||
onPressed: () => ConnectionManager().callService(
|
||||
domain: "vacuum",
|
||||
entityId: entity.entityId,
|
||||
service: "pause"
|
||||
),
|
||||
)
|
||||
);
|
||||
}
|
||||
if (entity.supportStop) {
|
||||
commandButtons.add(
|
||||
IconButton(
|
||||
icon: Icon(MaterialDesignIcons.getIconDataFromIconName("mdi:stop")),
|
||||
iconSize: iconSize,
|
||||
onPressed: () => Logger.d("[VACUUM] stop"),
|
||||
onPressed: () => ConnectionManager().callService(
|
||||
domain: "vacuum",
|
||||
entityId: entity.entityId,
|
||||
service: "stop"
|
||||
),
|
||||
)
|
||||
);
|
||||
}
|
||||
if (entity.supportCleanSpot) {
|
||||
commandButtons.add(
|
||||
IconButton(
|
||||
icon: Icon(MaterialDesignIcons.getIconDataFromIconName("mdi:broom")),
|
||||
iconSize: iconSize,
|
||||
onPressed: () => ConnectionManager().callService(
|
||||
domain: "vacuum",
|
||||
entityId: entity.entityId,
|
||||
service: "clean_spot"
|
||||
),
|
||||
)
|
||||
);
|
||||
}
|
||||
if (entity.supportLocate) {
|
||||
commandButtons.add(
|
||||
IconButton(
|
||||
icon: Icon(MaterialDesignIcons.getIconDataFromIconName("mdi:map-marker")),
|
||||
iconSize: iconSize,
|
||||
onPressed: () => ConnectionManager().callService(
|
||||
domain: "vacuum",
|
||||
entityId: entity.entityId,
|
||||
service: "locate"
|
||||
),
|
||||
)
|
||||
);
|
||||
}
|
||||
if (entity.supportReturnHome) {
|
||||
commandButtons.add(
|
||||
IconButton(
|
||||
icon: Icon(MaterialDesignIcons.getIconDataFromIconName("mdi:home-map-marker")),
|
||||
iconSize: iconSize,
|
||||
onPressed: () => ConnectionManager().callService(
|
||||
domain: "vacuum",
|
||||
entityId: entity.entityId,
|
||||
service: "return_to_base"
|
||||
),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
return Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: <Widget>[
|
||||
Text("Vacuum cleaner commands:", style: TextStyle(fontSize: Sizes.stateFontSize)),
|
||||
Container(height: Sizes.rowPadding,),
|
||||
Row(
|
||||
mainAxisSize: MainAxisSize.max,
|
||||
children: commandButtons,
|
||||
)
|
||||
],
|
||||
if (commandButtons.isEmpty) {
|
||||
return Container(width: 0, height: 0,);
|
||||
}
|
||||
|
||||
return Padding(
|
||||
padding: EdgeInsets.only(bottom: Sizes.doubleRowPadding),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: <Widget>[
|
||||
Text("Vacuum cleaner commands:", style: TextStyle(fontSize: Sizes.stateFontSize)),
|
||||
Container(height: Sizes.rowPadding,),
|
||||
Row(
|
||||
mainAxisSize: MainAxisSize.max,
|
||||
children: commandButtons.map((button) => Expanded(
|
||||
child: button,
|
||||
)).toList(),
|
||||
)
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildFanSpeed(VacuumEntity entity) {
|
||||
if (entity.supportFanSpeed) {
|
||||
return Padding(
|
||||
padding: EdgeInsets.only(bottom: Sizes.doubleRowPadding),
|
||||
child: ModeSelectorWidget(
|
||||
caption: "Fan speed",
|
||||
options: entity.fanSpeedList,
|
||||
value: entity.fanSpeed,
|
||||
onChange: (val) => ConnectionManager().callService(
|
||||
domain: "vacuum",
|
||||
entityId: entity.entityId,
|
||||
service: "set_fan_speed",
|
||||
additionalServiceData: {"fan_speed": val}
|
||||
)
|
||||
),
|
||||
);
|
||||
} else {
|
||||
return Container(width: 0, height: 0,);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Widget _buildAdditionalInfo(VacuumEntity entity) {
|
||||
List<Widget> rows = [];
|
||||
if (entity.cleanedArea != null) {
|
||||
rows.add(
|
||||
Text("Cleaned area: ${entity.cleanedArea}")
|
||||
);
|
||||
}
|
||||
|
||||
if (rows.isEmpty) {
|
||||
return Container(width: 0, height: 0,);
|
||||
}
|
||||
|
||||
return Padding(
|
||||
padding: EdgeInsets.only(bottom: Sizes.doubleRowPadding),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: rows,
|
||||
),
|
||||
);
|
||||
|
||||
}
|
||||
}
|
||||
|
40
lib/entities/vacuum/widgets/vacuum_state_button.dart
Normal file
40
lib/entities/vacuum/widgets/vacuum_state_button.dart
Normal file
@ -0,0 +1,40 @@
|
||||
part of '../../../main.dart';
|
||||
|
||||
class VacuumStateButton extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
Widget result;
|
||||
VacuumEntity entity = EntityModel.of(context).entityWrapper.entity;
|
||||
if (entity.supportTurnOn && entity.supportTurnOff) {
|
||||
result = FlatServiceButton(
|
||||
serviceDomain: "vacuum",
|
||||
serviceName: entity.state == EntityState.on ? "turn_off" : "turn_on",
|
||||
entityId: entity.entityId,
|
||||
text: entity.state == EntityState.on ? "TURN OFF" : "TURN ON"
|
||||
);
|
||||
} else if (entity.supportStart && (entity.state == EntityState.docked || entity.state == EntityState.idle)) {
|
||||
result = FlatServiceButton(
|
||||
serviceDomain: "vacuum",
|
||||
serviceName: "start",
|
||||
entityId: entity.entityId,
|
||||
text: "START CLEANING"
|
||||
);
|
||||
} else if (entity.supportReturnHome && entity.state == EntityState.cleaning) {
|
||||
result = FlatServiceButton(
|
||||
serviceDomain: "vacuum",
|
||||
serviceName: "return_to_base",
|
||||
entityId: entity.entityId,
|
||||
text: "RETURN TO DOCK"
|
||||
);
|
||||
} else {
|
||||
result = Text(entity.state.toUpperCase(), style: TextStyle(
|
||||
fontSize: 16,
|
||||
color: Colors.grey
|
||||
));
|
||||
}
|
||||
return Padding(
|
||||
padding: EdgeInsets.only(right: 15),
|
||||
child: result,
|
||||
);
|
||||
}
|
||||
}
|
@ -95,6 +95,7 @@ part 'entities/fan/widgets/fan_controls.dart';
|
||||
part 'entities/alarm_control_panel/widgets/alarm_control_panel_controls.widget.dart';
|
||||
part 'entities/vacuum/vacuum_entity.class.dart';
|
||||
part 'entities/vacuum/widgets/vacuum_controls.dart';
|
||||
part 'entities/vacuum/widgets/vacuum_state_button.dart';
|
||||
part 'pages/settings.page.dart';
|
||||
part 'pages/purchase.page.dart';
|
||||
part 'pages/widgets/product_purchase.widget.dart';
|
||||
|
Reference in New Issue
Block a user