WIP #416 Vacuum support
This commit is contained in:
parent
2f110b20bb
commit
abd23e27ea
@ -29,6 +29,10 @@ class EntityState {
|
||||
static const ok = 'ok';
|
||||
static const problem = 'problem';
|
||||
static const active = 'active';
|
||||
static const cleaning = 'cleaning';
|
||||
static const docked = 'docked';
|
||||
static const returning = 'returning';
|
||||
static const error = 'error';
|
||||
}
|
||||
|
||||
class EntityUIAction {
|
||||
|
80
lib/entities/vacuum/vacuum_entity.class.dart
Normal file
80
lib/entities/vacuum/vacuum_entity.class.dart
Normal file
@ -0,0 +1,80 @@
|
||||
part of '../../main.dart';
|
||||
|
||||
class VacuumEntity extends Entity {
|
||||
|
||||
static const SUPPORT_TURN_ON = 1;
|
||||
static const SUPPORT_TURN_OFF = 2;
|
||||
static const SUPPORT_PAUSE = 4;
|
||||
static const SUPPORT_STOP = 8;
|
||||
static const SUPPORT_RETURN_HOME = 16;
|
||||
static const SUPPORT_FAN_SPEED = 32;
|
||||
static const SUPPORT_BATTERY = 64;
|
||||
static const SUPPORT_STATUS = 128;
|
||||
static const SUPPORT_SEND_COMMAND = 256;
|
||||
static const SUPPORT_LOCATE = 512;
|
||||
static const SUPPORT_CLEAN_SPOT = 1024;
|
||||
static const SUPPORT_MAP = 2048;
|
||||
static const SUPPORT_STATE = 4096;
|
||||
static const SUPPORT_START = 8192;
|
||||
|
||||
VacuumEntity(Map rawData, String webHost) : super(rawData, webHost);
|
||||
|
||||
bool get supportTurnOn => ((supportedFeatures &
|
||||
VacuumEntity.SUPPORT_TURN_ON) ==
|
||||
VacuumEntity.SUPPORT_TURN_ON);
|
||||
bool get supportTurnOff => ((supportedFeatures &
|
||||
VacuumEntity.SUPPORT_TURN_OFF) ==
|
||||
VacuumEntity.SUPPORT_TURN_OFF);
|
||||
bool get supportPause => ((supportedFeatures &
|
||||
VacuumEntity.SUPPORT_PAUSE) ==
|
||||
VacuumEntity.SUPPORT_PAUSE);
|
||||
bool get supportStop => ((supportedFeatures &
|
||||
VacuumEntity.SUPPORT_STOP) ==
|
||||
VacuumEntity.SUPPORT_STOP);
|
||||
bool get supportReturnHome => ((supportedFeatures &
|
||||
VacuumEntity.SUPPORT_RETURN_HOME) ==
|
||||
VacuumEntity.SUPPORT_RETURN_HOME);
|
||||
bool get supportFanSpeed => ((supportedFeatures &
|
||||
VacuumEntity.SUPPORT_FAN_SPEED) ==
|
||||
VacuumEntity.SUPPORT_FAN_SPEED);
|
||||
bool get supportBattery => ((supportedFeatures &
|
||||
VacuumEntity.SUPPORT_BATTERY) ==
|
||||
VacuumEntity.SUPPORT_BATTERY);
|
||||
bool get supportStatus => ((supportedFeatures &
|
||||
VacuumEntity.SUPPORT_STATUS) ==
|
||||
VacuumEntity.SUPPORT_STATUS);
|
||||
bool get supportSendCommand => ((supportedFeatures &
|
||||
VacuumEntity.SUPPORT_SEND_COMMAND) ==
|
||||
VacuumEntity.SUPPORT_SEND_COMMAND);
|
||||
bool get supportLocate => ((supportedFeatures &
|
||||
VacuumEntity.SUPPORT_LOCATE) ==
|
||||
VacuumEntity.SUPPORT_LOCATE);
|
||||
bool get supportCleanSpot => ((supportedFeatures &
|
||||
VacuumEntity.SUPPORT_CLEAN_SPOT) ==
|
||||
VacuumEntity.SUPPORT_CLEAN_SPOT);
|
||||
bool get supportMap => ((supportedFeatures &
|
||||
VacuumEntity.SUPPORT_MAP) ==
|
||||
VacuumEntity.SUPPORT_MAP);
|
||||
bool get supportState => ((supportedFeatures &
|
||||
VacuumEntity.SUPPORT_STATE) ==
|
||||
VacuumEntity.SUPPORT_STATE);
|
||||
bool get supportStart => ((supportedFeatures &
|
||||
VacuumEntity.SUPPORT_START) ==
|
||||
VacuumEntity.SUPPORT_START);
|
||||
|
||||
List<String> get fanSpeedList => getStringListAttributeValue("fan_speed_list");
|
||||
String get fanSpeed => getAttribute("fan_speed");
|
||||
String get status => getAttribute("status");
|
||||
int get batteryLevel => _getIntAttributeValue("battery_level");
|
||||
String get batteryIcon => getAttribute("battery_icon");
|
||||
|
||||
/*@override
|
||||
Widget _buildStatePart(BuildContext context) {
|
||||
return SwitchStateWidget();
|
||||
}*/
|
||||
|
||||
@override
|
||||
Widget _buildAdditionalControlsForPage(BuildContext context) {
|
||||
return VacuumControls();
|
||||
}
|
||||
}
|
104
lib/entities/vacuum/widgets/vacuum_controls.dart
Normal file
104
lib/entities/vacuum/widgets/vacuum_controls.dart
Normal file
@ -0,0 +1,104 @@
|
||||
part of '../../../main.dart';
|
||||
|
||||
class VacuumControls extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
VacuumEntity entity = EntityModel.of(context).entityWrapper.entity;
|
||||
return Padding(
|
||||
padding: EdgeInsets.only(left: Sizes.leftWidgetPadding, right: Sizes.rightWidgetPadding),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: <Widget>[
|
||||
_buildStatusAndBattery(entity),
|
||||
_buildCommands(entity)
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildStatusAndBattery(VacuumEntity entity) {
|
||||
List<Widget> result = [];
|
||||
if (entity.supportStatus) {
|
||||
result.addAll(
|
||||
<Widget>[
|
||||
Text("Status:", style: TextStyle(fontSize: Sizes.stateFontSize),),
|
||||
Container(width: 6,),
|
||||
Expanded(
|
||||
//flex: 1,
|
||||
child: Text(
|
||||
"${entity.status}",
|
||||
maxLines: 1,
|
||||
softWrap: true,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(
|
||||
fontSize: Sizes.stateFontSize,
|
||||
fontWeight: FontWeight.bold
|
||||
),
|
||||
),
|
||||
),
|
||||
]
|
||||
);
|
||||
}
|
||||
if (entity.supportBattery && entity.batteryLevel != null) {
|
||||
String iconName = entity.batteryIcon ?? "mdi:battery";
|
||||
int batteryLevel = entity.batteryLevel ?? 100;
|
||||
result.addAll(<Widget>[
|
||||
Icon(MaterialDesignIcons.getIconDataFromIconName(iconName)),
|
||||
Container(width: 6,),
|
||||
Text("$batteryLevel %", style: TextStyle(fontSize: Sizes.stateFontSize))
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
if (result.isEmpty) {
|
||||
return Container(width: 0, height: 0);
|
||||
}
|
||||
|
||||
return Padding(
|
||||
padding: EdgeInsets.only(bottom: Sizes.rowPadding),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
mainAxisSize: MainAxisSize.max,
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: result,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildCommands(VacuumEntity entity) {
|
||||
List<Widget> commandButtons = [];
|
||||
double iconSize = 32;
|
||||
if (entity.supportPause) {
|
||||
commandButtons.add(
|
||||
IconButton(
|
||||
icon: Icon(MaterialDesignIcons.getIconDataFromIconName("mdi:play-pause")),
|
||||
iconSize: iconSize,
|
||||
onPressed: () => Logger.d("[VACUUM] pause"),
|
||||
)
|
||||
);
|
||||
}
|
||||
if (entity.supportStop) {
|
||||
commandButtons.add(
|
||||
IconButton(
|
||||
icon: Icon(MaterialDesignIcons.getIconDataFromIconName("mdi:stop")),
|
||||
iconSize: iconSize,
|
||||
onPressed: () => Logger.d("[VACUUM] stop"),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
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,
|
||||
)
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
@ -101,6 +101,9 @@ class EntityCollection {
|
||||
case "timer": {
|
||||
return TimerEntity(rawEntityData, homeAssistantWebHost);
|
||||
}
|
||||
case "vacuum": {
|
||||
return VacuumEntity(rawEntityData, homeAssistantWebHost);
|
||||
}
|
||||
default: {
|
||||
return Entity(rawEntityData, homeAssistantWebHost);
|
||||
}
|
||||
|
@ -93,6 +93,8 @@ part 'entities/light/widgets/light_controls.dart';
|
||||
part 'entities/media_player/widgets/media_player_widgets.dart';
|
||||
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 'pages/settings.page.dart';
|
||||
part 'pages/purchase.page.dart';
|
||||
part 'pages/widgets/product_purchase.widget.dart';
|
||||
|
@ -37,7 +37,8 @@ class MaterialDesignIcons {
|
||||
"alarm_control_panel.armed_custom_bypass" : "mdi:bell",
|
||||
"alarm_control_panel.triggered" : "mdi:bell-ring",
|
||||
"alarm_control_panel" : "mdi:bell",
|
||||
"updater": "mdi:cloud-upload"
|
||||
"updater": "mdi:cloud-upload",
|
||||
"vacuum": "mdi:robot-vacuum"
|
||||
};
|
||||
|
||||
static final Map defaultIconsByDeviceClass = {
|
||||
|
Reference in New Issue
Block a user