From 0bd7b91e25ced9cf1cecf43f1212c8f1a794f86a Mon Sep 17 00:00:00 2001 From: Steve Saunders Date: Sat, 6 Jul 2024 13:17:02 +1000 Subject: [PATCH] Alter attribute naming to remove "pv_" --- README.md | 10 ++++++---- custom_components/solcast_solar/solcastapi.py | 20 +++++++++---------- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 3417cf4d..42f67977 100644 --- a/README.md +++ b/README.md @@ -287,13 +287,15 @@ Click the Forecast option button and select the Solcast Solar option.. Click SAV > [!NOTE] > Where a site breakdown is available as an attribute, the attribute name is the Solcast site resource ID. > -> Most sensors also include an attribute for `pv_estimate`, `pv_estimate10` and `pv_estimate90`. Template sensors may be created to expose their value, or the `state_attr()` can be used directly in automations. +> Most sensors also include an attribute for `estimate`, `estimate10` and `estimate90`. Template sensors may be created to expose their value, or the `state_attr()` can be used directly in automations. > > Access these in a template sensor or automation using something like: > -> `{{ state_attr('sensor.solcast_pv_forecast_peak_forecast_today', '1234-5678-9012-3456') | float(0) }}` -> `{{ state_attr('sensor.solcast_pv_forecast_peak_forecast_today', 'pv_estimate10') | float(0) }}` -> `{{ state_attr('sensor.solcast_pv_forecast_peak_forecast_today', '1234-5678-9012-3456_pv_estimate10') | float(0) }}` +> ``` +> {{ state_attr('sensor.solcast_pv_forecast_peak_forecast_today', '1234-5678-9012-3456') | float(0) }} +> {{ state_attr('sensor.solcast_pv_forecast_peak_forecast_today', 'estimate10') | float(0) }} +> {{ state_attr('sensor.solcast_pv_forecast_peak_forecast_today', '1234-5678-9012-3456-estimate10') | float(0) }} +> ``` ### Configuration diff --git a/custom_components/solcast_solar/solcastapi.py b/custom_components/solcast_solar/solcastapi.py index a36e9d27..e9f84eb5 100644 --- a/custom_components/solcast_solar/solcastapi.py +++ b/custom_components/solcast_solar/solcastapi.py @@ -596,7 +596,7 @@ def get_forecast_n_hour(self, n_hour, _use_data_field=None) -> int: def get_forecasts_n_hour(self, n_hour) -> Dict[str, Any]: res = {} - for _data_field in ('pv_estimate', 'pv_estimate10', 'pv_estimate90'): res[_data_field] = self.get_forecast_n_hour(n_hour, _data_field) + for _data_field in ('pv_estimate', 'pv_estimate10', 'pv_estimate90'): res[_data_field.replace('pv_','')] = self.get_forecast_n_hour(n_hour, _data_field) return res def get_forecast_custom_hours(self, n_hours, _use_data_field=None) -> int: @@ -608,7 +608,7 @@ def get_forecast_custom_hours(self, n_hours, _use_data_field=None) -> int: def get_forecasts_custom_hours(self, n_hour) -> Dict[str, Any]: res = {} - for _data_field in ('pv_estimate', 'pv_estimate10', 'pv_estimate90'): res[_data_field] = self.get_forecast_custom_hours(n_hour, _data_field) + for _data_field in ('pv_estimate', 'pv_estimate10', 'pv_estimate90'): res[_data_field.replace('pv_','')] = self.get_forecast_custom_hours(n_hour, _data_field) return res def get_power_n_mins(self, n_mins, site=None, _use_data_field=None) -> int: @@ -624,8 +624,8 @@ def get_sites_power_n_mins(self, n_mins) -> Dict[str, Any]: res = {} for site in self._sites: res[site['resource_id']] = self.get_power_n_mins(n_mins, site['resource_id']) - for _data_field in ('pv_estimate', 'pv_estimate10', 'pv_estimate90'): res[site['resource_id']+'_'+_data_field] = self.get_power_n_mins(n_mins, site['resource_id'], _data_field) - for _data_field in ('pv_estimate', 'pv_estimate10', 'pv_estimate90'): res[_data_field] = self.get_power_n_mins(n_mins, None, _data_field) + for _data_field in ('pv_estimate', 'pv_estimate10', 'pv_estimate90'): res[site['resource_id']+'-'+_data_field.replace('pv_','')] = self.get_power_n_mins(n_mins, site['resource_id'], _data_field) + for _data_field in ('pv_estimate', 'pv_estimate10', 'pv_estimate90'): res[_data_field.replace('pv_','')] = self.get_power_n_mins(n_mins, None, _data_field) return res def get_peak_w_day(self, n_day, site=None, _use_data_field=None) -> int: @@ -640,8 +640,8 @@ def get_sites_peak_w_day(self, n_day) -> Dict[str, Any]: res = {} for site in self._sites: res[site['resource_id']] = self.get_peak_w_day(n_day, site['resource_id']) - for _data_field in ('pv_estimate', 'pv_estimate10', 'pv_estimate90'): res[site['resource_id']+'_'+_data_field] = self.get_peak_w_day(n_day, site['resource_id'], _data_field) - for _data_field in ('pv_estimate', 'pv_estimate10', 'pv_estimate90'): res[_data_field] = self.get_peak_w_day(n_day, None, _data_field) + for _data_field in ('pv_estimate', 'pv_estimate10', 'pv_estimate90'): res[site['resource_id']+'-'+_data_field.replace('pv_','')] = self.get_peak_w_day(n_day, site['resource_id'], _data_field) + for _data_field in ('pv_estimate', 'pv_estimate10', 'pv_estimate90'): res[_data_field.replace('pv_','')] = self.get_peak_w_day(n_day, None, _data_field) return res def get_peak_w_time_day(self, n_day, site=None, _use_data_field=None) -> dt: @@ -655,8 +655,8 @@ def get_sites_peak_w_time_day(self, n_day) -> Dict[str, Any]: res = {} for site in self._sites: res[site['resource_id']] = self.get_peak_w_time_day(n_day, site['resource_id']) - for _data_field in ('pv_estimate', 'pv_estimate10', 'pv_estimate90'): res[site['resource_id']+'_'+_data_field] = self.get_peak_w_time_day(n_day, site['resource_id'], _data_field) - for _data_field in ('pv_estimate', 'pv_estimate10', 'pv_estimate90'): res[_data_field] = self.get_peak_w_time_day(n_day, None, _data_field) + for _data_field in ('pv_estimate', 'pv_estimate10', 'pv_estimate90'): res[site['resource_id']+'-'+_data_field.replace('pv_','')] = self.get_peak_w_time_day(n_day, site['resource_id'], _data_field) + for _data_field in ('pv_estimate', 'pv_estimate10', 'pv_estimate90'): res[_data_field.replace('pv_','')] = self.get_peak_w_time_day(n_day, None, _data_field) return res def get_forecast_remaining_today(self, _use_data_field=None) -> float: @@ -669,7 +669,7 @@ def get_forecast_remaining_today(self, _use_data_field=None) -> float: def get_forecasts_remaining_today(self) -> Dict[str, Any]: res = {} - for _data_field in ('pv_estimate', 'pv_estimate10', 'pv_estimate90'): res[_data_field] = self.get_forecast_remaining_today(_data_field) + for _data_field in ('pv_estimate', 'pv_estimate10', 'pv_estimate90'): res[_data_field.replace('pv_','')] = self.get_forecast_remaining_today(_data_field) return res def get_total_kwh_forecast_day(self, n_day, _use_data_field=None) -> float: @@ -681,7 +681,7 @@ def get_total_kwh_forecast_day(self, n_day, _use_data_field=None) -> float: def get_total_kwh_forecasts_day(self, n_day) -> Dict[str, Any]: res = {} - for _data_field in ('pv_estimate', 'pv_estimate10', 'pv_estimate90'): res[_data_field] = self.get_total_kwh_forecast_day(n_day, _data_field) + for _data_field in ('pv_estimate', 'pv_estimate10', 'pv_estimate90'): res[_data_field.replace('pv_','')] = self.get_total_kwh_forecast_day(n_day, _data_field) return res def get_forecast_list_slice(self, _data, start_utc, end_utc, search_past=False):