This repository has been archived on 2023-11-18. You can view files and clone it, but cannot push or open issues or pull requests.
ha_client/lib/entity_class/switch_entity.class.dart

34 lines
796 B
Dart
Raw Normal View History

part of '../main.dart';
2018-10-02 00:41:40 +03:00
class _SwitchEntityWidgetState extends _EntityWidgetState {
@override
void initState() {
super.initState();
}
@override
2018-10-02 23:10:40 +03:00
void setNewState(newValue) {
setState(() {
widget.entity.assumedState = newValue ? 'on' : 'off';
});
Timer(Duration(seconds: 2), (){
setState(() {
widget.entity.assumedState = widget.entity.state;
});
});
eventBus.fire(new ServiceCallEvent(
2018-10-02 00:41:40 +03:00
widget.entity.domain, (newValue as bool) ? "turn_on" : "turn_off", widget.entity.entityId, null));
}
@override
Widget _buildActionWidget(bool inCard, BuildContext context) {
return Switch(
2018-10-02 23:10:40 +03:00
value: widget.entity.assumedState == 'on',
onChanged: ((switchState) {
2018-10-02 23:10:40 +03:00
setNewState(switchState);
}),
);
}
}