WIP #120 render only needed states
This commit is contained in:
@ -8,7 +8,8 @@ class ClimateEntity extends Entity {
|
|||||||
EntityHistoryConfig historyConfig = EntityHistoryConfig(
|
EntityHistoryConfig historyConfig = EntityHistoryConfig(
|
||||||
chartType: EntityHistoryWidgetType.numericAttributes,
|
chartType: EntityHistoryWidgetType.numericAttributes,
|
||||||
numericState: false,
|
numericState: false,
|
||||||
numericAttributesToShow: ["temperature", "current_temperature"]
|
numericAttributesToShow: ["temperature", "current_temperature"],
|
||||||
|
statesToShow: ["heat", "cool", "auto"]
|
||||||
);
|
);
|
||||||
|
|
||||||
static const SUPPORT_TARGET_TEMPERATURE = 1;
|
static const SUPPORT_TARGET_TEMPERATURE = 1;
|
||||||
|
@ -28,8 +28,13 @@ class _CombinedHistoryChartWidgetState extends State<CombinedHistoryChartWidget>
|
|||||||
if ((_selectedId > -1) && (_parsedHistory != null) && (_parsedHistory.first.data.length >= (_selectedId + 1))) {
|
if ((_selectedId > -1) && (_parsedHistory != null) && (_parsedHistory.first.data.length >= (_selectedId + 1))) {
|
||||||
selectedTime = _parsedHistory.first.data[_selectedId].startTime;
|
selectedTime = _parsedHistory.first.data[_selectedId].startTime;
|
||||||
_parsedHistory.where((item) { return item.id == "state"; }).forEach((item) {
|
_parsedHistory.where((item) { return item.id == "state"; }).forEach((item) {
|
||||||
selectedStates.add("${item.data[_selectedId].state}");
|
if (_selectedId < item.data.length) {
|
||||||
colorIndexes.add(item.data[_selectedId].colorId);
|
selectedStates.add(item.data[_selectedId].state);
|
||||||
|
colorIndexes.add(item.data[_selectedId].colorId);
|
||||||
|
} else {
|
||||||
|
selectedStates.add(null);
|
||||||
|
colorIndexes.add(-1);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
_parsedHistory.where((item) { return item.id == "value"; }).forEach((item) {
|
_parsedHistory.where((item) { return item.id == "value"; }).forEach((item) {
|
||||||
selectedStates.add("${item.data[_selectedId].value}");
|
selectedStates.add("${item.data[_selectedId].value}");
|
||||||
@ -104,10 +109,19 @@ class _CombinedHistoryChartWidgetState extends State<CombinedHistoryChartWidget>
|
|||||||
} else {
|
} else {
|
||||||
endTime = now;
|
endTime = now;
|
||||||
}
|
}
|
||||||
|
String state;
|
||||||
|
if (widget.config.statesToShow != null) {
|
||||||
|
if (widget.config.statesToShow.isNotEmpty) {
|
||||||
|
state = widget.config.statesToShow.contains(stateData["state"]) ? stateData["state"] : null;
|
||||||
|
} else {
|
||||||
|
state = stateData["state"];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (stateData["attributes"] != null) {
|
if (stateData["attributes"] != null) {
|
||||||
data.add(CombinedEntityStateHistoryMoment(_parseToDouble(stateData["attributes"]["$attrName"]), stateData["state"], startTime, endTime, i, colorIdCounter));
|
data.add(CombinedEntityStateHistoryMoment(_parseToDouble(stateData["attributes"]["$attrName"]), state, startTime, endTime, i, colorIdCounter));
|
||||||
} else {
|
} else {
|
||||||
data.add(CombinedEntityStateHistoryMoment(null, stateData["state"], startTime, endTime, i, colorIdCounter));
|
data.add(CombinedEntityStateHistoryMoment(null, state, startTime, endTime, i, colorIdCounter));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
data.add(CombinedEntityStateHistoryMoment(data.last.value, data.last.state, now, null, widget.rawHistory.length, colorIdCounter));
|
data.add(CombinedEntityStateHistoryMoment(data.last.value, data.last.state, now, null, widget.rawHistory.length, colorIdCounter));
|
||||||
@ -144,7 +158,7 @@ class _CombinedHistoryChartWidgetState extends State<CombinedHistoryChartWidget>
|
|||||||
domainUpperBoundFn: (CombinedEntityStateHistoryMoment historyMoment, _) => historyMoment.endTime ?? DateTime.now(),
|
domainUpperBoundFn: (CombinedEntityStateHistoryMoment historyMoment, _) => historyMoment.endTime ?? DateTime.now(),
|
||||||
// No measure values are needed for symbol annotations.
|
// No measure values are needed for symbol annotations.
|
||||||
measureFn: (_, __) => null,
|
measureFn: (_, __) => null,
|
||||||
data: numericDataLists[numericDataLists.keys.first],
|
data: numericDataLists[numericDataLists.keys.first].where((hm) => hm.state != null).toList(),
|
||||||
)
|
)
|
||||||
// Configure our custom symbol annotation renderer for this series.
|
// Configure our custom symbol annotation renderer for this series.
|
||||||
..setAttribute(charts.rendererIdKey, 'stateBars')
|
..setAttribute(charts.rendererIdKey, 'stateBars')
|
||||||
@ -237,17 +251,26 @@ class CombinedHistoryControlWidget extends StatelessWidget {
|
|||||||
Widget _buildStates() {
|
Widget _buildStates() {
|
||||||
List<Widget> children = [];
|
List<Widget> children = [];
|
||||||
for (int i = 0; i < selectedStates.length; i++) {
|
for (int i = 0; i < selectedStates.length; i++) {
|
||||||
children.add(
|
if (selectedStates[i] != null) {
|
||||||
Text(
|
children.add(
|
||||||
"${selectedStates[i]}",
|
Text(
|
||||||
textAlign: TextAlign.right,
|
"${selectedStates[i]}",
|
||||||
style: TextStyle(
|
textAlign: TextAlign.right,
|
||||||
fontWeight: FontWeight.bold,
|
style: TextStyle(
|
||||||
color: EntityColors.historyStateColor(selectedStates[i], colorIndexes[i]),
|
fontWeight: FontWeight.bold,
|
||||||
fontSize: 22.0
|
color: EntityColors.historyStateColor(
|
||||||
),
|
selectedStates[i], colorIndexes[i]),
|
||||||
)
|
fontSize: 20.0
|
||||||
);
|
),
|
||||||
|
)
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
children.add(
|
||||||
|
Container(
|
||||||
|
height: 23.0,
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return Column(
|
return Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.end,
|
crossAxisAlignment: CrossAxisAlignment.end,
|
||||||
|
@ -9,9 +9,10 @@ class EntityHistoryWidgetType {
|
|||||||
class EntityHistoryConfig {
|
class EntityHistoryConfig {
|
||||||
final int chartType;
|
final int chartType;
|
||||||
final List<String> numericAttributesToShow;
|
final List<String> numericAttributesToShow;
|
||||||
|
final List<String> statesToShow;
|
||||||
final bool numericState;
|
final bool numericState;
|
||||||
|
|
||||||
EntityHistoryConfig({this.chartType, this.numericAttributesToShow, this.numericState: true});
|
EntityHistoryConfig({this.chartType, this.numericAttributesToShow: const [], this.statesToShow: const [], this.numericState: true});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user