2019-08-24 21:22:32 +03:00
|
|
|
part of '../../../main.dart';
|
2018-10-27 14:27:41 +03:00
|
|
|
|
|
|
|
class CoverControlWidget extends StatefulWidget {
|
|
|
|
|
|
|
|
CoverControlWidget({Key key}) : super(key: key);
|
|
|
|
|
|
|
|
@override
|
|
|
|
_CoverControlWidgetState createState() => _CoverControlWidgetState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _CoverControlWidgetState extends State<CoverControlWidget> {
|
|
|
|
|
|
|
|
double _tmpPosition = 0.0;
|
|
|
|
double _tmpTiltPosition = 0.0;
|
|
|
|
bool _changedHere = false;
|
|
|
|
|
|
|
|
void _setNewPosition(CoverEntity entity, double position) {
|
|
|
|
setState(() {
|
|
|
|
_tmpPosition = position.roundToDouble();
|
|
|
|
_changedHere = true;
|
2019-10-28 19:59:47 +02:00
|
|
|
ConnectionManager().callService(entity.domain, "set_cover_position", entity.entityId,{"position": _tmpPosition.round()});
|
2018-10-27 14:27:41 +03:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
void _setNewTiltPosition(CoverEntity entity, double position) {
|
|
|
|
setState(() {
|
|
|
|
_tmpTiltPosition = position.roundToDouble();
|
|
|
|
_changedHere = true;
|
2019-10-28 19:59:47 +02:00
|
|
|
ConnectionManager().callService(entity.domain, "set_cover_tilt_position", entity.entityId,{"tilt_position": _tmpTiltPosition.round()});
|
2018-10-27 14:27:41 +03:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
void _resetVars(CoverEntity entity) {
|
|
|
|
_tmpPosition = entity.currentPosition;
|
|
|
|
_tmpTiltPosition = entity.currentTiltPosition;
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
final entityModel = EntityModel.of(context);
|
2018-11-16 22:32:43 +02:00
|
|
|
final CoverEntity entity = entityModel.entityWrapper.entity;
|
2018-10-27 14:27:41 +03:00
|
|
|
if (_changedHere) {
|
|
|
|
_changedHere = false;
|
|
|
|
} else {
|
|
|
|
_resetVars(entity);
|
|
|
|
}
|
|
|
|
return Padding(
|
2018-11-12 20:28:10 +02:00
|
|
|
padding: EdgeInsets.fromLTRB(Sizes.leftWidgetPadding, Sizes.rowPadding, Sizes.rightWidgetPadding, 0.0),
|
2018-10-27 14:27:41 +03:00
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: <Widget>[
|
|
|
|
_buildPositionControls(entity),
|
|
|
|
_buildTiltControls(entity)
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
Widget _buildPositionControls(CoverEntity entity) {
|
|
|
|
if (entity.supportSetPosition) {
|
|
|
|
return Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: <Widget>[
|
|
|
|
Padding(
|
|
|
|
padding: EdgeInsets.fromLTRB(
|
2018-11-12 20:28:10 +02:00
|
|
|
0.0, Sizes.rowPadding, 0.0, Sizes.rowPadding),
|
2018-10-27 14:27:41 +03:00
|
|
|
child: Text("Position", style: TextStyle(
|
2018-11-12 20:28:10 +02:00
|
|
|
fontSize: Sizes.stateFontSize
|
2018-10-27 14:27:41 +03:00
|
|
|
)),
|
|
|
|
),
|
|
|
|
Slider(
|
|
|
|
value: _tmpPosition,
|
|
|
|
min: 0.0,
|
|
|
|
max: 100.0,
|
|
|
|
divisions: 10,
|
|
|
|
onChanged: (double value) {
|
|
|
|
setState(() {
|
|
|
|
_tmpPosition = value.roundToDouble();
|
|
|
|
_changedHere = true;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
onChangeEnd: (double value) => _setNewPosition(entity, value),
|
|
|
|
),
|
2018-11-12 20:28:10 +02:00
|
|
|
Container(height: Sizes.rowPadding,)
|
2018-10-27 14:27:41 +03:00
|
|
|
],
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
return Container(width: 0.0, height: 0.0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Widget _buildTiltControls(CoverEntity entity) {
|
|
|
|
List<Widget> controls = [];
|
|
|
|
if (entity.supportCloseTilt || entity.supportOpenTilt || entity.supportStopTilt) {
|
|
|
|
controls.add(
|
|
|
|
CoverTiltControlsWidget()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
if (entity.supportSetTiltPosition) {
|
|
|
|
controls.addAll(<Widget>[
|
|
|
|
Slider(
|
|
|
|
value: _tmpTiltPosition,
|
|
|
|
min: 0.0,
|
|
|
|
max: 100.0,
|
|
|
|
divisions: 10,
|
|
|
|
onChanged: (double value) {
|
|
|
|
setState(() {
|
|
|
|
_tmpTiltPosition = value.roundToDouble();
|
|
|
|
_changedHere = true;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
onChangeEnd: (double value) => _setNewTiltPosition(entity, value),
|
|
|
|
),
|
2018-11-12 20:28:10 +02:00
|
|
|
Container(height: Sizes.rowPadding,)
|
2018-10-27 14:27:41 +03:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
if (controls.isNotEmpty) {
|
|
|
|
controls.insert(0, Padding(
|
|
|
|
padding: EdgeInsets.fromLTRB(
|
2018-11-12 20:28:10 +02:00
|
|
|
0.0, Sizes.rowPadding, 0.0, Sizes.rowPadding),
|
2018-10-27 14:27:41 +03:00
|
|
|
child: Text("Tilt position", style: TextStyle(
|
2018-11-12 20:28:10 +02:00
|
|
|
fontSize: Sizes.stateFontSize
|
2018-10-27 14:27:41 +03:00
|
|
|
)),
|
|
|
|
));
|
|
|
|
return Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: controls,
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
return Container(width: 0.0, height: 0.0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
class CoverTiltControlsWidget extends StatelessWidget {
|
|
|
|
void _open(CoverEntity entity) {
|
2019-10-28 19:59:47 +02:00
|
|
|
ConnectionManager().callService(
|
|
|
|
entity.domain, "open_cover_tilt", entity.entityId, null);
|
2018-10-27 14:27:41 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void _close(CoverEntity entity) {
|
2019-10-28 19:59:47 +02:00
|
|
|
ConnectionManager().callService(
|
|
|
|
entity.domain, "close_cover_tilt", entity.entityId, null);
|
2018-10-27 14:27:41 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void _stop(CoverEntity entity) {
|
2019-10-28 19:59:47 +02:00
|
|
|
ConnectionManager().callService(
|
|
|
|
entity.domain, "stop_cover_tilt", entity.entityId, null);
|
2018-10-27 14:27:41 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
final entityModel = EntityModel.of(context);
|
2018-11-16 22:32:43 +02:00
|
|
|
final CoverEntity entity = entityModel.entityWrapper.entity;
|
2018-10-27 14:27:41 +03:00
|
|
|
List<Widget> buttons = [];
|
|
|
|
if (entity.supportOpenTilt) {
|
|
|
|
buttons.add(IconButton(
|
|
|
|
icon: Icon(
|
2019-02-22 15:15:27 +02:00
|
|
|
MaterialDesignIcons.getIconDataFromIconName(
|
2018-10-27 14:27:41 +03:00
|
|
|
"mdi:arrow-top-right"),
|
2018-11-12 20:28:10 +02:00
|
|
|
size: Sizes.iconSize,
|
2018-10-27 14:27:41 +03:00
|
|
|
),
|
|
|
|
onPressed: entity.canTiltBeOpened ? () => _open(entity) : null));
|
|
|
|
} else {
|
|
|
|
buttons.add(Container(
|
2018-11-12 20:28:10 +02:00
|
|
|
width: Sizes.iconSize + 20.0,
|
2018-10-27 14:27:41 +03:00
|
|
|
));
|
|
|
|
}
|
|
|
|
if (entity.supportStopTilt) {
|
|
|
|
buttons.add(IconButton(
|
|
|
|
icon: Icon(
|
2019-02-22 15:15:27 +02:00
|
|
|
MaterialDesignIcons.getIconDataFromIconName("mdi:stop"),
|
2018-11-12 20:28:10 +02:00
|
|
|
size: Sizes.iconSize,
|
2018-10-27 14:27:41 +03:00
|
|
|
),
|
|
|
|
onPressed: () => _stop(entity)));
|
|
|
|
} else {
|
|
|
|
buttons.add(Container(
|
2018-11-12 20:28:10 +02:00
|
|
|
width: Sizes.iconSize + 20.0,
|
2018-10-27 14:27:41 +03:00
|
|
|
));
|
|
|
|
}
|
|
|
|
if (entity.supportCloseTilt) {
|
|
|
|
buttons.add(IconButton(
|
|
|
|
icon: Icon(
|
2019-02-22 15:15:27 +02:00
|
|
|
MaterialDesignIcons.getIconDataFromIconName(
|
2018-10-27 14:27:41 +03:00
|
|
|
"mdi:arrow-bottom-left"),
|
2018-11-12 20:28:10 +02:00
|
|
|
size: Sizes.iconSize,
|
2018-10-27 14:27:41 +03:00
|
|
|
),
|
|
|
|
onPressed: entity.canTiltBeClosed ? () => _close(entity) : null));
|
|
|
|
} else {
|
|
|
|
buttons.add(Container(
|
2018-11-12 20:28:10 +02:00
|
|
|
width: Sizes.iconSize + 20.0,
|
2018-10-27 14:27:41 +03:00
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
return Row(
|
|
|
|
children: buttons,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|