Skip to content
Open
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions custom_components/solix_ble/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
F2000,
F3800,
Generic,
MagGo3in1,
PrimeCharger160w,
PrimeCharger250w,
PrimePowerBank20k,
Expand Down Expand Up @@ -56,6 +57,8 @@ def get_power_station_class(model: Models) -> SolixBLEDevice:
return PrimeCharger250w
elif model is Models.PRIME_POWER_BANK_20K:
return PrimePowerBank20k
elif model is Models.MAGGO_3IN1:
return MagGo3in1
elif model is Models.SOLARBANK_2:
return Solarbank2
elif model is Models.UNKNOWN:
Expand Down
1 change: 1 addition & 0 deletions custom_components/solix_ble/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,5 @@ class Models(Enum):
PRIME_CHARGER_250 = "Prime Charger (250w)"
PRIME_POWER_BANK_20K = "Prime Power Bank 20k (220w)"
SOLARBANK_2 = "Solarbank 2"
MAGGO_3IN1 = "MagGo 3-in-1 Wireless Charger (A25x7)"
UNKNOWN = "Unknown"
26 changes: 26 additions & 0 deletions custom_components/solix_ble/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
C1000G2,
F2000,
F3800,
MagGo3in1,
PrimeCharger160w,
PrimeCharger250w,
PrimePowerBank20k,
Expand Down Expand Up @@ -259,6 +260,7 @@ async def async_setup_entry(
F3800,
Solarbank2,
PrimePowerBank20k,
MagGo3in1,
]:
sensors.append(
SolixSensorEntity(
Expand Down Expand Up @@ -1121,6 +1123,30 @@ async def async_setup_entry(
)
)

# Wireless charging pad 1 power out
if type(device) in [MagGo3in1]:

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

These need to be individual so that devices which might have just 1 wireless charging pad can make use of this code by just adding them to the list for that sensor.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Done — split into three separate per-pad blocks, each gated on its own if type(device) in [MagGo3in1]: list, so a future single-pad device can be added to just the relevant pad's sensor.

sensors.append(
SolixSensorEntity(
device, "Pad 1 Power", "W", "pad_1_power", SensorDeviceClass.POWER
)
)

# Wireless charging pad 2 power out
if type(device) in [MagGo3in1]:
sensors.append(
SolixSensorEntity(
device, "Pad 2 Power", "W", "pad_2_power", SensorDeviceClass.POWER
)
)

# Wireless charging pad 3 power out
if type(device) in [MagGo3in1]:
sensors.append(
SolixSensorEntity(
device, "Pad 3 Power", "W", "pad_3_power", SensorDeviceClass.POWER
)
)

async_add_entities(sensors)


Expand Down
17 changes: 17 additions & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,13 @@ def get_service_info(self) -> BluetoothServiceInfoBleak:
model_class=Models.PRIME_POWER_BANK_20K,
)

MOCK_MAGGO_3IN1_DETAILS = MockDeviceDetails(
name="Anker MagGo 3 in 1 Charger",
addr="AA:BB:CC:DD:00:06",
model_string="MagGo 3-in-1 Wireless Charger (A25x7)",
model_class=Models.MAGGO_3IN1,
)

MOCK_SOLAR_BANK_2_DETAILS = MockDeviceDetails(
name="Solar Bank 2",
addr="AA:BB:CC:DD:00:02",
Expand Down Expand Up @@ -379,6 +386,16 @@ def get_service_info(self) -> BluetoothServiceInfoBleak:
"usb_port_a1": ("status_usb_a1", PortStatus.OUTPUT),
}

# Sometimes the method name we are patching and the
# entity ID do not line up, so a tuple is used to
# manually specify it
MOCK_MAGGO_3IN1_TEST_DATA = {
"pad_1_power": 5.0,
"pad_2_power": 0.0,
"pad_3_power": 7.5,
"power_out": ("total_power_out", 12.5),
}


# Sometimes the method name we are patching and the
# entity ID do not line up, so a tuple is used to
Expand Down
3 changes: 3 additions & 0 deletions tests/test_config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
MOCK_C1000X_DETAILS,
MOCK_F2000_DETAILS,
MOCK_F3800_DETAILS,
MOCK_MAGGO_3IN1_DETAILS,
MOCK_PRIME_160_DETAILS,
MOCK_PRIME_250_DETAILS,
MOCK_PRIME_POWER_BANK_20K_DETAILS,
Expand All @@ -48,6 +49,7 @@
MOCK_PRIME_160_DETAILS,
MOCK_PRIME_250_DETAILS,
MOCK_PRIME_POWER_BANK_20K_DETAILS,
MOCK_MAGGO_3IN1_DETAILS,
MOCK_SOLAR_BANK_2_DETAILS,
MOCK_UNKNOWN_DETAILS,
],
Expand All @@ -64,6 +66,7 @@
"prime_160w",
"prime_250w",
"prime_power_bank_20k",
"maggo_3in1",
"solar_bank_2",
"unknown",
],
Expand Down
4 changes: 4 additions & 0 deletions tests/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
MOCK_C1000X_DETAILS,
MOCK_F2000_DETAILS,
MOCK_F3800_DETAILS,
MOCK_MAGGO_3IN1_DETAILS,
MOCK_PRIME_160_DETAILS,
MOCK_PRIME_250_DETAILS,
MOCK_PRIME_POWER_BANK_20K_DETAILS,
Expand All @@ -49,6 +50,9 @@
pytest.param(MOCK_PRIME_160_DETAILS, MOCK_PRIME_160_DETAILS, id="prime_160w"),
pytest.param(MOCK_PRIME_250_DETAILS, MOCK_PRIME_250_DETAILS, id="prime_250w"),
pytest.param(MOCK_PRIME_POWER_BANK_20K_DETAILS, MOCK_PRIME_POWER_BANK_20K_DETAILS, id="prime_power_bank_20k"),
pytest.param(
MOCK_MAGGO_3IN1_DETAILS, MOCK_MAGGO_3IN1_DETAILS, id="maggo_3in1"
),
pytest.param(
MOCK_SOLAR_BANK_2_DETAILS, MOCK_SOLAR_BANK_2_DETAILS, id="solar_bank_2"
),
Expand Down
9 changes: 9 additions & 0 deletions tests/test_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
MOCK_C1000G2_DETAILS,
MOCK_F2000_DETAILS,
MOCK_F3800_DETAILS,
MOCK_MAGGO_3IN1_DETAILS,
MOCK_MAGGO_3IN1_TEST_DATA,
MOCK_PRIME_160_DETAILS,
MOCK_PRIME_160_TEST_DATA,
MOCK_PRIME_250_DETAILS,
Expand Down Expand Up @@ -105,6 +107,13 @@
MOCK_PRIME_POWER_BANK_20K_TEST_DATA,
id="prime_power_bank_20k",
),
pytest.param(
MOCK_MAGGO_3IN1_DETAILS,
MOCK_MAGGO_3IN1_DETAILS,
"MagGo3in1",
MOCK_MAGGO_3IN1_TEST_DATA,
id="maggo_3in1",
),
pytest.param(
MOCK_SOLAR_BANK_2_DETAILS,
MOCK_SOLAR_BANK_2_DETAILS,
Expand Down