|
| 1 | +from typing import Any, Dict, Optional |
| 2 | + |
| 3 | +import voluptuous as vol |
| 4 | + |
| 5 | +from solax.inverter import Inverter |
| 6 | +from solax.units import DailyTotal, Total, Units |
| 7 | +from solax.utils import div10, div100, pack_u16, to_signed |
| 8 | + |
| 9 | + |
| 10 | +class X1BoostG4(Inverter): |
| 11 | + """ |
| 12 | + X1-Boost gen 4 with Pocket WiFi 3.009.03 |
| 13 | + Includes X-Forwarded-For for direct LAN API access |
| 14 | + """ |
| 15 | + |
| 16 | + # pylint: disable=duplicate-code |
| 17 | + _schema = vol.Schema( |
| 18 | + { |
| 19 | + vol.Required("type", "type"): vol.All(int, 18), |
| 20 | + vol.Required( |
| 21 | + "sn", |
| 22 | + ): str, |
| 23 | + vol.Required("ver"): str, |
| 24 | + vol.Required("data"): vol.Schema( |
| 25 | + vol.All([vol.Coerce(float)], vol.Length(min=100, max=100)) |
| 26 | + ), |
| 27 | + vol.Required("information"): vol.Schema( |
| 28 | + vol.All(vol.Length(min=10, max=10)) |
| 29 | + ), |
| 30 | + }, |
| 31 | + extra=vol.REMOVE_EXTRA, |
| 32 | + ) |
| 33 | + |
| 34 | + @classmethod |
| 35 | + def response_decoder(cls): |
| 36 | + return { |
| 37 | + "AC Voltage": (0, Units.V, div10), |
| 38 | + "AC Output Current": (1, Units.A, div10), |
| 39 | + "AC Output Power": (3, Units.W), |
| 40 | + "PV1 Voltage": (4, Units.V, div10), |
| 41 | + "PV2 Voltage": (5, Units.V, div10), |
| 42 | + "PV1 Current": (8, Units.A, div10), |
| 43 | + "PV2 Current": (9, Units.A, div10), |
| 44 | + "PV1 Power": (13, Units.W), |
| 45 | + "PV2 Power": (14, Units.W), |
| 46 | + "AC Frequency": (2, Units.HZ, div100), |
| 47 | + "Total Generated Energy": (pack_u16(19, 20), Total(Units.KWH), div10), |
| 48 | + "Today's Generated Energy": (21, DailyTotal(Units.KWH), div10), |
| 49 | + "Exported Power": (pack_u16(72, 73), Units.W, to_signed), |
| 50 | + "Total Export Energy": (pack_u16(74, 75), Total(Units.KWH), div100), |
| 51 | + "Total Import Energy": (pack_u16(76, 77), Total(Units.KWH), div100), |
| 52 | + } |
| 53 | + |
| 54 | + @classmethod |
| 55 | + def inverter_serial_number_getter(cls, response: Dict[str, Any]) -> Optional[str]: |
| 56 | + return response["information"][2] |
| 57 | + |
| 58 | + @classmethod |
| 59 | + def build_all_variants(cls, host, port, pwd=""): |
| 60 | + versions = [ |
| 61 | + cls._build(host, port, pwd, True), |
| 62 | + cls._build(host, port, pwd, False), |
| 63 | + ] |
| 64 | + for inverter in versions: |
| 65 | + inverter.http_client = inverter.http_client.with_headers( |
| 66 | + {"X-Forwarded-For": "5.8.8.8"} |
| 67 | + ) |
| 68 | + return versions |
0 commit comments