Skip to content

Commit

Permalink
Alter attribute naming to remove "pv_"
Browse files Browse the repository at this point in the history
  • Loading branch information
autoSteve committed Jul 6, 2024
1 parent 4a8efa3 commit 0bd7b91
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 10 additions & 10 deletions custom_components/solcast_solar/solcastapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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):
Expand Down

0 comments on commit 0bd7b91

Please sign in to comment.