const.py 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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. # The portal JS bundle uses test.solar.siseli.com for auth/login endpoints
  17. # and solar.siseli.com for data (device-state, station) endpoints.
  18. API_BASE_URL = "https://solar.siseli.com" # data endpoints
  19. API_AUTH_BASE_URL = "https://test.solar.siseli.com" # auth / login endpoints
  20. # ─── Auth endpoints (discovered from portal JS bundle) ─────────────────────────
  21. # The login endpoint requires IOT-Open-AppID signing (see api.py _sign_request).
  22. API_LOGIN = "/apis/login/account" # POST + signed headers
  23. API_REFRESH_TOKEN = "/login/refresh/access/token" # POST, no token needed
  24. # ─── IOT Open Platform app credentials (embedded in portal umi.js) ────────────
  25. IOT_APP_ID = "JO4DAiNeys"
  26. IOT_APP_SECRET_ENC = "VK51roUwyT4CJGcDWRp17WMhzX4F702I10fWc0FnC6A="
  27. # ─── Data endpoints ────────────────────────────────────────────────────────────
  28. API_TIME_SERIES = "/apis/deviceState/simple/attribute/keys/history/v1"
  29. API_MONTHLY_SUMMARY = "/apis/stationOverView/stateAttributeSummary/category/yearly"
  30. API_SETTINGS_GET = "/api/device/settings/v1"
  31. API_SETTINGS_SET = "/api/device/settings/update/v1"
  32. API_DEVICE_LIST = "/apis/device/list"
  33. # ─── Token refresh window ──────────────────────────────────────────────────────
  34. # Refresh the access token this many seconds *before* its stated expiry.
  35. # Mirrors the portal JS which refreshes when ≤300 s remain.
  36. TOKEN_REFRESH_LEAD_SECONDS = 300 # 5 minutes
  37. # ─── Sensor keys ───────────────────────────────────────────────────────────────
  38. SENSOR_KEYS = [
  39. "pvInputPower",
  40. "acOutputActivePower",
  41. "batteryDischargeCurrent",
  42. "batteryChargingCurrent",
  43. "batteryVoltage",
  44. "feedInPower",
  45. "batteryPower",
  46. "batterySOC",
  47. "gridPower",
  48. "loadPower",
  49. ]
  50. SENSOR_DEFINITIONS = {
  51. "pvInputPower": {
  52. "name": "PV Input Power",
  53. "unit": "W",
  54. "device_class": "power",
  55. "icon": "mdi:solar-power",
  56. },
  57. "acOutputActivePower": {
  58. "name": "AC Output Power",
  59. "unit": "W",
  60. "device_class": "power",
  61. "icon": "mdi:power-plug",
  62. },
  63. "batteryDischargeCurrent": {
  64. "name": "Battery Discharge Current",
  65. "unit": "A",
  66. "device_class": "current",
  67. "icon": "mdi:battery-arrow-down",
  68. },
  69. "batteryChargingCurrent": {
  70. "name": "Battery Charging Current",
  71. "unit": "A",
  72. "device_class": "current",
  73. "icon": "mdi:battery-arrow-up",
  74. },
  75. "batteryVoltage": {
  76. "name": "Battery Voltage",
  77. "unit": "V",
  78. "device_class": "voltage",
  79. "icon": "mdi:battery",
  80. },
  81. "batteryPower": {
  82. "name": "Battery Power",
  83. "unit": "W",
  84. "device_class": "power",
  85. "icon": "mdi:battery-charging",
  86. },
  87. "batterySOC": {
  88. "name": "Battery State of Charge",
  89. "unit": "%",
  90. "device_class": "battery",
  91. "icon": "mdi:battery",
  92. },
  93. "feedInPower": {
  94. "name": "Grid Feed-in Power",
  95. "unit": "W",
  96. "device_class": "power",
  97. "icon": "mdi:transmission-tower-export",
  98. },
  99. "gridPower": {
  100. "name": "Grid Import Power",
  101. "unit": "W",
  102. "device_class": "power",
  103. "icon": "mdi:transmission-tower-import",
  104. },
  105. "loadPower": {
  106. "name": "Load Power",
  107. "unit": "W",
  108. "device_class": "power",
  109. "icon": "mdi:home-lightning-bolt",
  110. },
  111. # Monthly summary sensors
  112. "monthly_pv_generated": {
  113. "name": "Monthly PV Generated",
  114. "unit": "kWh",
  115. "device_class": "energy",
  116. "icon": "mdi:solar-power",
  117. },
  118. "monthly_grid_import": {
  119. "name": "Monthly Grid Import",
  120. "unit": "kWh",
  121. "device_class": "energy",
  122. "icon": "mdi:transmission-tower-import",
  123. },
  124. "monthly_total_consumption": {
  125. "name": "Monthly Total Consumption",
  126. "unit": "kWh",
  127. "device_class": "energy",
  128. "icon": "mdi:home-lightning-bolt",
  129. },
  130. "monthly_solar_percentage": {
  131. "name": "Monthly Solar Coverage",
  132. "unit": "%",
  133. "icon": "mdi:percent",
  134. },
  135. }