mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 05:07:41 +00:00
Update SMA device info on setup (#51159)
* Update device info on setup * Remove migration
This commit is contained in:
parent
3027b848c1
commit
5e721b2566
@ -32,6 +32,7 @@ from .const import (
|
|||||||
DOMAIN,
|
DOMAIN,
|
||||||
PLATFORMS,
|
PLATFORMS,
|
||||||
PYSMA_COORDINATOR,
|
PYSMA_COORDINATOR,
|
||||||
|
PYSMA_DEVICE_INFO,
|
||||||
PYSMA_OBJECT,
|
PYSMA_OBJECT,
|
||||||
PYSMA_REMOVE_LISTENER,
|
PYSMA_REMOVE_LISTENER,
|
||||||
PYSMA_SENSORS,
|
PYSMA_SENSORS,
|
||||||
@ -141,6 +142,8 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||||||
session = async_get_clientsession(hass, verify_ssl=verify_ssl)
|
session = async_get_clientsession(hass, verify_ssl=verify_ssl)
|
||||||
sma = pysma.SMA(session, url, password, group)
|
sma = pysma.SMA(session, url, password, group)
|
||||||
|
|
||||||
|
# Get updated device info
|
||||||
|
device_info = await sma.device_info()
|
||||||
# Get all device sensors
|
# Get all device sensors
|
||||||
sensor_def = await sma.get_sensors()
|
sensor_def = await sma.get_sensors()
|
||||||
|
|
||||||
@ -189,6 +192,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||||||
PYSMA_COORDINATOR: coordinator,
|
PYSMA_COORDINATOR: coordinator,
|
||||||
PYSMA_SENSORS: sensor_def,
|
PYSMA_SENSORS: sensor_def,
|
||||||
PYSMA_REMOVE_LISTENER: remove_stop_listener,
|
PYSMA_REMOVE_LISTENER: remove_stop_listener,
|
||||||
|
PYSMA_DEVICE_INFO: device_info,
|
||||||
}
|
}
|
||||||
|
|
||||||
hass.config_entries.async_setup_platforms(entry, PLATFORMS)
|
hass.config_entries.async_setup_platforms(entry, PLATFORMS)
|
||||||
|
@ -20,7 +20,7 @@ from homeassistant.data_entry_flow import FlowResult
|
|||||||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
|
|
||||||
from .const import CONF_CUSTOM, CONF_GROUP, DEVICE_INFO, DOMAIN, GROUPS
|
from .const import CONF_CUSTOM, CONF_GROUP, DOMAIN, GROUPS
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -63,7 +63,6 @@ class SmaConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
|||||||
CONF_PASSWORD: vol.UNDEFINED,
|
CONF_PASSWORD: vol.UNDEFINED,
|
||||||
CONF_SENSORS: [],
|
CONF_SENSORS: [],
|
||||||
CONF_CUSTOM: {},
|
CONF_CUSTOM: {},
|
||||||
DEVICE_INFO: {},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async def async_step_user(
|
async def async_step_user(
|
||||||
@ -79,7 +78,7 @@ class SmaConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
|||||||
self._data[CONF_PASSWORD] = user_input[CONF_PASSWORD]
|
self._data[CONF_PASSWORD] = user_input[CONF_PASSWORD]
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self._data[DEVICE_INFO] = await validate_input(self.hass, user_input)
|
device_info = await validate_input(self.hass, user_input)
|
||||||
except aiohttp.ClientError:
|
except aiohttp.ClientError:
|
||||||
errors["base"] = "cannot_connect"
|
errors["base"] = "cannot_connect"
|
||||||
except InvalidAuth:
|
except InvalidAuth:
|
||||||
@ -91,7 +90,7 @@ class SmaConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
|||||||
errors["base"] = "unknown"
|
errors["base"] = "unknown"
|
||||||
|
|
||||||
if not errors:
|
if not errors:
|
||||||
await self.async_set_unique_id(self._data[DEVICE_INFO]["serial"])
|
await self.async_set_unique_id(device_info["serial"])
|
||||||
self._abort_if_unique_id_configured()
|
self._abort_if_unique_id_configured()
|
||||||
return self.async_create_entry(
|
return self.async_create_entry(
|
||||||
title=self._data[CONF_HOST], data=self._data
|
title=self._data[CONF_HOST], data=self._data
|
||||||
@ -120,7 +119,6 @@ class SmaConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
|||||||
) -> FlowResult:
|
) -> FlowResult:
|
||||||
"""Import a config flow from configuration."""
|
"""Import a config flow from configuration."""
|
||||||
device_info = await validate_input(self.hass, import_config)
|
device_info = await validate_input(self.hass, import_config)
|
||||||
import_config[DEVICE_INFO] = device_info
|
|
||||||
|
|
||||||
# If unique is configured import was already run
|
# If unique is configured import was already run
|
||||||
# This means remap was already done, so we can abort
|
# This means remap was already done, so we can abort
|
||||||
|
@ -6,6 +6,7 @@ PYSMA_COORDINATOR = "coordinator"
|
|||||||
PYSMA_OBJECT = "pysma"
|
PYSMA_OBJECT = "pysma"
|
||||||
PYSMA_REMOVE_LISTENER = "remove_listener"
|
PYSMA_REMOVE_LISTENER = "remove_listener"
|
||||||
PYSMA_SENSORS = "pysma_sensors"
|
PYSMA_SENSORS = "pysma_sensors"
|
||||||
|
PYSMA_DEVICE_INFO = "device_info"
|
||||||
|
|
||||||
PLATFORMS = ["sensor"]
|
PLATFORMS = ["sensor"]
|
||||||
|
|
||||||
@ -14,7 +15,6 @@ CONF_FACTOR = "factor"
|
|||||||
CONF_GROUP = "group"
|
CONF_GROUP = "group"
|
||||||
CONF_KEY = "key"
|
CONF_KEY = "key"
|
||||||
CONF_UNIT = "unit"
|
CONF_UNIT = "unit"
|
||||||
DEVICE_INFO = "device_info"
|
|
||||||
|
|
||||||
DEFAULT_SCAN_INTERVAL = 5
|
DEFAULT_SCAN_INTERVAL = 5
|
||||||
|
|
||||||
|
@ -33,10 +33,10 @@ from .const import (
|
|||||||
CONF_GROUP,
|
CONF_GROUP,
|
||||||
CONF_KEY,
|
CONF_KEY,
|
||||||
CONF_UNIT,
|
CONF_UNIT,
|
||||||
DEVICE_INFO,
|
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
GROUPS,
|
GROUPS,
|
||||||
PYSMA_COORDINATOR,
|
PYSMA_COORDINATOR,
|
||||||
|
PYSMA_DEVICE_INFO,
|
||||||
PYSMA_SENSORS,
|
PYSMA_SENSORS,
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -124,6 +124,7 @@ async def async_setup_entry(
|
|||||||
|
|
||||||
coordinator = sma_data[PYSMA_COORDINATOR]
|
coordinator = sma_data[PYSMA_COORDINATOR]
|
||||||
used_sensors = sma_data[PYSMA_SENSORS]
|
used_sensors = sma_data[PYSMA_SENSORS]
|
||||||
|
device_info = sma_data[PYSMA_DEVICE_INFO]
|
||||||
|
|
||||||
entities = []
|
entities = []
|
||||||
for sensor in used_sensors:
|
for sensor in used_sensors:
|
||||||
@ -131,7 +132,7 @@ async def async_setup_entry(
|
|||||||
SMAsensor(
|
SMAsensor(
|
||||||
coordinator,
|
coordinator,
|
||||||
config_entry.unique_id,
|
config_entry.unique_id,
|
||||||
config_entry.data[DEVICE_INFO],
|
device_info,
|
||||||
sensor,
|
sensor,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
@ -185,11 +186,15 @@ class SMAsensor(CoordinatorEntity, SensorEntity):
|
|||||||
@property
|
@property
|
||||||
def device_info(self) -> DeviceInfo:
|
def device_info(self) -> DeviceInfo:
|
||||||
"""Return the device information."""
|
"""Return the device information."""
|
||||||
|
if not self._device_info:
|
||||||
|
return None
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"identifiers": {(DOMAIN, self._config_entry_unique_id)},
|
"identifiers": {(DOMAIN, self._config_entry_unique_id)},
|
||||||
"name": self._device_info["name"],
|
"name": self._device_info["name"],
|
||||||
"manufacturer": self._device_info["manufacturer"],
|
"manufacturer": self._device_info["manufacturer"],
|
||||||
"model": self._device_info["type"],
|
"model": self._device_info["type"],
|
||||||
|
"sw_version": self._device_info["sw_version"],
|
||||||
}
|
}
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
@ -69,7 +69,6 @@ MOCK_CUSTOM_SENSOR2 = {
|
|||||||
MOCK_SETUP_DATA = dict(
|
MOCK_SETUP_DATA = dict(
|
||||||
{
|
{
|
||||||
"custom": {},
|
"custom": {},
|
||||||
"device_info": MOCK_DEVICE,
|
|
||||||
"sensors": [],
|
"sensors": [],
|
||||||
},
|
},
|
||||||
**MOCK_USER_INPUT,
|
**MOCK_USER_INPUT,
|
||||||
@ -91,7 +90,6 @@ MOCK_CUSTOM_SETUP_DATA = dict(
|
|||||||
"unit": MOCK_CUSTOM_SENSOR2["unit"],
|
"unit": MOCK_CUSTOM_SENSOR2["unit"],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"device_info": MOCK_DEVICE,
|
|
||||||
"sensors": [],
|
"sensors": [],
|
||||||
},
|
},
|
||||||
**MOCK_USER_INPUT,
|
**MOCK_USER_INPUT,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user