mirror of
https://github.com/home-assistant/core.git
synced 2025-07-14 16:57:10 +00:00
Add Manual Charge Switch for Installers for Kostal Plenticore (#146932)
* Add Manual Charge Switch for Installers * Update stale docstring * Installer config fixture * fix ruff
This commit is contained in:
parent
35478e3162
commit
bf88fcd5bf
@ -14,6 +14,7 @@ from homeassistant.helpers.device_registry import DeviceInfo
|
|||||||
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
||||||
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||||
|
|
||||||
|
from .const import CONF_SERVICE_CODE
|
||||||
from .coordinator import PlenticoreConfigEntry, SettingDataUpdateCoordinator
|
from .coordinator import PlenticoreConfigEntry, SettingDataUpdateCoordinator
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
@ -29,6 +30,7 @@ class PlenticoreSwitchEntityDescription(SwitchEntityDescription):
|
|||||||
on_label: str
|
on_label: str
|
||||||
off_value: str
|
off_value: str
|
||||||
off_label: str
|
off_label: str
|
||||||
|
installer_required: bool = False
|
||||||
|
|
||||||
|
|
||||||
SWITCH_SETTINGS_DATA = [
|
SWITCH_SETTINGS_DATA = [
|
||||||
@ -42,6 +44,17 @@ SWITCH_SETTINGS_DATA = [
|
|||||||
off_value="2",
|
off_value="2",
|
||||||
off_label="Automatic economical",
|
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,
|
||||||
|
),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
@ -73,7 +86,13 @@ async def async_setup_entry(
|
|||||||
description.key,
|
description.key,
|
||||||
)
|
)
|
||||||
continue
|
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(
|
entities.append(
|
||||||
PlenticoreDataSwitch(
|
PlenticoreDataSwitch(
|
||||||
settings_data_update_coordinator,
|
settings_data_update_coordinator,
|
||||||
|
@ -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
|
@pytest.fixture
|
||||||
def mock_plenticore() -> Generator[Plenticore]:
|
def mock_plenticore() -> Generator[Plenticore]:
|
||||||
"""Set up a Plenticore mock with some default values."""
|
"""Set up a Plenticore mock with some default values."""
|
||||||
|
69
tests/components/kostal_plenticore/test_switch.py
Normal file
69
tests/components/kostal_plenticore/test_switch.py
Normal file
@ -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…
x
Reference in New Issue
Block a user