Ctrl K
ComunidadGuías…

app/services/forecast/pvnode_rules.rb

Rama develop · réplica de lectura del repositorio original.

Archivo original ↗Preguntar a KiBot
module Forecast
  # Shared pvnode export rules for the .env value emitter (Export::Env::Forecast)
  # and the compose env-key list (Export::Services::ForecastCollector).
  module PvnodeRules
    # Canonical env-var key set for the site-based API v2, consumed by the
    # compose service's environment list. Location and all PV strings live on
    # the pvnode site and are referenced by the site ID, so none of the
    # location/roof/extra-param variables are exported. PVNODE_PAID is appended
    # only for paid accounts; see #v2_env_keys.
    V2_BASE_KEYS = %w[FORECAST_PROVIDER PVNODE_SITE_ID PVNODE_APIKEY].freeze

    module_function

    # PVNODE_PAID is only set for paid accounts; the collector treats an absent
    # value as the free tier.
    def paid_plan?(value)
      value.present? && value.to_s != 'false'
    end

    # The full, ordered v2 env-var key list for the given pvnode settings.
    # PVNODE_REQUEST_LIMIT is optional in both API versions: without it the
    # collector schedules against the full request budget of the plan.
    def v2_env_keys(paid_value, request_limit = nil)
      keys = V2_BASE_KEYS.dup
      keys << 'PVNODE_PAID' if paid_plan?(paid_value)
      keys << 'PVNODE_REQUEST_LIMIT' if request_limit.present?
      keys
    end
  end
end