Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EnergySiteInfo: add tarrif v2 and remove tou settings #175

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 80 additions & 18 deletions Sources/TeslaSwift/Model/EnergySiteInfo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ open class EnergySiteInfo: Codable {
open var offGridVehicleChargingReservePercent: Double?

open var userSettings: UserSettings
open var touSettings: TOUSettings?
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

touSettings arent there anymore?
what about for WallConnector?

Copy link
Author

@KevM KevM Oct 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I was on a code sabbatical. I'm back at my Swift efforts now. I do not have a wall connector so maybe my JSON is not the same as yours? Can you give me a sample JSON for an energy site with a wall connector?

Copy link
Owner

@jonasman jonasman Oct 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here's my json with 1 wall connector gen 3.
Looking at the lib, a lot of fields are missing.
Anyway tou_settings can be removed even tho this is a tou_capable

{
  "response": {
    "id": "AAAA",
    "site_name": "Oeiras",
    "site_number": "STE20231001-XXXXX",
    "installation_date": "2023-10-01T22:15:08Z",
    "user_settings": {
      "go_off_grid_test_banner_enabled": null,
      "storm_mode_enabled": null,
      "powerwall_onboarding_settings_set": null,
      "powerwall_tesla_electric_interested_in": null,
      "vpp_tour_enabled": null,
      "sync_grid_alert_enabled": false,
      "breaker_alert_enabled": false,
      "off_grid_vehicle_charging_enabled": null
    },
    "components": {
      "solar": false,
      "battery": false,
      "grid": false,
      "backup": false,
      "gateway": "gateway_type_none",
      "load_meter": false,
      "tou_capable": false,
      "storm_mode_capable": false,
      "flex_energy_request_capable": false,
      "car_charging_data_supported": false,
      "off_grid_vehicle_charging_reserve_supported": false,
      "vehicle_charging_performance_view_enabled": false,
      "vehicle_charging_solar_offset_view_enabled": false,
      "battery_solar_offset_view_enabled": false,
      "energy_service_self_scheduling_enabled": true,
      "wall_connectors": [
        {
          "device_id": "XXXX",
          "din": "1529455-02-E--PGT23103001005",
          "part_number": "1529455-02-E",
          "part_type": 15,
          "part_name": "Gen 3 Wall Connector",
          "is_active": true
        }
      ],
      "nbt_supported": true
    },
    "installation_time_zone": "Europe/Lisbon",
    "tariff_content_v2": {
      "code": "(edited)",
      "name": "0,215",
      "utility": "Luzboa",
      "daily_charges": [
        {
          "name": "Charge"
        }
      ],
      "demand_charges": {
        "ALL": {
          "rates": {
            "ALL": 0
          }
        },
        "Summer": {},
        "Winter": {}
      },
      "energy_charges": {
        "ALL": {
          "rates": {
            "ALL": 0
          }
        },
        "Summer": {
          "rates": {
            "OFF_PEAK": 0.21
          }
        },
        "Winter": {}
      },
      "seasons": {
        "Summer": {
          "fromDay": 1,
          "toDay": 31,
          "fromMonth": 1,
          "toMonth": 12,
          "tou_periods": {
            "OFF_PEAK": {
              "periods": [
                {
                  "toDayOfWeek": 6
                }
              ]
            }
          }
        },
        "Winter": {}
      },
      "sell_tariff": {
        "name": "0,215",
        "utility": "Luzboa",
        "daily_charges": [
          {
            "name": "Charge"
          }
        ],
        "demand_charges": {
          "ALL": {
            "rates": {
              "ALL": 0
            }
          },
          "Summer": {},
          "Winter": {}
        },
        "energy_charges": {
          "ALL": {
            "rates": {
              "ALL": 0
            }
          },
          "Summer": {
            "rates": {
              "OFF_PEAK": 0.21
            }
          },
          "Winter": {}
        },
        "seasons": {
          "Summer": {
            "fromDay": 1,
            "toDay": 31,
            "fromMonth": 1,
            "toMonth": 12,
            "tou_periods": {
              "OFF_PEAK": {
                "periods": [
                  {
                    "toDayOfWeek": 6
                  }
                ]
              }
            }
          },
          "Winter": {}
        }
      },
      "version": 1
    }
  }
}

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

made a commit with the missing fields

open var components: Components
open var tariffContentV2: TariffV2?

enum CodingKeys: String, CodingKey {
case id
Expand All @@ -34,8 +34,8 @@ open class EnergySiteInfo: Codable {
case installationDate = "installation_date"
case userSettings = "user_settings"
case components, version
case tariffContentV2 = "tariff_content_v2"
case batteryCount = "battery_count"
case touSettings = "tou_settings"
case nameplatePower = "nameplate_power"
case nameplateEnergy = "nameplate_energy"
case installationTimeZone = "installation_time_zone"
Expand Down Expand Up @@ -87,43 +87,105 @@ open class EnergySiteInfo: Codable {
case wallConnectors = "wall_connectors"
}
}

// MARK: - SeasonPeriod
open class SeasonPeriod: Codable {
open var toDayOfWeek: Int?
open var toHour: Int?
open var toMinute: Int?
open var fromDayOfWeek: Int?
open var fromHour: Int?
open var fromMinute: Int?
}

// MARK: - SeasonPeriods
open class TariffV2: Codable {
open var code: String
open var name: String
open var utility: String
open var energyCharges: [String: EnergyChargeRates]
open var seasons: [String: Season]
open var sellTariff: SellTariff
open var version: Int

enum CodingKeys: String, CodingKey {
case code
case name
case utility
case energyCharges = "energy_charges"
case seasons
case sellTariff = "sell_tariff"
case version
}
}

// MARK: - SeasonPeriod
open class SeasonPeriods: Codable {
open var periods: [SeasonPeriod]

// MARK: - TouSettings
open class TOUSettings: Codable {
open var optimizationStrategy: String
open var schedule: [Schedule]
enum CodingKeys: String, CodingKey {
case periods
}
}

// MARK: - Season
open class Season: Codable {
open var fromDay: Int
open var toDay: Int
open var fromMonth: Int
open var toMonth: Int
open var touPeriods: [String: SeasonPeriods]

enum CodingKeys: String, CodingKey {
case optimizationStrategy = "optimization_strategy"
case schedule
case fromDay = "fromDay"
case toDay = "toDay"
case fromMonth = "fromMonth"
case toMonth = "toMonth"
case touPeriods = "tou_periods"
}
}

// MARK: - Schedule
open class Schedule: Codable {
open var target: String
open var weekDays: [Int]
open var startSeconds: Int
open var endSeconds: Int
// MARK: - EnergyChargeRates
open class EnergyChargeRates: Codable {
open var rates: [String: Double]

enum CodingKeys: String, CodingKey {
case target
case weekDays = "week_days"
case startSeconds = "start_seconds"
case endSeconds = "end_seconds"
case rates
}
}

// MARK: - SellTariff
open class SellTariff: Codable {
open var name: String
open var utility: String
open var energyCharges: [String: EnergyChargeRates]
open var seasons: [String: Season]

enum CodingKeys: String, CodingKey {
case name
case utility
case energyCharges = "energy_charges"
case seasons
}
}
// MARK: - UserSettings
open class UserSettings: Codable {
open var stormModeEnabled: Bool?
open var syncGridAlertEnabled: Bool
open var breakerAlertEnabled: Bool
open var vppTourEnabled: Bool?
open var goOffGridTestBannerEnabled: Bool?
open var powerwallOnboardingSettingsSet: Bool?
open var powerwallTeslaElectricInterestedIn: Bool?

enum CodingKeys: String, CodingKey {
case stormModeEnabled = "storm_mode_enabled"
case syncGridAlertEnabled = "sync_grid_alert_enabled"
case breakerAlertEnabled = "breaker_alert_enabled"
case vppTourEnabled = "vpp_tour_enabled"
case goOffGridTestBannerEnabled = "go_off_grid_test_banner_enabled"
case powerwallOnboardingSettingsSet = "powerwall_onboarding_settings_set"
case powerwallTeslaElectricInterestedIn = "powerwall_tesla_electric_interested_in"
}
}
}