mirror of
https://github.com/home-assistant/core.git
synced 2025-04-24 01:08:12 +00:00
Remove YAML support from powerwall (#45381)
This commit is contained in:
parent
59f178ab9e
commit
38d4af1a6e
@ -5,9 +5,8 @@ import logging
|
||||
|
||||
import requests
|
||||
from tesla_powerwall import MissingAttributeError, Powerwall, PowerwallUnreachableError
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import CONF_IP_ADDRESS
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.exceptions import ConfigEntryNotReady
|
||||
@ -32,10 +31,7 @@ from .const import (
|
||||
UPDATE_INTERVAL,
|
||||
)
|
||||
|
||||
CONFIG_SCHEMA = vol.Schema(
|
||||
{DOMAIN: vol.Schema({vol.Required(CONF_IP_ADDRESS): cv.string})},
|
||||
extra=vol.ALLOW_EXTRA,
|
||||
)
|
||||
CONFIG_SCHEMA = cv.deprecated(DOMAIN)
|
||||
|
||||
PLATFORMS = ["binary_sensor", "sensor"]
|
||||
|
||||
@ -45,18 +41,7 @@ _LOGGER = logging.getLogger(__name__)
|
||||
async def async_setup(hass: HomeAssistant, config: dict):
|
||||
"""Set up the Tesla Powerwall component."""
|
||||
hass.data.setdefault(DOMAIN, {})
|
||||
conf = config.get(DOMAIN)
|
||||
|
||||
if not conf:
|
||||
return True
|
||||
|
||||
hass.async_create_task(
|
||||
hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": SOURCE_IMPORT},
|
||||
data=conf,
|
||||
)
|
||||
)
|
||||
return True
|
||||
|
||||
|
||||
|
@ -83,13 +83,6 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
||||
errors=errors,
|
||||
)
|
||||
|
||||
async def async_step_import(self, user_input):
|
||||
"""Handle import."""
|
||||
await self.async_set_unique_id(user_input[CONF_IP_ADDRESS])
|
||||
self._abort_if_unique_id_configured()
|
||||
|
||||
return await self.async_step_user(user_input)
|
||||
|
||||
@callback
|
||||
def _async_ip_address_already_configured(self, ip_address):
|
||||
"""See if we already have an entry matching the ip_address."""
|
||||
|
@ -14,9 +14,6 @@ from tesla_powerwall import (
|
||||
SiteMaster,
|
||||
)
|
||||
|
||||
from homeassistant.components.powerwall.const import DOMAIN
|
||||
from homeassistant.const import CONF_IP_ADDRESS
|
||||
|
||||
from tests.common import load_fixture
|
||||
|
||||
|
||||
@ -85,8 +82,3 @@ async def _async_load_json_fixture(hass, path):
|
||||
load_fixture, os.path.join("powerwall", path)
|
||||
)
|
||||
return json.loads(fixture)
|
||||
|
||||
|
||||
def _mock_get_config():
|
||||
"""Return a default powerwall config."""
|
||||
return {DOMAIN: {CONF_IP_ADDRESS: "1.2.3.4"}}
|
||||
|
@ -3,10 +3,11 @@
|
||||
from unittest.mock import patch
|
||||
|
||||
from homeassistant.components.powerwall.const import DOMAIN
|
||||
from homeassistant.const import STATE_ON
|
||||
from homeassistant.setup import async_setup_component
|
||||
from homeassistant.const import CONF_IP_ADDRESS, STATE_ON
|
||||
|
||||
from .mocks import _mock_get_config, _mock_powerwall_with_fixtures
|
||||
from .mocks import _mock_powerwall_with_fixtures
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
|
||||
|
||||
async def test_sensors(hass):
|
||||
@ -14,14 +15,15 @@ async def test_sensors(hass):
|
||||
|
||||
mock_powerwall = await _mock_powerwall_with_fixtures(hass)
|
||||
|
||||
config_entry = MockConfigEntry(domain=DOMAIN, data={CONF_IP_ADDRESS: "1.2.3.4"})
|
||||
config_entry.add_to_hass(hass)
|
||||
with patch(
|
||||
"homeassistant.components.powerwall.config_flow.Powerwall",
|
||||
return_value=mock_powerwall,
|
||||
), patch(
|
||||
"homeassistant.components.powerwall.Powerwall",
|
||||
return_value=mock_powerwall,
|
||||
"homeassistant.components.powerwall.Powerwall", return_value=mock_powerwall
|
||||
):
|
||||
assert await async_setup_component(hass, DOMAIN, _mock_get_config())
|
||||
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
state = hass.states.get("binary_sensor.grid_status")
|
||||
|
@ -47,34 +47,6 @@ async def test_form_source_user(hass):
|
||||
assert len(mock_setup_entry.mock_calls) == 1
|
||||
|
||||
|
||||
async def test_form_source_import(hass):
|
||||
"""Test we setup the config entry via import."""
|
||||
await setup.async_setup_component(hass, "persistent_notification", {})
|
||||
|
||||
mock_powerwall = await _mock_powerwall_site_name(hass, "Imported site")
|
||||
with patch(
|
||||
"homeassistant.components.powerwall.config_flow.Powerwall",
|
||||
return_value=mock_powerwall,
|
||||
), patch(
|
||||
"homeassistant.components.powerwall.async_setup", return_value=True
|
||||
) as mock_setup, patch(
|
||||
"homeassistant.components.powerwall.async_setup_entry",
|
||||
return_value=True,
|
||||
) as mock_setup_entry:
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": config_entries.SOURCE_IMPORT},
|
||||
data={CONF_IP_ADDRESS: "1.2.3.4"},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert result["type"] == "create_entry"
|
||||
assert result["title"] == "Imported site"
|
||||
assert result["data"] == {CONF_IP_ADDRESS: "1.2.3.4"}
|
||||
assert len(mock_setup.mock_calls) == 1
|
||||
assert len(mock_setup_entry.mock_calls) == 1
|
||||
|
||||
|
||||
async def test_form_cannot_connect(hass):
|
||||
"""Test we handle cannot connect error."""
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
|
@ -3,10 +3,11 @@
|
||||
from unittest.mock import patch
|
||||
|
||||
from homeassistant.components.powerwall.const import DOMAIN
|
||||
from homeassistant.const import PERCENTAGE
|
||||
from homeassistant.setup import async_setup_component
|
||||
from homeassistant.const import CONF_IP_ADDRESS, PERCENTAGE
|
||||
|
||||
from .mocks import _mock_get_config, _mock_powerwall_with_fixtures
|
||||
from .mocks import _mock_powerwall_with_fixtures
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
|
||||
|
||||
async def test_sensors(hass):
|
||||
@ -14,13 +15,15 @@ async def test_sensors(hass):
|
||||
|
||||
mock_powerwall = await _mock_powerwall_with_fixtures(hass)
|
||||
|
||||
config_entry = MockConfigEntry(domain=DOMAIN, data={CONF_IP_ADDRESS: "1.2.3.4"})
|
||||
config_entry.add_to_hass(hass)
|
||||
with patch(
|
||||
"homeassistant.components.powerwall.config_flow.Powerwall",
|
||||
return_value=mock_powerwall,
|
||||
), patch(
|
||||
"homeassistant.components.powerwall.Powerwall", return_value=mock_powerwall
|
||||
):
|
||||
assert await async_setup_component(hass, DOMAIN, _mock_get_config())
|
||||
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
device_registry = await hass.helpers.device_registry.async_get_registry()
|
||||
|
Loading…
x
Reference in New Issue
Block a user