Files
flutter_opencode_client/lib/data/model/server/temp.dart
GT610 3c592baf2c fix: Use latest dartssh2 and add a switch for temperature between celsius and millicelsius (#1095)
* refactor(sftp): Optimize file download logic and SSH command execution handling

Replace manual chunked downloads with a more concise `sftp.download` method
Consistently use `utf8.decode` to process SSH command output

Remove redundant code and comments, and simplify the logic

* chore: Update `dartssh2` submodule

* feat (Temperature Display): Added an option to switch between degrees Celsius and millicelsius

Allows users to switch temperature units in server settings, resolving the issue of incorrect temperature display on some devices

* chore: Add a participnt

* fix(sftp): Fixed a resource leak issue during file downloads and SSH command execution

Ensured that remote and local file handles are properly closed during file downloads to prevent resource leaks. Additionally, improved error handling during SSH command execution to ensure that all streams are either successfully completed or properly handled in the event of an error.
2026-04-01 11:27:58 +08:00

50 lines
1.1 KiB
Dart

class Temperatures {
final Map<String, double> _map = {};
void parse(String type, String value, {double divisor = 1000.0}) {
final typeSplited = type.split('\n');
final valueSplited = value.split('\n');
for (var i = 0; i < typeSplited.length && i < valueSplited.length; i++) {
final t = typeSplited[i];
final v = valueSplited[i];
if (t.isEmpty || v.isEmpty) {
continue;
}
final name = t.split('/').last;
final temp = double.tryParse(v);
if (temp == null) {
continue;
}
_map[name] = temp / divisor;
}
}
double? get(String name) {
return _map[name];
}
Iterable<String> get devices {
return _map.keys;
}
bool get isEmpty {
return _map.isEmpty;
}
double? get first {
if (_map.isEmpty) {
return null;
}
for (final key in _cpuTemp) {
if (_map.containsKey(key)) {
return _map[key];
}
}
return _map.values.firstOrNull;
}
}
/// soc: mobile phone
/// cpu_thermal / x86_pkg_temp / coretemp / zenpower: x86
const _cpuTemp = ['x86_pkg_temp', 'coretemp', 'zenpower', 'cpu_thermal', 'soc'];