2019-08-24 21:22:32 +03:00
|
|
|
part of '../../main.dart';
|
2018-10-27 14:27:41 +03:00
|
|
|
|
|
|
|
class DateTimeEntity extends Entity {
|
2019-03-19 23:07:40 +02:00
|
|
|
DateTimeEntity(Map rawData, String webHost) : super(rawData, webHost);
|
|
|
|
|
2018-10-27 14:27:41 +03:00
|
|
|
bool get hasDate => attributes["has_date"] ?? false;
|
|
|
|
bool get hasTime => attributes["has_time"] ?? false;
|
|
|
|
int get year => attributes["year"] ?? 1970;
|
|
|
|
int get month => attributes["month"] ?? 1;
|
|
|
|
int get day => attributes["day"] ?? 1;
|
|
|
|
int get hour => attributes["hour"] ?? 0;
|
|
|
|
int get minute => attributes["minute"] ?? 0;
|
|
|
|
int get second => attributes["second"] ?? 0;
|
|
|
|
String get formattedState => _getFormattedState();
|
|
|
|
DateTime get dateTimeState => _getDateTimeState();
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget _buildStatePart(BuildContext context) {
|
|
|
|
return DateTimeStateWidget();
|
|
|
|
}
|
|
|
|
|
|
|
|
DateTime _getDateTimeState() {
|
|
|
|
return DateTime(
|
|
|
|
this.year, this.month, this.day, this.hour, this.minute, this.second);
|
|
|
|
}
|
|
|
|
|
|
|
|
String _getFormattedState() {
|
|
|
|
String formattedState = "";
|
|
|
|
if (this.hasDate) {
|
|
|
|
formattedState += formatDate(dateTimeState, [M, ' ', d, ', ', yyyy]);
|
|
|
|
}
|
|
|
|
if (this.hasTime) {
|
|
|
|
formattedState += " " + formatDate(dateTimeState, [HH, ':', nn]);
|
|
|
|
}
|
|
|
|
return formattedState;
|
|
|
|
}
|
|
|
|
|
2019-10-28 19:59:47 +02:00
|
|
|
void setNewState(Map newValue) {
|
2019-11-08 21:37:41 +02:00
|
|
|
ConnectionManager().callService(domain: domain, service: "set_datetime", entityId: entityId, data: newValue);
|
2018-10-27 14:27:41 +03:00
|
|
|
}
|
|
|
|
}
|