const.py 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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. # Remote device config endpoints (discovered 2026-03-07 from live API testing).
  34. # These accept a plain IOT-Token header (no IOT-Open-Sign) and use the device ID
  35. # as a query parameter. Write sends one setting key+value per call.
  36. API_SETTINGS_GET = "/apis/remote/device/configs/cache/get" # ?deviceId=<id>
  37. API_SETTINGS_SET = "/apis/remote/device/config/write" # ?deviceId=<id>
  38. API_DEVICE_LIST = "/apis/device/list"
  39. # ─── Token refresh window ──────────────────────────────────────────────────────
  40. # Refresh the access token this many seconds *before* its stated expiry.
  41. # Mirrors the portal JS which refreshes when ≤300 s remain.
  42. TOKEN_REFRESH_LEAD_SECONDS = 300 # 5 minutes
  43. # ─── Sensor keys ───────────────────────────────────────────────────────────────
  44. SENSOR_KEYS = [
  45. "pvInputPower",
  46. "acOutputActivePower",
  47. "batteryDischargeCurrent",
  48. "batteryChargingCurrent",
  49. "batteryVoltage",
  50. "feedInPower",
  51. "batteryPower",
  52. "batterySOC",
  53. "gridPower",
  54. "loadPower",
  55. ]
  56. SENSOR_DEFINITIONS = {
  57. "pvInputPower": {
  58. "name": "PV Input Power",
  59. "unit": "W",
  60. "device_class": "power",
  61. "icon": "mdi:solar-power",
  62. },
  63. "acOutputActivePower": {
  64. "name": "AC Output Power",
  65. "unit": "W",
  66. "device_class": "power",
  67. "icon": "mdi:power-plug",
  68. },
  69. "batteryDischargeCurrent": {
  70. "name": "Battery Discharge Current",
  71. "unit": "A",
  72. "device_class": "current",
  73. "icon": "mdi:battery-arrow-down",
  74. },
  75. "batteryChargingCurrent": {
  76. "name": "Battery Charging Current",
  77. "unit": "A",
  78. "device_class": "current",
  79. "icon": "mdi:battery-arrow-up",
  80. },
  81. "batteryVoltage": {
  82. "name": "Battery Voltage",
  83. "unit": "V",
  84. "device_class": "voltage",
  85. "icon": "mdi:battery",
  86. },
  87. "batteryPower": {
  88. "name": "Battery Power",
  89. "unit": "W",
  90. "device_class": "power",
  91. "icon": "mdi:battery-charging",
  92. },
  93. "batterySOC": {
  94. "name": "Battery State of Charge",
  95. "unit": "%",
  96. "device_class": "battery",
  97. "icon": "mdi:battery",
  98. },
  99. "feedInPower": {
  100. "name": "Grid Feed-in Power",
  101. "unit": "W",
  102. "device_class": "power",
  103. "icon": "mdi:transmission-tower-export",
  104. },
  105. "gridPower": {
  106. "name": "Grid Import Power",
  107. "unit": "W",
  108. "device_class": "power",
  109. "icon": "mdi:transmission-tower-import",
  110. },
  111. "loadPower": {
  112. "name": "Load Power",
  113. "unit": "W",
  114. "device_class": "power",
  115. "icon": "mdi:home-lightning-bolt",
  116. },
  117. # Monthly summary sensors
  118. "monthly_pv_generated": {
  119. "name": "Monthly PV Generated",
  120. "unit": "kWh",
  121. "device_class": "energy",
  122. "icon": "mdi:solar-power",
  123. },
  124. "monthly_grid_import": {
  125. "name": "Monthly Grid Import",
  126. "unit": "kWh",
  127. "device_class": "energy",
  128. "icon": "mdi:transmission-tower-import",
  129. },
  130. "monthly_total_consumption": {
  131. "name": "Monthly Total Consumption",
  132. "unit": "kWh",
  133. "device_class": "energy",
  134. "icon": "mdi:home-lightning-bolt",
  135. },
  136. "monthly_solar_percentage": {
  137. "name": "Monthly Solar Coverage",
  138. "unit": "%",
  139. "icon": "mdi:percent",
  140. },
  141. }