This commit is contained in:
Yegor Vialov 2018-10-15 00:29:40 +03:00
parent ffc053fbe6
commit 69f45b52cf
5 changed files with 37 additions and 13 deletions

View File

@ -233,6 +233,8 @@ class ClimateEntity extends Entity {
List<String> get operationList => (attributes["operation_list"] as List).cast<String>(); List<String> get operationList => (attributes["operation_list"] as List).cast<String>();
double get temperature => _getTemperature(); double get temperature => _getTemperature();
double get targetHigh => _getTargetHigh();
double get targetLow => _getTargetLow();
String get operationMode => attributes['operation_mode'] ?? ""; String get operationMode => attributes['operation_mode'] ?? "";
bool get awayMode => attributes['away_mode'] == "on"; bool get awayMode => attributes['away_mode'] == "on";
@ -249,13 +251,35 @@ class ClimateEntity extends Entity {
} }
double _getTemperature() { double _getTemperature() {
var temp1 = attributes['temperature'] ?? attributes['target_temp_low']; var temp1 = attributes['temperature'];
if (temp1 is int) { if (temp1 is int) {
return temp1.toDouble(); return temp1.toDouble();
} else if (temp1 is double) { } else if (temp1 is double) {
return temp1; return temp1;
} else { } else {
return 0.0; return null;
}
}
double _getTargetHigh() {
var temp1 = attributes['target_temp_high'];
if (temp1 is int) {
return temp1.toDouble();
} else if (temp1 is double) {
return temp1;
} else {
return null;
}
}
double _getTargetLow() {
var temp1 = attributes['target_temp_low'];
if (temp1 is int) {
return temp1.toDouble();
} else if (temp1 is double) {
return temp1;
} else {
return null;
} }
} }
} }

View File

@ -237,13 +237,13 @@ class _ClimateControlWidgetState extends State<ClimateControlWidget> {
bool _showPending = false; bool _showPending = false;
bool _changedHere = false; bool _changedHere = false;
Timer _resetTimer; Timer _resetTimer;
double _tmpTemp = 0.0; double _tmpTemperature = 0.0;
String _tmpOperationMode = ""; String _tmpOperationMode = "";
bool _tmpAwayMode = false; bool _tmpAwayMode = false;
double _temperatureStep = 0.2; double _temperatureStep = 0.2;
void _resetVars(ClimateEntity entity) { void _resetVars(ClimateEntity entity) {
_tmpTemp = entity.temperature; _tmpTemperature = entity.temperature;
_tmpOperationMode = entity.operationMode; _tmpOperationMode = entity.operationMode;
_tmpAwayMode = entity.awayMode; _tmpAwayMode = entity.awayMode;
_showPending = false; _showPending = false;
@ -251,20 +251,20 @@ class _ClimateControlWidgetState extends State<ClimateControlWidget> {
} }
void _temperatureUp(ClimateEntity entity) { void _temperatureUp(ClimateEntity entity) {
_tmpTemp += _temperatureStep; _tmpTemperature += _temperatureStep;
_setTemperature(entity); _setTemperature(entity);
} }
void _temperatureDown(ClimateEntity entity) { void _temperatureDown(ClimateEntity entity) {
_tmpTemp -= _temperatureStep; _tmpTemperature -= _temperatureStep;
_setTemperature(entity); _setTemperature(entity);
} }
void _setTemperature(ClimateEntity entity) { void _setTemperature(ClimateEntity entity) {
setState(() { setState(() {
_tmpTemp = double.parse(_tmpTemp.toStringAsFixed(1)); _tmpTemperature = double.parse(_tmpTemperature.toStringAsFixed(1));
_changedHere = true; _changedHere = true;
eventBus.fire(new ServiceCallEvent(entity.domain, "set_temperature", entity.entityId,{"temperature": "${_tmpTemp.toStringAsFixed(1)}"})); eventBus.fire(new ServiceCallEvent(entity.domain, "set_temperature", entity.entityId,{"temperature": "${_tmpTemperature.toStringAsFixed(1)}"}));
_resetStateTimer(entity); _resetStateTimer(entity);
}); });
} }
@ -302,7 +302,7 @@ class _ClimateControlWidgetState extends State<ClimateControlWidget> {
final entityModel = EntityModel.of(context); final entityModel = EntityModel.of(context);
final ClimateEntity entity = entityModel.entity; final ClimateEntity entity = entityModel.entity;
if (_changedHere) { if (_changedHere) {
_showPending = (_tmpTemp != entity.temperature); _showPending = (_tmpTemperature != entity.temperature);
_changedHere = false; _changedHere = false;
} else { } else {
_resetTimer?.cancel(); _resetTimer?.cancel();
@ -320,7 +320,7 @@ class _ClimateControlWidgetState extends State<ClimateControlWidget> {
children: <Widget>[ children: <Widget>[
Expanded( Expanded(
child: Text( child: Text(
"$_tmpTemp", "$_tmpTemperature",
style: TextStyle( style: TextStyle(
fontSize: entity.largeFontSize, fontSize: entity.largeFontSize,
color: _showPending ? Colors.red : Colors.black color: _showPending ? Colors.red : Colors.black

View File

@ -350,7 +350,7 @@ class ClimateStateWidget extends StatelessWidget {
fontSize: entityModel.entity.stateFontSize, fontSize: entityModel.entity.stateFontSize,
)), )),
Text( Text(
" ${entity.attributes["temperature"]}", entity.temperature!= null ? " ${entity.temperature}" : " ${entity.targetLow} - ${entity.targetHigh}",
textAlign: TextAlign.right, textAlign: TextAlign.right,
style: new TextStyle( style: new TextStyle(
fontSize: entityModel.entity.stateFontSize, fontSize: entityModel.entity.stateFontSize,

View File

@ -30,7 +30,7 @@ part 'card_class.dart';
EventBus eventBus = new EventBus(); EventBus eventBus = new EventBus();
const String appName = "HA Client"; const String appName = "HA Client";
const appVersion = "0.2.5.34"; const appVersion = "0.2.5.35";
String homeAssistantWebHost; String homeAssistantWebHost;

View File

@ -1,7 +1,7 @@
name: hass_client name: hass_client
description: Home Assistant Android Client description: Home Assistant Android Client
version: 0.2.5+34 version: 0.2.5+35
environment: environment:
sdk: ">=2.0.0-dev.68.0 <3.0.0" sdk: ">=2.0.0-dev.68.0 <3.0.0"