2018-09-25 22:47:06 +03:00
|
|
|
part of 'main.dart';
|
|
|
|
|
|
|
|
class TheLogger {
|
|
|
|
|
|
|
|
static List<String> _log = [];
|
|
|
|
|
|
|
|
static String getLog() {
|
|
|
|
String res = '';
|
|
|
|
_log.forEach((line) {
|
|
|
|
res += "$line\n";
|
|
|
|
});
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool get isInDebugMode {
|
|
|
|
bool inDebugMode = false;
|
|
|
|
|
|
|
|
assert(inDebugMode = true);
|
|
|
|
|
|
|
|
return inDebugMode;
|
|
|
|
}
|
|
|
|
|
2018-10-27 01:24:23 +03:00
|
|
|
static void error(String message) {
|
|
|
|
_writeToLog("Error", message);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void warning(String message) {
|
|
|
|
_writeToLog("Warning", message);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void debug(String message) {
|
|
|
|
_writeToLog("Debug", message);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void _writeToLog(String level, String message) {
|
2018-09-25 22:47:06 +03:00
|
|
|
if (isInDebugMode) {
|
|
|
|
debugPrint('$message');
|
|
|
|
}
|
2018-10-27 01:24:23 +03:00
|
|
|
DateTime t = DateTime.now();
|
|
|
|
_log.add("${formatDate(t, ["mm","dd"," ","HH",":","nn",":","ss"])} [$level] : $message");
|
|
|
|
if (_log.length > 100) {
|
2018-09-25 22:47:06 +03:00
|
|
|
_log.removeAt(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-10-02 00:41:40 +03:00
|
|
|
class HAUtils {
|
2018-09-25 22:47:06 +03:00
|
|
|
static void launchURL(String url) async {
|
|
|
|
if (await canLaunch(url)) {
|
|
|
|
await launch(url);
|
|
|
|
} else {
|
2018-10-27 01:24:23 +03:00
|
|
|
TheLogger.error( "Could not launch $url");
|
2018-09-25 22:47:06 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class StateChangedEvent {
|
|
|
|
String entityId;
|
2018-09-29 13:49:25 +03:00
|
|
|
String newState;
|
2018-09-29 17:59:38 +03:00
|
|
|
bool localChange;
|
2018-09-25 22:47:06 +03:00
|
|
|
|
2018-09-29 17:59:38 +03:00
|
|
|
StateChangedEvent(this.entityId, this.newState, this.localChange);
|
2018-09-25 22:47:06 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
class SettingsChangedEvent {
|
|
|
|
bool reconnect;
|
|
|
|
|
|
|
|
SettingsChangedEvent(this.reconnect);
|
2018-09-29 13:49:25 +03:00
|
|
|
}
|
|
|
|
|
2018-10-07 02:17:14 +03:00
|
|
|
class RefreshDataEvent {
|
|
|
|
RefreshDataEvent();
|
|
|
|
}
|
|
|
|
|
|
|
|
class RefreshDataFinishedEvent {
|
|
|
|
RefreshDataFinishedEvent();
|
|
|
|
}
|
|
|
|
|
2018-09-29 13:49:25 +03:00
|
|
|
class ServiceCallEvent {
|
|
|
|
String domain;
|
|
|
|
String service;
|
|
|
|
String entityId;
|
2018-10-16 17:35:13 +03:00
|
|
|
Map<String, dynamic> additionalParams;
|
2018-09-29 13:49:25 +03:00
|
|
|
|
|
|
|
ServiceCallEvent(this.domain, this.service, this.entityId, this.additionalParams);
|
2018-09-29 16:19:01 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
class ShowEntityPageEvent {
|
|
|
|
Entity entity;
|
|
|
|
|
|
|
|
ShowEntityPageEvent(this.entity);
|
2018-10-07 09:55:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
class ShowErrorEvent {
|
|
|
|
String text;
|
|
|
|
int errorCode;
|
|
|
|
|
|
|
|
ShowErrorEvent(this.text, this.errorCode);
|
2018-09-25 22:47:06 +03:00
|
|
|
}
|