Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
21 changes: 20 additions & 1 deletion homeassistant/components/kostal_plenticore/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
from homeassistant.helpers.update_coordinator import CoordinatorEntity

from .const import CONF_SERVICE_CODE, DOMAIN
from .coordinator import PlenticoreConfigEntry, SettingDataUpdateCoordinator

_LOGGER = logging.getLogger(__name__)
Expand All @@ -29,6 +30,7 @@ class PlenticoreSwitchEntityDescription(SwitchEntityDescription):
on_label: str
off_value: str
off_label: str
installer_required: bool = False


SWITCH_SETTINGS_DATA = [
Expand All @@ -42,6 +44,17 @@ class PlenticoreSwitchEntityDescription(SwitchEntityDescription):
off_value="2",
off_label="Automatic economical",
),
PlenticoreSwitchEntityDescription(
module_id="devices:local",
key="Battery:ManualCharge",
name="Battery Manual Charge",
is_on="1",
on_value="1",
on_label="On",
off_value="0",
off_label="Off",
installer_required=True,
),
]


Expand Down Expand Up @@ -73,7 +86,13 @@ async def async_setup_entry(
description.key,
)
continue

if entry.data.get(CONF_SERVICE_CODE) is None and description.installer_required:
_LOGGER.debug(
"Skipping installer required setting data %s/%s",
description.module_id,
description.key,
)
continue
entities.append(
PlenticoreDataSwitch(
settings_data_update_coordinator,
Expand Down
15 changes: 15 additions & 0 deletions tests/components/kostal_plenticore/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,21 @@ def mock_config_entry() -> MockConfigEntry:
)


@pytest.fixture
def mock_installer_config_entry() -> MockConfigEntry:
"""Return a mocked ConfigEntry for testing with installer login."""
return MockConfigEntry(
entry_id="2ab8dd92a62787ddfe213a67e09406bd",
title="scb",
domain="kostal_plenticore",
data={
"host": "192.168.1.2",
"password": "secret_password",
"service_code": "12345",
},
)


@pytest.fixture
def mock_plenticore() -> Generator[Plenticore]:
"""Set up a Plenticore mock with some default values."""
Expand Down
69 changes: 69 additions & 0 deletions tests/components/kostal_plenticore/test_switch.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
"""Test the Kostal Plenticore Solar Inverter switch platform."""

from pykoplenti import SettingsData

from homeassistant.components.kostal_plenticore.coordinator import Plenticore
from homeassistant.core import HomeAssistant
from homeassistant.helpers import entity_registry as er

from tests.common import MockConfigEntry


async def test_installer_setting_not_available(
hass: HomeAssistant,
mock_plenticore: Plenticore,
mock_config_entry: MockConfigEntry,
entity_registry: er.EntityRegistry,
) -> None:
"""Test that the manual charge setting is not available when not using the installer login."""

mock_plenticore.client.get_settings.return_value = {
"devices:local": [
SettingsData(
min=None,
max=None,
default=None,
access="readwrite",
unit=None,
id="Battery:ManualCharge",
type="bool",
)
]
}

mock_config_entry.add_to_hass(hass)

await hass.config_entries.async_setup(mock_config_entry.entry_id)
await hass.async_block_till_done()

assert not entity_registry.async_is_registered("switch.scb_battery_manual_charge")


async def test_installer_setting_available(
hass: HomeAssistant,
mock_plenticore: Plenticore,
mock_installer_config_entry: MockConfigEntry,
entity_registry: er.EntityRegistry,
) -> None:
"""Test that the manual charge setting is available when using the installer login."""

mock_plenticore.client.get_settings.return_value = {
"devices:local": [
SettingsData(
min=None,
max=None,
default=None,
access="readwrite",
unit=None,
id="Battery:ManualCharge",
type="bool",
)
]
}

mock_installer_config_entry.add_to_hass(hass)

await hass.config_entries.async_setup(mock_installer_config_entry.entry_id)
await hass.async_block_till_done()

assert entity_registry.async_is_registered("switch.scb_battery_manual_charge")
Loading