mirror of
https://github.com/home-assistant/core.git
synced 2025-07-26 22:57:17 +00:00
Deprecate YAML config for Solar-log (#43484)
Per ADR-0010, this PR deprecates YAML configuration for Solar-log. Users who already use the Solar-log integration do not need to take action, as their configuration has already been imported into the UI.
This commit is contained in:
parent
a092b4c204
commit
977ed942ba
@ -4,39 +4,28 @@ from urllib.parse import ParseResult, urlparse
|
|||||||
|
|
||||||
from requests.exceptions import HTTPError, Timeout
|
from requests.exceptions import HTTPError, Timeout
|
||||||
from sunwatcher.solarlog.solarlog import SolarLog
|
from sunwatcher.solarlog.solarlog import SolarLog
|
||||||
import voluptuous as vol
|
|
||||||
|
|
||||||
from homeassistant.components.sensor import PLATFORM_SCHEMA
|
from homeassistant.const import CONF_HOST
|
||||||
from homeassistant.config_entries import SOURCE_IMPORT
|
|
||||||
from homeassistant.const import CONF_HOST, CONF_NAME
|
|
||||||
import homeassistant.helpers.config_validation as cv
|
|
||||||
from homeassistant.helpers.entity import Entity
|
from homeassistant.helpers.entity import Entity
|
||||||
from homeassistant.util import Throttle
|
from homeassistant.util import Throttle
|
||||||
|
|
||||||
from .const import DEFAULT_HOST, DEFAULT_NAME, DOMAIN, SCAN_INTERVAL, SENSOR_TYPES
|
from .const import SCAN_INTERVAL, SENSOR_TYPES
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
|
||||||
{
|
|
||||||
vol.Optional(CONF_HOST, default=DEFAULT_HOST): cv.string,
|
|
||||||
vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
|
async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
|
||||||
"""Import YAML configuration when available."""
|
"""Set up the solarlog platform."""
|
||||||
hass.async_create_task(
|
_LOGGER.warning(
|
||||||
hass.config_entries.flow.async_init(
|
"Configuration of the solarlog platform in configuration.yaml is deprecated in Home Assistant 0.119. Please remove entry from your configuration"
|
||||||
DOMAIN, context={"source": SOURCE_IMPORT}, data=dict(config)
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(hass, entry, async_add_entities):
|
async def async_setup_entry(hass, entry, async_add_entities):
|
||||||
"""Add solarlog entry."""
|
"""Add solarlog entry."""
|
||||||
host_entry = entry.data[CONF_HOST]
|
host_entry = entry.data[CONF_HOST]
|
||||||
|
device_name = entry.title
|
||||||
|
|
||||||
url = urlparse(host_entry, "http")
|
url = urlparse(host_entry, "http")
|
||||||
netloc = url.netloc or url.path
|
netloc = url.netloc or url.path
|
||||||
@ -44,8 +33,6 @@ async def async_setup_entry(hass, entry, async_add_entities):
|
|||||||
url = ParseResult("http", netloc, path, *url[3:])
|
url = ParseResult("http", netloc, path, *url[3:])
|
||||||
host = url.geturl()
|
host = url.geturl()
|
||||||
|
|
||||||
platform_name = entry.title
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
api = await hass.async_add_executor_job(SolarLog, host)
|
api = await hass.async_add_executor_job(SolarLog, host)
|
||||||
_LOGGER.debug("Connected to Solar-Log device, setting up entries")
|
_LOGGER.debug("Connected to Solar-Log device, setting up entries")
|
||||||
@ -61,7 +48,7 @@ async def async_setup_entry(hass, entry, async_add_entities):
|
|||||||
# Create a new sensor for each sensor type.
|
# Create a new sensor for each sensor type.
|
||||||
entities = []
|
entities = []
|
||||||
for sensor_key in SENSOR_TYPES:
|
for sensor_key in SENSOR_TYPES:
|
||||||
sensor = SolarlogSensor(entry.entry_id, platform_name, sensor_key, data)
|
sensor = SolarlogSensor(entry.entry_id, device_name, sensor_key, data)
|
||||||
entities.append(sensor)
|
entities.append(sensor)
|
||||||
|
|
||||||
async_add_entities(entities, True)
|
async_add_entities(entities, True)
|
||||||
@ -71,9 +58,9 @@ async def async_setup_entry(hass, entry, async_add_entities):
|
|||||||
class SolarlogSensor(Entity):
|
class SolarlogSensor(Entity):
|
||||||
"""Representation of a Sensor."""
|
"""Representation of a Sensor."""
|
||||||
|
|
||||||
def __init__(self, entry_id, platform_name, sensor_key, data):
|
def __init__(self, entry_id, device_name, sensor_key, data):
|
||||||
"""Initialize the sensor."""
|
"""Initialize the sensor."""
|
||||||
self.platform_name = platform_name
|
self.device_name = device_name
|
||||||
self.sensor_key = sensor_key
|
self.sensor_key = sensor_key
|
||||||
self.data = data
|
self.data = data
|
||||||
self.entry_id = entry_id
|
self.entry_id = entry_id
|
||||||
@ -92,7 +79,7 @@ class SolarlogSensor(Entity):
|
|||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
"""Return the name of the sensor."""
|
"""Return the name of the sensor."""
|
||||||
return f"{self.platform_name} {self._label}"
|
return f"{self.device_name} {self._label}"
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def unit_of_measurement(self):
|
def unit_of_measurement(self):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user