mirror of
https://github.com/home-assistant/core.git
synced 2025-07-24 21:57:51 +00:00
Remove CONF_NAME from config entry in solarlog (#131738)
* Remove CONF_NAME from config entry * Remove name from strings.json
This commit is contained in:
parent
5458ee2fa9
commit
4eb5734d73
@ -1,7 +1,6 @@
|
|||||||
"""Config flow for solarlog integration."""
|
"""Config flow for solarlog integration."""
|
||||||
|
|
||||||
from collections.abc import Mapping
|
from collections.abc import Mapping
|
||||||
import logging
|
|
||||||
from typing import Any
|
from typing import Any
|
||||||
from urllib.parse import ParseResult, urlparse
|
from urllib.parse import ParseResult, urlparse
|
||||||
|
|
||||||
@ -14,12 +13,9 @@ from solarlog_cli.solarlog_exceptions import (
|
|||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.config_entries import ConfigFlow, ConfigFlowResult
|
from homeassistant.config_entries import ConfigFlow, ConfigFlowResult
|
||||||
from homeassistant.const import CONF_HOST, CONF_NAME, CONF_PASSWORD
|
from homeassistant.const import CONF_HOST, CONF_PASSWORD
|
||||||
from homeassistant.util import slugify
|
|
||||||
|
|
||||||
from .const import CONF_HAS_PWD, DEFAULT_HOST, DEFAULT_NAME, DOMAIN
|
from .const import CONF_HAS_PWD, DEFAULT_HOST, DOMAIN
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
|
||||||
|
|
||||||
|
|
||||||
class SolarLogConfigFlow(ConfigFlow, domain=DOMAIN):
|
class SolarLogConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||||
@ -84,24 +80,21 @@ class SolarLogConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||||||
|
|
||||||
self._async_abort_entries_match({CONF_HOST: user_input[CONF_HOST]})
|
self._async_abort_entries_match({CONF_HOST: user_input[CONF_HOST]})
|
||||||
|
|
||||||
user_input[CONF_NAME] = slugify(user_input[CONF_NAME])
|
|
||||||
|
|
||||||
if await self._test_connection(user_input[CONF_HOST]):
|
if await self._test_connection(user_input[CONF_HOST]):
|
||||||
if user_input[CONF_HAS_PWD]:
|
if user_input[CONF_HAS_PWD]:
|
||||||
self._user_input = user_input
|
self._user_input = user_input
|
||||||
return await self.async_step_password()
|
return await self.async_step_password()
|
||||||
|
|
||||||
return self.async_create_entry(
|
return self.async_create_entry(
|
||||||
title=user_input[CONF_NAME], data=user_input
|
title=user_input[CONF_HOST], data=user_input
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
user_input = {CONF_NAME: DEFAULT_NAME, CONF_HOST: DEFAULT_HOST}
|
user_input = {CONF_HOST: DEFAULT_HOST}
|
||||||
|
|
||||||
return self.async_show_form(
|
return self.async_show_form(
|
||||||
step_id="user",
|
step_id="user",
|
||||||
data_schema=vol.Schema(
|
data_schema=vol.Schema(
|
||||||
{
|
{
|
||||||
vol.Required(CONF_NAME, default=user_input[CONF_NAME]): str,
|
|
||||||
vol.Required(CONF_HOST, default=user_input[CONF_HOST]): str,
|
vol.Required(CONF_HOST, default=user_input[CONF_HOST]): str,
|
||||||
vol.Required(CONF_HAS_PWD, default=False): bool,
|
vol.Required(CONF_HAS_PWD, default=False): bool,
|
||||||
}
|
}
|
||||||
@ -120,7 +113,7 @@ class SolarLogConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||||||
):
|
):
|
||||||
self._user_input |= user_input
|
self._user_input |= user_input
|
||||||
return self.async_create_entry(
|
return self.async_create_entry(
|
||||||
title=self._user_input[CONF_NAME], data=self._user_input
|
title=self._user_input[CONF_HOST], data=self._user_input
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
user_input = {CONF_PASSWORD: ""}
|
user_input = {CONF_PASSWORD: ""}
|
||||||
|
@ -6,6 +6,5 @@ DOMAIN = "solarlog"
|
|||||||
|
|
||||||
# Default config for solarlog.
|
# Default config for solarlog.
|
||||||
DEFAULT_HOST = "http://solar-log"
|
DEFAULT_HOST = "http://solar-log"
|
||||||
DEFAULT_NAME = "solarlog"
|
|
||||||
|
|
||||||
CONF_HAS_PWD = "has_password"
|
CONF_HAS_PWD = "has_password"
|
||||||
|
@ -52,7 +52,6 @@ class SolarLogCoordinator(DataUpdateCoordinator[SolarlogData]):
|
|||||||
path = url.path if url.netloc else ""
|
path = url.path if url.netloc else ""
|
||||||
url = ParseResult("http", netloc, path, *url[3:])
|
url = ParseResult("http", netloc, path, *url[3:])
|
||||||
self.unique_id = entry.entry_id
|
self.unique_id = entry.entry_id
|
||||||
self.name = entry.title
|
|
||||||
self.host = url.geturl()
|
self.host = url.geturl()
|
||||||
|
|
||||||
self.solarlog = SolarLogConnector(
|
self.solarlog = SolarLogConnector(
|
||||||
|
@ -43,7 +43,7 @@ class SolarLogCoordinatorEntity(SolarLogBaseEntity):
|
|||||||
manufacturer="Solar-Log",
|
manufacturer="Solar-Log",
|
||||||
model="Controller",
|
model="Controller",
|
||||||
identifiers={(DOMAIN, coordinator.unique_id)},
|
identifiers={(DOMAIN, coordinator.unique_id)},
|
||||||
name=coordinator.name,
|
name="SolarLog",
|
||||||
configuration_url=coordinator.host,
|
configuration_url=coordinator.host,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -5,7 +5,6 @@
|
|||||||
"title": "Define your Solar-Log connection",
|
"title": "Define your Solar-Log connection",
|
||||||
"data": {
|
"data": {
|
||||||
"host": "[%key:common::config_flow::data::host%]",
|
"host": "[%key:common::config_flow::data::host%]",
|
||||||
"name": "The prefix to be used for your Solar-Log sensors",
|
|
||||||
"has_password": "I have the password for the Solar-Log user account."
|
"has_password": "I have the password for the Solar-Log user account."
|
||||||
},
|
},
|
||||||
"data_description": {
|
"data_description": {
|
||||||
|
@ -10,9 +10,9 @@ from homeassistant.components.solarlog.const import (
|
|||||||
CONF_HAS_PWD,
|
CONF_HAS_PWD,
|
||||||
DOMAIN as SOLARLOG_DOMAIN,
|
DOMAIN as SOLARLOG_DOMAIN,
|
||||||
)
|
)
|
||||||
from homeassistant.const import CONF_HOST, CONF_NAME, CONF_PASSWORD
|
from homeassistant.const import CONF_HOST, CONF_PASSWORD
|
||||||
|
|
||||||
from .const import HOST, NAME
|
from .const import HOST
|
||||||
|
|
||||||
from tests.common import MockConfigEntry, load_json_object_fixture
|
from tests.common import MockConfigEntry, load_json_object_fixture
|
||||||
|
|
||||||
@ -38,7 +38,6 @@ def mock_config_entry() -> MockConfigEntry:
|
|||||||
title="solarlog",
|
title="solarlog",
|
||||||
data={
|
data={
|
||||||
CONF_HOST: HOST,
|
CONF_HOST: HOST,
|
||||||
CONF_NAME: NAME,
|
|
||||||
CONF_HAS_PWD: True,
|
CONF_HAS_PWD: True,
|
||||||
CONF_PASSWORD: "pwd",
|
CONF_PASSWORD: "pwd",
|
||||||
},
|
},
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
"""Common const used across tests for SolarLog."""
|
"""Common const used across tests for SolarLog."""
|
||||||
|
|
||||||
NAME = "Solarlog test 1 2 3"
|
|
||||||
HOST = "http://1.1.1.1"
|
HOST = "http://1.1.1.1"
|
||||||
|
@ -5,7 +5,6 @@
|
|||||||
'data': dict({
|
'data': dict({
|
||||||
'has_password': True,
|
'has_password': True,
|
||||||
'host': '**REDACTED**',
|
'host': '**REDACTED**',
|
||||||
'name': 'Solarlog test 1 2 3',
|
|
||||||
'password': 'pwd',
|
'password': 'pwd',
|
||||||
}),
|
}),
|
||||||
'disabled_by': None,
|
'disabled_by': None,
|
||||||
|
@ -254,7 +254,7 @@
|
|||||||
StateSnapshot({
|
StateSnapshot({
|
||||||
'attributes': ReadOnlyDict({
|
'attributes': ReadOnlyDict({
|
||||||
'device_class': 'power',
|
'device_class': 'power',
|
||||||
'friendly_name': 'solarlog Alternator loss',
|
'friendly_name': 'SolarLog Alternator loss',
|
||||||
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
|
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
|
||||||
'unit_of_measurement': <UnitOfPower.WATT: 'W'>,
|
'unit_of_measurement': <UnitOfPower.WATT: 'W'>,
|
||||||
}),
|
}),
|
||||||
@ -308,7 +308,7 @@
|
|||||||
StateSnapshot({
|
StateSnapshot({
|
||||||
'attributes': ReadOnlyDict({
|
'attributes': ReadOnlyDict({
|
||||||
'device_class': 'power_factor',
|
'device_class': 'power_factor',
|
||||||
'friendly_name': 'solarlog Capacity',
|
'friendly_name': 'SolarLog Capacity',
|
||||||
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
|
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
|
||||||
'unit_of_measurement': '%',
|
'unit_of_measurement': '%',
|
||||||
}),
|
}),
|
||||||
@ -359,7 +359,7 @@
|
|||||||
StateSnapshot({
|
StateSnapshot({
|
||||||
'attributes': ReadOnlyDict({
|
'attributes': ReadOnlyDict({
|
||||||
'device_class': 'power',
|
'device_class': 'power',
|
||||||
'friendly_name': 'solarlog Consumption AC',
|
'friendly_name': 'SolarLog Consumption AC',
|
||||||
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
|
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
|
||||||
'unit_of_measurement': <UnitOfPower.WATT: 'W'>,
|
'unit_of_measurement': <UnitOfPower.WATT: 'W'>,
|
||||||
}),
|
}),
|
||||||
@ -416,7 +416,7 @@
|
|||||||
StateSnapshot({
|
StateSnapshot({
|
||||||
'attributes': ReadOnlyDict({
|
'attributes': ReadOnlyDict({
|
||||||
'device_class': 'energy',
|
'device_class': 'energy',
|
||||||
'friendly_name': 'solarlog Consumption day',
|
'friendly_name': 'SolarLog Consumption day',
|
||||||
'state_class': <SensorStateClass.TOTAL_INCREASING: 'total_increasing'>,
|
'state_class': <SensorStateClass.TOTAL_INCREASING: 'total_increasing'>,
|
||||||
'unit_of_measurement': <UnitOfEnergy.KILO_WATT_HOUR: 'kWh'>,
|
'unit_of_measurement': <UnitOfEnergy.KILO_WATT_HOUR: 'kWh'>,
|
||||||
}),
|
}),
|
||||||
@ -473,7 +473,7 @@
|
|||||||
StateSnapshot({
|
StateSnapshot({
|
||||||
'attributes': ReadOnlyDict({
|
'attributes': ReadOnlyDict({
|
||||||
'device_class': 'energy',
|
'device_class': 'energy',
|
||||||
'friendly_name': 'solarlog Consumption month',
|
'friendly_name': 'SolarLog Consumption month',
|
||||||
'state_class': <SensorStateClass.TOTAL_INCREASING: 'total_increasing'>,
|
'state_class': <SensorStateClass.TOTAL_INCREASING: 'total_increasing'>,
|
||||||
'unit_of_measurement': <UnitOfEnergy.KILO_WATT_HOUR: 'kWh'>,
|
'unit_of_measurement': <UnitOfEnergy.KILO_WATT_HOUR: 'kWh'>,
|
||||||
}),
|
}),
|
||||||
@ -530,7 +530,7 @@
|
|||||||
StateSnapshot({
|
StateSnapshot({
|
||||||
'attributes': ReadOnlyDict({
|
'attributes': ReadOnlyDict({
|
||||||
'device_class': 'energy',
|
'device_class': 'energy',
|
||||||
'friendly_name': 'solarlog Consumption total',
|
'friendly_name': 'SolarLog Consumption total',
|
||||||
'state_class': <SensorStateClass.TOTAL: 'total'>,
|
'state_class': <SensorStateClass.TOTAL: 'total'>,
|
||||||
'unit_of_measurement': <UnitOfEnergy.KILO_WATT_HOUR: 'kWh'>,
|
'unit_of_measurement': <UnitOfEnergy.KILO_WATT_HOUR: 'kWh'>,
|
||||||
}),
|
}),
|
||||||
@ -587,7 +587,7 @@
|
|||||||
StateSnapshot({
|
StateSnapshot({
|
||||||
'attributes': ReadOnlyDict({
|
'attributes': ReadOnlyDict({
|
||||||
'device_class': 'energy',
|
'device_class': 'energy',
|
||||||
'friendly_name': 'solarlog Consumption year',
|
'friendly_name': 'SolarLog Consumption year',
|
||||||
'state_class': <SensorStateClass.TOTAL_INCREASING: 'total_increasing'>,
|
'state_class': <SensorStateClass.TOTAL_INCREASING: 'total_increasing'>,
|
||||||
'unit_of_measurement': <UnitOfEnergy.KILO_WATT_HOUR: 'kWh'>,
|
'unit_of_measurement': <UnitOfEnergy.KILO_WATT_HOUR: 'kWh'>,
|
||||||
}),
|
}),
|
||||||
@ -642,7 +642,7 @@
|
|||||||
StateSnapshot({
|
StateSnapshot({
|
||||||
'attributes': ReadOnlyDict({
|
'attributes': ReadOnlyDict({
|
||||||
'device_class': 'energy',
|
'device_class': 'energy',
|
||||||
'friendly_name': 'solarlog Consumption yesterday',
|
'friendly_name': 'SolarLog Consumption yesterday',
|
||||||
'unit_of_measurement': <UnitOfEnergy.KILO_WATT_HOUR: 'kWh'>,
|
'unit_of_measurement': <UnitOfEnergy.KILO_WATT_HOUR: 'kWh'>,
|
||||||
}),
|
}),
|
||||||
'context': <ANY>,
|
'context': <ANY>,
|
||||||
@ -695,7 +695,7 @@
|
|||||||
StateSnapshot({
|
StateSnapshot({
|
||||||
'attributes': ReadOnlyDict({
|
'attributes': ReadOnlyDict({
|
||||||
'device_class': 'power_factor',
|
'device_class': 'power_factor',
|
||||||
'friendly_name': 'solarlog Efficiency',
|
'friendly_name': 'SolarLog Efficiency',
|
||||||
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
|
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
|
||||||
'unit_of_measurement': '%',
|
'unit_of_measurement': '%',
|
||||||
}),
|
}),
|
||||||
@ -746,7 +746,7 @@
|
|||||||
StateSnapshot({
|
StateSnapshot({
|
||||||
'attributes': ReadOnlyDict({
|
'attributes': ReadOnlyDict({
|
||||||
'device_class': 'power',
|
'device_class': 'power',
|
||||||
'friendly_name': 'solarlog Installed peak power',
|
'friendly_name': 'SolarLog Installed peak power',
|
||||||
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
|
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
|
||||||
'unit_of_measurement': <UnitOfPower.WATT: 'W'>,
|
'unit_of_measurement': <UnitOfPower.WATT: 'W'>,
|
||||||
}),
|
}),
|
||||||
@ -795,7 +795,7 @@
|
|||||||
StateSnapshot({
|
StateSnapshot({
|
||||||
'attributes': ReadOnlyDict({
|
'attributes': ReadOnlyDict({
|
||||||
'device_class': 'timestamp',
|
'device_class': 'timestamp',
|
||||||
'friendly_name': 'solarlog Last update',
|
'friendly_name': 'SolarLog Last update',
|
||||||
}),
|
}),
|
||||||
'context': <ANY>,
|
'context': <ANY>,
|
||||||
'entity_id': 'sensor.solarlog_last_update',
|
'entity_id': 'sensor.solarlog_last_update',
|
||||||
@ -844,7 +844,7 @@
|
|||||||
StateSnapshot({
|
StateSnapshot({
|
||||||
'attributes': ReadOnlyDict({
|
'attributes': ReadOnlyDict({
|
||||||
'device_class': 'power',
|
'device_class': 'power',
|
||||||
'friendly_name': 'solarlog Power AC',
|
'friendly_name': 'SolarLog Power AC',
|
||||||
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
|
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
|
||||||
'unit_of_measurement': <UnitOfPower.WATT: 'W'>,
|
'unit_of_measurement': <UnitOfPower.WATT: 'W'>,
|
||||||
}),
|
}),
|
||||||
@ -895,7 +895,7 @@
|
|||||||
StateSnapshot({
|
StateSnapshot({
|
||||||
'attributes': ReadOnlyDict({
|
'attributes': ReadOnlyDict({
|
||||||
'device_class': 'power',
|
'device_class': 'power',
|
||||||
'friendly_name': 'solarlog Power available',
|
'friendly_name': 'SolarLog Power available',
|
||||||
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
|
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
|
||||||
'unit_of_measurement': <UnitOfPower.WATT: 'W'>,
|
'unit_of_measurement': <UnitOfPower.WATT: 'W'>,
|
||||||
}),
|
}),
|
||||||
@ -946,7 +946,7 @@
|
|||||||
StateSnapshot({
|
StateSnapshot({
|
||||||
'attributes': ReadOnlyDict({
|
'attributes': ReadOnlyDict({
|
||||||
'device_class': 'power',
|
'device_class': 'power',
|
||||||
'friendly_name': 'solarlog Power DC',
|
'friendly_name': 'SolarLog Power DC',
|
||||||
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
|
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
|
||||||
'unit_of_measurement': <UnitOfPower.WATT: 'W'>,
|
'unit_of_measurement': <UnitOfPower.WATT: 'W'>,
|
||||||
}),
|
}),
|
||||||
@ -997,7 +997,7 @@
|
|||||||
StateSnapshot({
|
StateSnapshot({
|
||||||
'attributes': ReadOnlyDict({
|
'attributes': ReadOnlyDict({
|
||||||
'device_class': 'energy',
|
'device_class': 'energy',
|
||||||
'friendly_name': 'solarlog Self-consumption year',
|
'friendly_name': 'SolarLog Self-consumption year',
|
||||||
'state_class': <SensorStateClass.TOTAL_INCREASING: 'total_increasing'>,
|
'state_class': <SensorStateClass.TOTAL_INCREASING: 'total_increasing'>,
|
||||||
'unit_of_measurement': <UnitOfEnergy.KILO_WATT_HOUR: 'kWh'>,
|
'unit_of_measurement': <UnitOfEnergy.KILO_WATT_HOUR: 'kWh'>,
|
||||||
}),
|
}),
|
||||||
@ -1051,7 +1051,7 @@
|
|||||||
StateSnapshot({
|
StateSnapshot({
|
||||||
'attributes': ReadOnlyDict({
|
'attributes': ReadOnlyDict({
|
||||||
'device_class': 'power_factor',
|
'device_class': 'power_factor',
|
||||||
'friendly_name': 'solarlog Usage',
|
'friendly_name': 'SolarLog Usage',
|
||||||
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
|
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
|
||||||
'unit_of_measurement': '%',
|
'unit_of_measurement': '%',
|
||||||
}),
|
}),
|
||||||
@ -1102,7 +1102,7 @@
|
|||||||
StateSnapshot({
|
StateSnapshot({
|
||||||
'attributes': ReadOnlyDict({
|
'attributes': ReadOnlyDict({
|
||||||
'device_class': 'voltage',
|
'device_class': 'voltage',
|
||||||
'friendly_name': 'solarlog Voltage AC',
|
'friendly_name': 'SolarLog Voltage AC',
|
||||||
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
|
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
|
||||||
'unit_of_measurement': <UnitOfElectricPotential.VOLT: 'V'>,
|
'unit_of_measurement': <UnitOfElectricPotential.VOLT: 'V'>,
|
||||||
}),
|
}),
|
||||||
@ -1153,7 +1153,7 @@
|
|||||||
StateSnapshot({
|
StateSnapshot({
|
||||||
'attributes': ReadOnlyDict({
|
'attributes': ReadOnlyDict({
|
||||||
'device_class': 'voltage',
|
'device_class': 'voltage',
|
||||||
'friendly_name': 'solarlog Voltage DC',
|
'friendly_name': 'SolarLog Voltage DC',
|
||||||
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
|
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
|
||||||
'unit_of_measurement': <UnitOfElectricPotential.VOLT: 'V'>,
|
'unit_of_measurement': <UnitOfElectricPotential.VOLT: 'V'>,
|
||||||
}),
|
}),
|
||||||
@ -1210,7 +1210,7 @@
|
|||||||
StateSnapshot({
|
StateSnapshot({
|
||||||
'attributes': ReadOnlyDict({
|
'attributes': ReadOnlyDict({
|
||||||
'device_class': 'energy',
|
'device_class': 'energy',
|
||||||
'friendly_name': 'solarlog Yield day',
|
'friendly_name': 'SolarLog Yield day',
|
||||||
'state_class': <SensorStateClass.TOTAL_INCREASING: 'total_increasing'>,
|
'state_class': <SensorStateClass.TOTAL_INCREASING: 'total_increasing'>,
|
||||||
'unit_of_measurement': <UnitOfEnergy.KILO_WATT_HOUR: 'kWh'>,
|
'unit_of_measurement': <UnitOfEnergy.KILO_WATT_HOUR: 'kWh'>,
|
||||||
}),
|
}),
|
||||||
@ -1267,7 +1267,7 @@
|
|||||||
StateSnapshot({
|
StateSnapshot({
|
||||||
'attributes': ReadOnlyDict({
|
'attributes': ReadOnlyDict({
|
||||||
'device_class': 'energy',
|
'device_class': 'energy',
|
||||||
'friendly_name': 'solarlog Yield month',
|
'friendly_name': 'SolarLog Yield month',
|
||||||
'state_class': <SensorStateClass.TOTAL_INCREASING: 'total_increasing'>,
|
'state_class': <SensorStateClass.TOTAL_INCREASING: 'total_increasing'>,
|
||||||
'unit_of_measurement': <UnitOfEnergy.KILO_WATT_HOUR: 'kWh'>,
|
'unit_of_measurement': <UnitOfEnergy.KILO_WATT_HOUR: 'kWh'>,
|
||||||
}),
|
}),
|
||||||
@ -1324,7 +1324,7 @@
|
|||||||
StateSnapshot({
|
StateSnapshot({
|
||||||
'attributes': ReadOnlyDict({
|
'attributes': ReadOnlyDict({
|
||||||
'device_class': 'energy',
|
'device_class': 'energy',
|
||||||
'friendly_name': 'solarlog Yield total',
|
'friendly_name': 'SolarLog Yield total',
|
||||||
'state_class': <SensorStateClass.TOTAL: 'total'>,
|
'state_class': <SensorStateClass.TOTAL: 'total'>,
|
||||||
'unit_of_measurement': <UnitOfEnergy.KILO_WATT_HOUR: 'kWh'>,
|
'unit_of_measurement': <UnitOfEnergy.KILO_WATT_HOUR: 'kWh'>,
|
||||||
}),
|
}),
|
||||||
@ -1378,7 +1378,7 @@
|
|||||||
StateSnapshot({
|
StateSnapshot({
|
||||||
'attributes': ReadOnlyDict({
|
'attributes': ReadOnlyDict({
|
||||||
'device_class': 'energy',
|
'device_class': 'energy',
|
||||||
'friendly_name': 'solarlog Yield year',
|
'friendly_name': 'SolarLog Yield year',
|
||||||
'state_class': <SensorStateClass.TOTAL_INCREASING: 'total_increasing'>,
|
'state_class': <SensorStateClass.TOTAL_INCREASING: 'total_increasing'>,
|
||||||
'unit_of_measurement': <UnitOfEnergy.KILO_WATT_HOUR: 'kWh'>,
|
'unit_of_measurement': <UnitOfEnergy.KILO_WATT_HOUR: 'kWh'>,
|
||||||
}),
|
}),
|
||||||
@ -1433,7 +1433,7 @@
|
|||||||
StateSnapshot({
|
StateSnapshot({
|
||||||
'attributes': ReadOnlyDict({
|
'attributes': ReadOnlyDict({
|
||||||
'device_class': 'energy',
|
'device_class': 'energy',
|
||||||
'friendly_name': 'solarlog Yield yesterday',
|
'friendly_name': 'SolarLog Yield yesterday',
|
||||||
'unit_of_measurement': <UnitOfEnergy.KILO_WATT_HOUR: 'kWh'>,
|
'unit_of_measurement': <UnitOfEnergy.KILO_WATT_HOUR: 'kWh'>,
|
||||||
}),
|
}),
|
||||||
'context': <ANY>,
|
'context': <ANY>,
|
||||||
|
@ -12,11 +12,11 @@ from solarlog_cli.solarlog_exceptions import (
|
|||||||
from homeassistant.components.solarlog import config_flow
|
from homeassistant.components.solarlog import config_flow
|
||||||
from homeassistant.components.solarlog.const import CONF_HAS_PWD, DOMAIN
|
from homeassistant.components.solarlog.const import CONF_HAS_PWD, DOMAIN
|
||||||
from homeassistant.config_entries import SOURCE_USER
|
from homeassistant.config_entries import SOURCE_USER
|
||||||
from homeassistant.const import CONF_HOST, CONF_NAME, CONF_PASSWORD
|
from homeassistant.const import CONF_HOST, CONF_PASSWORD
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.data_entry_flow import FlowResultType
|
from homeassistant.data_entry_flow import FlowResultType
|
||||||
|
|
||||||
from .const import HOST, NAME
|
from .const import HOST
|
||||||
|
|
||||||
from tests.common import MockConfigEntry
|
from tests.common import MockConfigEntry
|
||||||
|
|
||||||
@ -33,12 +33,12 @@ async def test_form(hass: HomeAssistant, mock_setup_entry: AsyncMock) -> None:
|
|||||||
|
|
||||||
result2 = await hass.config_entries.flow.async_configure(
|
result2 = await hass.config_entries.flow.async_configure(
|
||||||
result["flow_id"],
|
result["flow_id"],
|
||||||
{CONF_HOST: HOST, CONF_NAME: NAME, CONF_HAS_PWD: False},
|
{CONF_HOST: HOST, CONF_HAS_PWD: False},
|
||||||
)
|
)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
assert result2["type"] is FlowResultType.CREATE_ENTRY
|
assert result2["type"] is FlowResultType.CREATE_ENTRY
|
||||||
assert result2["title"] == "solarlog_test_1_2_3"
|
assert result2["title"] == HOST
|
||||||
assert result2["data"][CONF_HOST] == "http://1.1.1.1"
|
assert result2["data"][CONF_HOST] == "http://1.1.1.1"
|
||||||
assert result2["data"][CONF_HAS_PWD] is False
|
assert result2["data"][CONF_HAS_PWD] is False
|
||||||
assert len(mock_setup_entry.mock_calls) == 1
|
assert len(mock_setup_entry.mock_calls) == 1
|
||||||
@ -66,12 +66,12 @@ async def test_user(
|
|||||||
|
|
||||||
# tests with all provided
|
# tests with all provided
|
||||||
result = await hass.config_entries.flow.async_configure(
|
result = await hass.config_entries.flow.async_configure(
|
||||||
result["flow_id"], {CONF_HOST: HOST, CONF_NAME: NAME, CONF_HAS_PWD: False}
|
result["flow_id"], {CONF_HOST: HOST, CONF_HAS_PWD: False}
|
||||||
)
|
)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
assert result["type"] is FlowResultType.CREATE_ENTRY
|
assert result["type"] is FlowResultType.CREATE_ENTRY
|
||||||
assert result["title"] == "solarlog_test_1_2_3"
|
assert result["title"] == HOST
|
||||||
assert result["data"][CONF_HOST] == HOST
|
assert result["data"][CONF_HOST] == HOST
|
||||||
assert len(mock_setup_entry.mock_calls) == 1
|
assert len(mock_setup_entry.mock_calls) == 1
|
||||||
|
|
||||||
@ -106,9 +106,7 @@ async def test_form_exceptions(
|
|||||||
mock_solarlog_connector.test_connection.side_effect = exception1
|
mock_solarlog_connector.test_connection.side_effect = exception1
|
||||||
|
|
||||||
# tests with connection error
|
# tests with connection error
|
||||||
result = await flow.async_step_user(
|
result = await flow.async_step_user({CONF_HOST: HOST, CONF_HAS_PWD: False})
|
||||||
{CONF_NAME: NAME, CONF_HOST: HOST, CONF_HAS_PWD: False}
|
|
||||||
)
|
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
assert result["type"] is FlowResultType.FORM
|
assert result["type"] is FlowResultType.FORM
|
||||||
@ -119,9 +117,7 @@ async def test_form_exceptions(
|
|||||||
mock_solarlog_connector.test_connection.side_effect = None
|
mock_solarlog_connector.test_connection.side_effect = None
|
||||||
mock_solarlog_connector.test_extended_data_available.side_effect = exception2
|
mock_solarlog_connector.test_extended_data_available.side_effect = exception2
|
||||||
|
|
||||||
result = await flow.async_step_user(
|
result = await flow.async_step_user({CONF_HOST: HOST, CONF_HAS_PWD: True})
|
||||||
{CONF_NAME: NAME, CONF_HOST: HOST, CONF_HAS_PWD: True}
|
|
||||||
)
|
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
assert result["type"] is FlowResultType.FORM
|
assert result["type"] is FlowResultType.FORM
|
||||||
@ -137,13 +133,11 @@ async def test_form_exceptions(
|
|||||||
mock_solarlog_connector.test_extended_data_available.side_effect = None
|
mock_solarlog_connector.test_extended_data_available.side_effect = None
|
||||||
|
|
||||||
# tests with all provided (no password)
|
# tests with all provided (no password)
|
||||||
result = await flow.async_step_user(
|
result = await flow.async_step_user({CONF_HOST: HOST, CONF_HAS_PWD: False})
|
||||||
{CONF_NAME: NAME, CONF_HOST: HOST, CONF_HAS_PWD: False}
|
|
||||||
)
|
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
assert result["type"] is FlowResultType.CREATE_ENTRY
|
assert result["type"] is FlowResultType.CREATE_ENTRY
|
||||||
assert result["title"] == "solarlog_test_1_2_3"
|
assert result["title"] == HOST
|
||||||
assert result["data"][CONF_HOST] == HOST
|
assert result["data"][CONF_HOST] == HOST
|
||||||
assert result["data"][CONF_HAS_PWD] is False
|
assert result["data"][CONF_HAS_PWD] is False
|
||||||
|
|
||||||
@ -152,16 +146,14 @@ async def test_form_exceptions(
|
|||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
assert result["type"] is FlowResultType.CREATE_ENTRY
|
assert result["type"] is FlowResultType.CREATE_ENTRY
|
||||||
assert result["title"] == "solarlog_test_1_2_3"
|
assert result["title"] == HOST
|
||||||
assert result["data"][CONF_PASSWORD] == "pwd"
|
assert result["data"][CONF_PASSWORD] == "pwd"
|
||||||
|
|
||||||
|
|
||||||
async def test_abort_if_already_setup(hass: HomeAssistant, test_connect: None) -> None:
|
async def test_abort_if_already_setup(hass: HomeAssistant, test_connect: None) -> None:
|
||||||
"""Test we abort if the device is already setup."""
|
"""Test we abort if the device is already setup."""
|
||||||
|
|
||||||
MockConfigEntry(domain=DOMAIN, data={CONF_NAME: NAME, CONF_HOST: HOST}).add_to_hass(
|
MockConfigEntry(domain=DOMAIN, data={CONF_HOST: HOST}).add_to_hass(hass)
|
||||||
hass
|
|
||||||
)
|
|
||||||
|
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
DOMAIN, context={"source": SOURCE_USER}
|
DOMAIN, context={"source": SOURCE_USER}
|
||||||
@ -173,7 +165,7 @@ async def test_abort_if_already_setup(hass: HomeAssistant, test_connect: None) -
|
|||||||
|
|
||||||
result = await hass.config_entries.flow.async_configure(
|
result = await hass.config_entries.flow.async_configure(
|
||||||
result["flow_id"],
|
result["flow_id"],
|
||||||
{CONF_HOST: HOST, CONF_NAME: "solarlog_test_7_8_9", CONF_HAS_PWD: False},
|
{CONF_HOST: HOST, CONF_HAS_PWD: False},
|
||||||
)
|
)
|
||||||
assert result["type"] is FlowResultType.ABORT
|
assert result["type"] is FlowResultType.ABORT
|
||||||
assert result["reason"] == "already_configured"
|
assert result["reason"] == "already_configured"
|
||||||
@ -196,7 +188,7 @@ async def test_reconfigure_flow(
|
|||||||
"""Test config flow options."""
|
"""Test config flow options."""
|
||||||
entry = MockConfigEntry(
|
entry = MockConfigEntry(
|
||||||
domain=DOMAIN,
|
domain=DOMAIN,
|
||||||
title="solarlog_test_1_2_3",
|
title=HOST,
|
||||||
data={
|
data={
|
||||||
CONF_HOST: HOST,
|
CONF_HOST: HOST,
|
||||||
CONF_HAS_PWD: False,
|
CONF_HAS_PWD: False,
|
||||||
@ -221,7 +213,7 @@ async def test_reconfigure_flow(
|
|||||||
|
|
||||||
entry = hass.config_entries.async_get_entry(entry.entry_id)
|
entry = hass.config_entries.async_get_entry(entry.entry_id)
|
||||||
assert entry
|
assert entry
|
||||||
assert entry.title == "solarlog_test_1_2_3"
|
assert entry.title == HOST
|
||||||
assert entry.data[CONF_HAS_PWD] == has_password
|
assert entry.data[CONF_HAS_PWD] == has_password
|
||||||
assert entry.data[CONF_PASSWORD] == password
|
assert entry.data[CONF_PASSWORD] == password
|
||||||
|
|
||||||
@ -244,7 +236,7 @@ async def test_reauth(
|
|||||||
|
|
||||||
entry = MockConfigEntry(
|
entry = MockConfigEntry(
|
||||||
domain=DOMAIN,
|
domain=DOMAIN,
|
||||||
title="solarlog_test_1_2_3",
|
title=HOST,
|
||||||
data={
|
data={
|
||||||
CONF_HOST: HOST,
|
CONF_HOST: HOST,
|
||||||
CONF_HAS_PWD: True,
|
CONF_HAS_PWD: True,
|
||||||
|
@ -19,7 +19,7 @@ from homeassistant.helpers.device_registry import DeviceRegistry
|
|||||||
from homeassistant.helpers.entity_registry import EntityRegistry
|
from homeassistant.helpers.entity_registry import EntityRegistry
|
||||||
|
|
||||||
from . import setup_platform
|
from . import setup_platform
|
||||||
from .const import HOST, NAME
|
from .const import HOST
|
||||||
|
|
||||||
from tests.common import MockConfigEntry
|
from tests.common import MockConfigEntry
|
||||||
|
|
||||||
@ -140,7 +140,7 @@ async def test_migrate_config_entry(
|
|||||||
"""Test successful migration of entry data."""
|
"""Test successful migration of entry data."""
|
||||||
entry = MockConfigEntry(
|
entry = MockConfigEntry(
|
||||||
domain=DOMAIN,
|
domain=DOMAIN,
|
||||||
title=NAME,
|
title=HOST,
|
||||||
data={
|
data={
|
||||||
CONF_HOST: HOST,
|
CONF_HOST: HOST,
|
||||||
},
|
},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user