From 636296f9b0228489b0f4a10cdf89f03ead583fc6 Mon Sep 17 00:00:00 2001 From: purcell-lab <79175134+purcell-lab@users.noreply.github.com> Date: Thu, 13 Jul 2023 17:47:26 +1000 Subject: [PATCH] Fix rounding for price & cost forecasts --- src/emhass/retrieve_hass.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/emhass/retrieve_hass.py b/src/emhass/retrieve_hass.py index 3999ef75..eab6b82b 100644 --- a/src/emhass/retrieve_hass.py +++ b/src/emhass/retrieve_hass.py @@ -223,7 +223,7 @@ def get_attr_data_dict(data_df: pd.DataFrame, idx: int, entity_id: str, list_df = copy.deepcopy(data_df).loc[data_df.index[idx]:].reset_index() list_df.columns = ['timestamps', entity_id] ts_list = [str(i) for i in list_df['timestamps'].tolist()] - vals_list = [str(np.round(i)) for i in list_df[entity_id].tolist()] + vals_list = [str(np.round(i,2)) for i in list_df[entity_id].tolist()] forecast_list = [] for i, ts in enumerate(ts_list): datum = {} @@ -231,7 +231,7 @@ def get_attr_data_dict(data_df: pd.DataFrame, idx: int, entity_id: str, datum[entity_id.split('sensor.')[1]] = vals_list[i] forecast_list.append(datum) data = { - "state": str(state), + "state": "{:.2f}".format(state), "attributes": { "unit_of_measurement": unit_of_measurement, "friendly_name": friendly_name, @@ -307,7 +307,7 @@ def post_data(self, data_df: pd.DataFrame, idx: int, entity_id: str, friendly_name, "scheduled_forecast", state) else: data = { - "state": str(state), + "state": "{:.2f}".format(state), "attributes": { "unit_of_measurement": unit_of_measurement, "friendly_name": friendly_name