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
1 changed files with 11 additions and 24 deletions
|
@ -4,39 +4,28 @@ from urllib.parse import ParseResult, urlparse
|
|||
|
||||
from requests.exceptions import HTTPError, Timeout
|
||||
from sunwatcher.solarlog.solarlog import SolarLog
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components.sensor import PLATFORM_SCHEMA
|
||||
from homeassistant.config_entries import SOURCE_IMPORT
|
||||
from homeassistant.const import CONF_HOST, CONF_NAME
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.const import CONF_HOST
|
||||
from homeassistant.helpers.entity import Entity
|
||||
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__)
|
||||
|
||||
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):
|
||||
"""Import YAML configuration when available."""
|
||||
hass.async_create_task(
|
||||
hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": SOURCE_IMPORT}, data=dict(config)
|
||||
)
|
||||
"""Set up the solarlog platform."""
|
||||
_LOGGER.warning(
|
||||
"Configuration of the solarlog platform in configuration.yaml is deprecated in Home Assistant 0.119. Please remove entry from your configuration"
|
||||
)
|
||||
return True
|
||||
|
||||
|
||||
async def async_setup_entry(hass, entry, async_add_entities):
|
||||
"""Add solarlog entry."""
|
||||
host_entry = entry.data[CONF_HOST]
|
||||
device_name = entry.title
|
||||
|
||||
url = urlparse(host_entry, "http")
|
||||
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:])
|
||||
host = url.geturl()
|
||||
|
||||
platform_name = entry.title
|
||||
|
||||
try:
|
||||
api = await hass.async_add_executor_job(SolarLog, host)
|
||||
_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.
|
||||
entities = []
|
||||
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)
|
||||
|
||||
async_add_entities(entities, True)
|
||||
|
@ -71,9 +58,9 @@ async def async_setup_entry(hass, entry, async_add_entities):
|
|||
class SolarlogSensor(Entity):
|
||||
"""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."""
|
||||
self.platform_name = platform_name
|
||||
self.device_name = device_name
|
||||
self.sensor_key = sensor_key
|
||||
self.data = data
|
||||
self.entry_id = entry_id
|
||||
|
@ -92,7 +79,7 @@ class SolarlogSensor(Entity):
|
|||
@property
|
||||
def name(self):
|
||||
"""Return the name of the sensor."""
|
||||
return f"{self.platform_name} {self._label}"
|
||||
return f"{self.device_name} {self._label}"
|
||||
|
||||
@property
|
||||
def unit_of_measurement(self):
|
||||
|
|
Loading…
Add table
Reference in a new issue