const.py 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. """Constants for the Solar of Things integration."""
  2. DOMAIN = "solar_of_things"
  3. # ─── Configuration keys ────────────────────────────────────────────────────────
  4. CONF_IOT_TOKEN = "iot_token" # legacy / advanced manual entry
  5. CONF_STATION_ID = "station_id"
  6. CONF_DEVICE_ID = "device_id"
  7. CONF_TIME_ZONE = "time_zone"
  8. # Credential-based auth (preferred)
  9. CONF_USER_ID = "user_id" # Siseli account / user-ID login (not email)
  10. CONF_PASSWORD = "password"
  11. # Runtime-stored token state (written back to config entry)
  12. CONF_REFRESH_TOKEN = "refresh_token"
  13. CONF_ACCESS_TOKEN_EXPIRES = "access_token_expires" # ISO-8601 string
  14. CONF_REFRESH_TOKEN_EXPIRES = "refresh_token_expires" # ISO-8601 string
  15. # ─── API bases ─────────────────────────────────────────────────────────────────
  16. # Both auth and data endpoints live on the production server solar.siseli.com.
  17. # The portal JS bundle embeds both test/prod AppIDs; AppID rBrTRfAPXz is the
  18. # one accepted by solar.siseli.com (confirmed by live API testing 2026-03-07).
  19. API_BASE_URL = "https://solar.siseli.com" # data endpoints
  20. API_AUTH_BASE_URL = "https://solar.siseli.com" # auth / login endpoints
  21. # ─── Auth endpoints (discovered from portal JS bundle) ─────────────────────────
  22. # The login endpoint requires IOT-Open-AppID signing (see api.py _sign_request).
  23. API_LOGIN = "/apis/login/account" # POST + signed headers
  24. API_REFRESH_TOKEN = "/login/refresh/access/token" # POST, no token needed
  25. # ─── IOT Open Platform app credentials (embedded in portal umi.js) ────────────
  26. # rBrTRfAPXz is the production AppID accepted by solar.siseli.com.
  27. # JO4DAiNeys is the test AppID (accepted only by test.solar.siseli.com).
  28. IOT_APP_ID = "rBrTRfAPXz"
  29. IOT_APP_SECRET_ENC = "I4D0KRr2339z3pQ/at91V9BpFAOe54DaTafwSm6suIQ="
  30. # ─── Data endpoints ────────────────────────────────────────────────────────────
  31. API_TIME_SERIES = "/apis/deviceState/simple/attribute/keys/history/v1"
  32. API_MONTHLY_SUMMARY = "/apis/stationOverView/stateAttributeSummary/category/yearly"
  33. API_SETTINGS_GET = "/api/device/settings/v1"
  34. API_SETTINGS_SET = "/api/device/settings/update/v1"
  35. API_DEVICE_LIST = "/apis/device/list"
  36. # ─── Token refresh window ──────────────────────────────────────────────────────
  37. # Refresh the access token this many seconds *before* its stated expiry.
  38. # Mirrors the portal JS which refreshes when ≤300 s remain.
  39. TOKEN_REFRESH_LEAD_SECONDS = 300 # 5 minutes
  40. # ─── Sensor keys ───────────────────────────────────────────────────────────────
  41. SENSOR_KEYS = [
  42. "pvInputPower",
  43. "acOutputActivePower",
  44. "batteryDischargeCurrent",
  45. "batteryChargingCurrent",
  46. "batteryVoltage",
  47. "feedInPower",
  48. "batteryPower",
  49. "batterySOC",
  50. "gridPower",
  51. "loadPower",
  52. ]
  53. SENSOR_DEFINITIONS = {
  54. "pvInputPower": {
  55. "name": "PV Input Power",
  56. "unit": "W",
  57. "device_class": "power",
  58. "icon": "mdi:solar-power",
  59. },
  60. "acOutputActivePower": {
  61. "name": "AC Output Power",
  62. "unit": "W",
  63. "device_class": "power",
  64. "icon": "mdi:power-plug",
  65. },
  66. "batteryDischargeCurrent": {
  67. "name": "Battery Discharge Current",
  68. "unit": "A",
  69. "device_class": "current",
  70. "icon": "mdi:battery-arrow-down",
  71. },
  72. "batteryChargingCurrent": {
  73. "name": "Battery Charging Current",
  74. "unit": "A",
  75. "device_class": "current",
  76. "icon": "mdi:battery-arrow-up",
  77. },
  78. "batteryVoltage": {
  79. "name": "Battery Voltage",
  80. "unit": "V",
  81. "device_class": "voltage",
  82. "icon": "mdi:battery",
  83. },
  84. "batteryPower": {
  85. "name": "Battery Power",
  86. "unit": "W",
  87. "device_class": "power",
  88. "icon": "mdi:battery-charging",
  89. },
  90. "batterySOC": {
  91. "name": "Battery State of Charge",
  92. "unit": "%",
  93. "device_class": "battery",
  94. "icon": "mdi:battery",
  95. },
  96. "feedInPower": {
  97. "name": "Grid Feed-in Power",
  98. "unit": "W",
  99. "device_class": "power",
  100. "icon": "mdi:transmission-tower-export",
  101. },
  102. "gridPower": {
  103. "name": "Grid Import Power",
  104. "unit": "W",
  105. "device_class": "power",
  106. "icon": "mdi:transmission-tower-import",
  107. },
  108. "loadPower": {
  109. "name": "Load Power",
  110. "unit": "W",
  111. "device_class": "power",
  112. "icon": "mdi:home-lightning-bolt",
  113. },
  114. # Monthly summary sensors
  115. "monthly_pv_generated": {
  116. "name": "Monthly PV Generated",
  117. "unit": "kWh",
  118. "device_class": "energy",
  119. "icon": "mdi:solar-power",
  120. },
  121. "monthly_grid_import": {
  122. "name": "Monthly Grid Import",
  123. "unit": "kWh",
  124. "device_class": "energy",
  125. "icon": "mdi:transmission-tower-import",
  126. },
  127. "monthly_total_consumption": {
  128. "name": "Monthly Total Consumption",
  129. "unit": "kWh",
  130. "device_class": "energy",
  131. "icon": "mdi:home-lightning-bolt",
  132. },
  133. "monthly_solar_percentage": {
  134. "name": "Monthly Solar Coverage",
  135. "unit": "%",
  136. "icon": "mdi:percent",
  137. },
  138. }