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/entities/climate/climate_entity.class.dart

114 lines
4.3 KiB
Dart
Raw Normal View History

2019-08-24 21:22:32 +03:00
part of '../../main.dart';
2018-10-27 14:27:41 +03:00
class ClimateEntity extends Entity {
@override
EntityHistoryConfig historyConfig = EntityHistoryConfig(
chartType: EntityHistoryWidgetType.numericAttributes,
numericState: false,
2018-11-03 23:10:25 +02:00
numericAttributesToShow: ["current_temperature"]
);
2018-10-27 14:27:41 +03:00
static const SUPPORT_TARGET_TEMPERATURE = 1;
2019-08-16 13:29:41 +03:00
static const SUPPORT_TARGET_TEMPERATURE_RANGE = 2;
static const SUPPORT_TARGET_HUMIDITY = 4;
static const SUPPORT_FAN_MODE = 8;
static const SUPPORT_PRESET_MODE = 16;
static const SUPPORT_SWING_MODE = 32;
static const SUPPORT_AUX_HEAT = 64;
//static const SUPPORT_OPERATION_MODE = 16;
//static const SUPPORT_HOLD_MODE = 256;
//static const SUPPORT_AWAY_MODE = 1024;
//static const SUPPORT_ON_OFF = 4096;
2018-10-27 14:27:41 +03:00
2019-03-19 23:07:40 +02:00
ClimateEntity(Map rawData, String webHost) : super(rawData, webHost);
bool get supportTargetTemperature => ((supportedFeatures &
2018-10-27 14:27:41 +03:00
ClimateEntity.SUPPORT_TARGET_TEMPERATURE) ==
ClimateEntity.SUPPORT_TARGET_TEMPERATURE);
2019-08-16 13:29:41 +03:00
bool get supportTargetTemperatureRange => ((supportedFeatures &
ClimateEntity.SUPPORT_TARGET_TEMPERATURE_RANGE) ==
ClimateEntity.SUPPORT_TARGET_TEMPERATURE_RANGE);
bool get supportTargetHumidity => ((supportedFeatures &
2018-10-27 14:27:41 +03:00
ClimateEntity.SUPPORT_TARGET_HUMIDITY) ==
ClimateEntity.SUPPORT_TARGET_HUMIDITY);
bool get supportFanMode =>
((supportedFeatures & ClimateEntity.SUPPORT_FAN_MODE) ==
2018-10-27 14:27:41 +03:00
ClimateEntity.SUPPORT_FAN_MODE);
bool get supportSwingMode =>
((supportedFeatures & ClimateEntity.SUPPORT_SWING_MODE) ==
2018-10-27 14:27:41 +03:00
ClimateEntity.SUPPORT_SWING_MODE);
2019-08-16 13:29:41 +03:00
bool get supportPresetMode =>
((supportedFeatures & ClimateEntity.SUPPORT_PRESET_MODE) ==
ClimateEntity.SUPPORT_PRESET_MODE);
2018-10-27 14:27:41 +03:00
bool get supportAuxHeat =>
((supportedFeatures & ClimateEntity.SUPPORT_AUX_HEAT) ==
2018-10-27 14:27:41 +03:00
ClimateEntity.SUPPORT_AUX_HEAT);
2019-08-16 13:29:41 +03:00
List<String> get hvacModes => attributes["hvac_modes"] != null
? (attributes["hvac_modes"] as List).cast<String>()
2018-10-27 14:27:41 +03:00
: null;
2019-08-16 13:29:41 +03:00
List<String> get fanModes => attributes["fan_modes"] != null
? (attributes["fan_modes"] as List).cast<String>()
2018-10-27 14:27:41 +03:00
: null;
2019-08-16 13:29:41 +03:00
List<String> get presetModes => attributes["preset_modes"] != null
? (attributes["preset_modes"] as List).cast<String>()
: null;
List<String> get swingModes => attributes["swing_modes"] != null
? (attributes["swing_modes"] as List).cast<String>()
2018-10-27 14:27:41 +03:00
: null;
double get temperature => _getDoubleAttributeValue('temperature');
2019-08-16 13:29:41 +03:00
double get currentTemperature => _getDoubleAttributeValue('current_temperature');
2018-10-27 14:27:41 +03:00
double get targetHigh => _getDoubleAttributeValue('target_temp_high');
double get targetLow => _getDoubleAttributeValue('target_temp_low');
double get maxTemp => _getDoubleAttributeValue('max_temp') ?? 100.0;
double get minTemp => _getDoubleAttributeValue('min_temp') ?? -100.0;
double get targetHumidity => _getDoubleAttributeValue('humidity');
double get maxHumidity => _getDoubleAttributeValue('max_humidity');
double get minHumidity => _getDoubleAttributeValue('min_humidity');
double get temperatureStep => _getDoubleAttributeValue('target_temp_step') ?? 0.5;
2019-08-16 13:29:41 +03:00
String get hvacAction => attributes['hvac_action'];
2018-10-27 14:27:41 +03:00
String get fanMode => attributes['fan_mode'];
2019-08-16 13:29:41 +03:00
String get presetMode => attributes['preset_mode'];
2018-10-27 14:27:41 +03:00
String get swingMode => attributes['swing_mode'];
bool get awayMode => attributes['away_mode'] == "on";
2019-08-16 13:29:41 +03:00
//bool get isOff => state == EntityState.off;
2018-10-27 14:27:41 +03:00
bool get auxHeat => attributes['aux_heat'] == "on";
2018-11-03 23:10:25 +02:00
@override
2019-03-19 23:07:40 +02:00
void update(Map rawData, String webHost) {
super.update(rawData, webHost);
2018-11-03 23:10:25 +02:00
if (supportTargetTemperature) {
historyConfig.numericAttributesToShow.add("temperature");
}
2019-08-16 13:29:41 +03:00
if (supportTargetTemperatureRange) {
2018-11-03 23:10:25 +02:00
historyConfig.numericAttributesToShow.add("target_temp_high");
historyConfig.numericAttributesToShow.add("target_temp_low");
}
}
2018-10-27 14:27:41 +03:00
@override
Widget _buildStatePart(BuildContext context) {
return ClimateStateWidget();
}
@override
Widget _buildAdditionalControlsForPage(BuildContext context) {
return ClimateControlWidget();
}
@override
double _getDoubleAttributeValue(String attributeName) {
var temp1 = attributes["$attributeName"];
if (temp1 is int) {
return temp1.toDouble();
} else if (temp1 is double) {
return temp1;
} else {
return null;
}
}
}