Migrate ViCare to has_entity_name (#101895)

* set has_entity_name

* remove sensor prefix

* Apply suggestions from code review

Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>

---------

Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>
This commit is contained in:
Christopher Fenner 2023-10-12 21:06:09 +02:00 committed by GitHub
parent 536ad57bf4
commit 6d2fbeb556
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 21 additions and 25 deletions

View file

@ -22,7 +22,7 @@ from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from . import ViCareRequiredKeysMixin
from .const import DOMAIN, VICARE_API, VICARE_DEVICE_CONFIG, VICARE_NAME
from .const import DOMAIN, VICARE_API, VICARE_DEVICE_CONFIG
from .entity import ViCareEntity
_LOGGER = logging.getLogger(__name__)
@ -117,7 +117,7 @@ def _build_entity(name, vicare_api, device_config, sensor):
async def _entities_from_descriptions(
hass, name, entities, sensor_descriptions, iterables, config_entry
hass, entities, sensor_descriptions, iterables, config_entry
):
"""Create entities from descriptions and list of burners/circuits."""
for description in sensor_descriptions:
@ -127,7 +127,7 @@ async def _entities_from_descriptions(
suffix = f" {current.id}"
entity = await hass.async_add_executor_job(
_build_entity,
f"{name} {description.name}{suffix}",
f"{description.name}{suffix}",
current,
hass.data[DOMAIN][config_entry.entry_id][VICARE_DEVICE_CONFIG],
description,
@ -142,7 +142,6 @@ async def async_setup_entry(
async_add_entities: AddEntitiesCallback,
) -> None:
"""Create the ViCare binary sensor devices."""
name = VICARE_NAME
api = hass.data[DOMAIN][config_entry.entry_id][VICARE_API]
entities = []
@ -150,7 +149,7 @@ async def async_setup_entry(
for description in GLOBAL_SENSORS:
entity = await hass.async_add_executor_job(
_build_entity,
f"{name} {description.name}",
description.name,
api,
hass.data[DOMAIN][config_entry.entry_id][VICARE_DEVICE_CONFIG],
description,
@ -160,21 +159,21 @@ async def async_setup_entry(
try:
await _entities_from_descriptions(
hass, name, entities, CIRCUIT_SENSORS, api.circuits, config_entry
hass, entities, CIRCUIT_SENSORS, api.circuits, config_entry
)
except PyViCareNotSupportedFeatureError:
_LOGGER.info("No circuits found")
try:
await _entities_from_descriptions(
hass, name, entities, BURNER_SENSORS, api.burners, config_entry
hass, entities, BURNER_SENSORS, api.burners, config_entry
)
except PyViCareNotSupportedFeatureError:
_LOGGER.info("No burners found")
try:
await _entities_from_descriptions(
hass, name, entities, COMPRESSOR_SENSORS, api.compressors, config_entry
hass, entities, COMPRESSOR_SENSORS, api.compressors, config_entry
)
except PyViCareNotSupportedFeatureError:
_LOGGER.info("No compressors found")

View file

@ -19,7 +19,7 @@ from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from . import ViCareRequiredKeysMixinWithSet
from .const import DOMAIN, VICARE_API, VICARE_DEVICE_CONFIG, VICARE_NAME
from .const import DOMAIN, VICARE_API, VICARE_DEVICE_CONFIG
from .entity import ViCareEntity
_LOGGER = logging.getLogger(__name__)
@ -73,7 +73,6 @@ async def async_setup_entry(
async_add_entities: AddEntitiesCallback,
) -> None:
"""Create the ViCare button entities."""
name = VICARE_NAME
api = hass.data[DOMAIN][config_entry.entry_id][VICARE_API]
entities = []
@ -81,7 +80,7 @@ async def async_setup_entry(
for description in BUTTON_DESCRIPTIONS:
entity = await hass.async_add_executor_job(
_build_entity,
f"{name} {description.name}",
description.name,
api,
hass.data[DOMAIN][config_entry.entry_id][VICARE_DEVICE_CONFIG],
description,

View file

@ -35,7 +35,7 @@ from homeassistant.helpers import entity_platform
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from .const import DOMAIN, VICARE_API, VICARE_DEVICE_CONFIG, VICARE_NAME
from .const import DOMAIN, VICARE_API, VICARE_DEVICE_CONFIG
from .entity import ViCareEntity
_LOGGER = logging.getLogger(__name__)
@ -105,7 +105,6 @@ async def async_setup_entry(
async_add_entities: AddEntitiesCallback,
) -> None:
"""Set up the ViCare climate platform."""
name = VICARE_NAME
entities = []
api = hass.data[DOMAIN][config_entry.entry_id][VICARE_API]
circuits = await hass.async_add_executor_job(_get_circuits, api)
@ -116,7 +115,7 @@ async def async_setup_entry(
suffix = f" {circuit.id}"
entity = ViCareClimate(
f"{name} Heating{suffix}",
f"Heating{suffix}",
api,
circuit,
hass.data[DOMAIN][config_entry.entry_id][VICARE_DEVICE_CONFIG],

View file

@ -8,6 +8,8 @@ from .const import DOMAIN
class ViCareEntity(Entity):
"""Base class for ViCare entities."""
_attr_has_entity_name = True
def __init__(self, device_config) -> None:
"""Initialize the entity."""

View file

@ -39,7 +39,6 @@ from .const import (
VICARE_CUBIC_METER,
VICARE_DEVICE_CONFIG,
VICARE_KWH,
VICARE_NAME,
VICARE_UNIT_TO_UNIT_OF_MEASUREMENT,
)
from .entity import ViCareEntity
@ -596,7 +595,7 @@ def _build_entity(name, vicare_api, device_config, sensor):
async def _entities_from_descriptions(
hass, name, entities, sensor_descriptions, iterables, config_entry
hass, entities, sensor_descriptions, iterables, config_entry
):
"""Create entities from descriptions and list of burners/circuits."""
for description in sensor_descriptions:
@ -606,7 +605,7 @@ async def _entities_from_descriptions(
suffix = f" {current.id}"
entity = await hass.async_add_executor_job(
_build_entity,
f"{name} {description.name}{suffix}",
f"{description.name}{suffix}",
current,
hass.data[DOMAIN][config_entry.entry_id][VICARE_DEVICE_CONFIG],
description,
@ -621,14 +620,13 @@ async def async_setup_entry(
async_add_entities: AddEntitiesCallback,
) -> None:
"""Create the ViCare sensor devices."""
name = VICARE_NAME
api = hass.data[DOMAIN][config_entry.entry_id][VICARE_API]
entities = []
for description in GLOBAL_SENSORS:
entity = await hass.async_add_executor_job(
_build_entity,
f"{name} {description.name}",
description.name,
api,
hass.data[DOMAIN][config_entry.entry_id][VICARE_DEVICE_CONFIG],
description,
@ -638,21 +636,21 @@ async def async_setup_entry(
try:
await _entities_from_descriptions(
hass, name, entities, CIRCUIT_SENSORS, api.circuits, config_entry
hass, entities, CIRCUIT_SENSORS, api.circuits, config_entry
)
except PyViCareNotSupportedFeatureError:
_LOGGER.info("No circuits found")
try:
await _entities_from_descriptions(
hass, name, entities, BURNER_SENSORS, api.burners, config_entry
hass, entities, BURNER_SENSORS, api.burners, config_entry
)
except PyViCareNotSupportedFeatureError:
_LOGGER.info("No burners found")
try:
await _entities_from_descriptions(
hass, name, entities, COMPRESSOR_SENSORS, api.compressors, config_entry
hass, entities, COMPRESSOR_SENSORS, api.compressors, config_entry
)
except PyViCareNotSupportedFeatureError:
_LOGGER.info("No compressors found")

View file

@ -19,7 +19,7 @@ from homeassistant.const import ATTR_TEMPERATURE, PRECISION_TENTHS, UnitOfTemper
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from .const import DOMAIN, VICARE_API, VICARE_DEVICE_CONFIG, VICARE_NAME
from .const import DOMAIN, VICARE_API, VICARE_DEVICE_CONFIG
from .entity import ViCareEntity
_LOGGER = logging.getLogger(__name__)
@ -69,7 +69,6 @@ async def async_setup_entry(
async_add_entities: AddEntitiesCallback,
) -> None:
"""Set up the ViCare climate platform."""
name = VICARE_NAME
entities = []
api = hass.data[DOMAIN][config_entry.entry_id][VICARE_API]
circuits = await hass.async_add_executor_job(_get_circuits, api)
@ -80,7 +79,7 @@ async def async_setup_entry(
suffix = f" {circuit.id}"
entity = ViCareWater(
f"{name} Water{suffix}",
f"Water{suffix}",
api,
circuit,
hass.data[DOMAIN][config_entry.entry_id][VICARE_DEVICE_CONFIG],