Skip to content

Commit bf88fcd

Browse files
authored
Add Manual Charge Switch for Installers for Kostal Plenticore (#146932)
* Add Manual Charge Switch for Installers * Update stale docstring * Installer config fixture * fix ruff
1 parent 35478e3 commit bf88fcd

File tree

3 files changed

+104
-1
lines changed

3 files changed

+104
-1
lines changed

homeassistant/components/kostal_plenticore/switch.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
1515
from homeassistant.helpers.update_coordinator import CoordinatorEntity
1616

17+
from .const import CONF_SERVICE_CODE
1718
from .coordinator import PlenticoreConfigEntry, SettingDataUpdateCoordinator
1819

1920
_LOGGER = logging.getLogger(__name__)
@@ -29,6 +30,7 @@ class PlenticoreSwitchEntityDescription(SwitchEntityDescription):
2930
on_label: str
3031
off_value: str
3132
off_label: str
33+
installer_required: bool = False
3234

3335

3436
SWITCH_SETTINGS_DATA = [
@@ -42,6 +44,17 @@ class PlenticoreSwitchEntityDescription(SwitchEntityDescription):
4244
off_value="2",
4345
off_label="Automatic economical",
4446
),
47+
PlenticoreSwitchEntityDescription(
48+
module_id="devices:local",
49+
key="Battery:ManualCharge",
50+
name="Battery Manual Charge",
51+
is_on="1",
52+
on_value="1",
53+
on_label="On",
54+
off_value="0",
55+
off_label="Off",
56+
installer_required=True,
57+
),
4558
]
4659

4760

@@ -73,7 +86,13 @@ async def async_setup_entry(
7386
description.key,
7487
)
7588
continue
76-
89+
if entry.data.get(CONF_SERVICE_CODE) is None and description.installer_required:
90+
_LOGGER.debug(
91+
"Skipping installer required setting data %s/%s",
92+
description.module_id,
93+
description.key,
94+
)
95+
continue
7796
entities.append(
7897
PlenticoreDataSwitch(
7998
settings_data_update_coordinator,

tests/components/kostal_plenticore/conftest.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,21 @@ def mock_config_entry() -> MockConfigEntry:
2626
)
2727

2828

29+
@pytest.fixture
30+
def mock_installer_config_entry() -> MockConfigEntry:
31+
"""Return a mocked ConfigEntry for testing with installer login."""
32+
return MockConfigEntry(
33+
entry_id="2ab8dd92a62787ddfe213a67e09406bd",
34+
title="scb",
35+
domain="kostal_plenticore",
36+
data={
37+
"host": "192.168.1.2",
38+
"password": "secret_password",
39+
"service_code": "12345",
40+
},
41+
)
42+
43+
2944
@pytest.fixture
3045
def mock_plenticore() -> Generator[Plenticore]:
3146
"""Set up a Plenticore mock with some default values."""
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
"""Test the Kostal Plenticore Solar Inverter switch platform."""
2+
3+
from pykoplenti import SettingsData
4+
5+
from homeassistant.components.kostal_plenticore.coordinator import Plenticore
6+
from homeassistant.core import HomeAssistant
7+
from homeassistant.helpers import entity_registry as er
8+
9+
from tests.common import MockConfigEntry
10+
11+
12+
async def test_installer_setting_not_available(
13+
hass: HomeAssistant,
14+
mock_plenticore: Plenticore,
15+
mock_config_entry: MockConfigEntry,
16+
entity_registry: er.EntityRegistry,
17+
) -> None:
18+
"""Test that the manual charge setting is not available when not using the installer login."""
19+
20+
mock_plenticore.client.get_settings.return_value = {
21+
"devices:local": [
22+
SettingsData(
23+
min=None,
24+
max=None,
25+
default=None,
26+
access="readwrite",
27+
unit=None,
28+
id="Battery:ManualCharge",
29+
type="bool",
30+
)
31+
]
32+
}
33+
34+
mock_config_entry.add_to_hass(hass)
35+
36+
await hass.config_entries.async_setup(mock_config_entry.entry_id)
37+
await hass.async_block_till_done()
38+
39+
assert not entity_registry.async_is_registered("switch.scb_battery_manual_charge")
40+
41+
42+
async def test_installer_setting_available(
43+
hass: HomeAssistant,
44+
mock_plenticore: Plenticore,
45+
mock_installer_config_entry: MockConfigEntry,
46+
entity_registry: er.EntityRegistry,
47+
) -> None:
48+
"""Test that the manual charge setting is available when using the installer login."""
49+
50+
mock_plenticore.client.get_settings.return_value = {
51+
"devices:local": [
52+
SettingsData(
53+
min=None,
54+
max=None,
55+
default=None,
56+
access="readwrite",
57+
unit=None,
58+
id="Battery:ManualCharge",
59+
type="bool",
60+
)
61+
]
62+
}
63+
64+
mock_installer_config_entry.add_to_hass(hass)
65+
66+
await hass.config_entries.async_setup(mock_installer_config_entry.entry_id)
67+
await hass.async_block_till_done()
68+
69+
assert entity_registry.async_is_registered("switch.scb_battery_manual_charge")

0 commit comments

Comments
 (0)