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:
parent
536ad57bf4
commit
6d2fbeb556
6 changed files with 21 additions and 25 deletions
|
@ -22,7 +22,7 @@ from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
|
||||||
from . import ViCareRequiredKeysMixin
|
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
|
from .entity import ViCareEntity
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
@ -117,7 +117,7 @@ def _build_entity(name, vicare_api, device_config, sensor):
|
||||||
|
|
||||||
|
|
||||||
async def _entities_from_descriptions(
|
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."""
|
"""Create entities from descriptions and list of burners/circuits."""
|
||||||
for description in sensor_descriptions:
|
for description in sensor_descriptions:
|
||||||
|
@ -127,7 +127,7 @@ async def _entities_from_descriptions(
|
||||||
suffix = f" {current.id}"
|
suffix = f" {current.id}"
|
||||||
entity = await hass.async_add_executor_job(
|
entity = await hass.async_add_executor_job(
|
||||||
_build_entity,
|
_build_entity,
|
||||||
f"{name} {description.name}{suffix}",
|
f"{description.name}{suffix}",
|
||||||
current,
|
current,
|
||||||
hass.data[DOMAIN][config_entry.entry_id][VICARE_DEVICE_CONFIG],
|
hass.data[DOMAIN][config_entry.entry_id][VICARE_DEVICE_CONFIG],
|
||||||
description,
|
description,
|
||||||
|
@ -142,7 +142,6 @@ async def async_setup_entry(
|
||||||
async_add_entities: AddEntitiesCallback,
|
async_add_entities: AddEntitiesCallback,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Create the ViCare binary sensor devices."""
|
"""Create the ViCare binary sensor devices."""
|
||||||
name = VICARE_NAME
|
|
||||||
api = hass.data[DOMAIN][config_entry.entry_id][VICARE_API]
|
api = hass.data[DOMAIN][config_entry.entry_id][VICARE_API]
|
||||||
|
|
||||||
entities = []
|
entities = []
|
||||||
|
@ -150,7 +149,7 @@ async def async_setup_entry(
|
||||||
for description in GLOBAL_SENSORS:
|
for description in GLOBAL_SENSORS:
|
||||||
entity = await hass.async_add_executor_job(
|
entity = await hass.async_add_executor_job(
|
||||||
_build_entity,
|
_build_entity,
|
||||||
f"{name} {description.name}",
|
description.name,
|
||||||
api,
|
api,
|
||||||
hass.data[DOMAIN][config_entry.entry_id][VICARE_DEVICE_CONFIG],
|
hass.data[DOMAIN][config_entry.entry_id][VICARE_DEVICE_CONFIG],
|
||||||
description,
|
description,
|
||||||
|
@ -160,21 +159,21 @@ async def async_setup_entry(
|
||||||
|
|
||||||
try:
|
try:
|
||||||
await _entities_from_descriptions(
|
await _entities_from_descriptions(
|
||||||
hass, name, entities, CIRCUIT_SENSORS, api.circuits, config_entry
|
hass, entities, CIRCUIT_SENSORS, api.circuits, config_entry
|
||||||
)
|
)
|
||||||
except PyViCareNotSupportedFeatureError:
|
except PyViCareNotSupportedFeatureError:
|
||||||
_LOGGER.info("No circuits found")
|
_LOGGER.info("No circuits found")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
await _entities_from_descriptions(
|
await _entities_from_descriptions(
|
||||||
hass, name, entities, BURNER_SENSORS, api.burners, config_entry
|
hass, entities, BURNER_SENSORS, api.burners, config_entry
|
||||||
)
|
)
|
||||||
except PyViCareNotSupportedFeatureError:
|
except PyViCareNotSupportedFeatureError:
|
||||||
_LOGGER.info("No burners found")
|
_LOGGER.info("No burners found")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
await _entities_from_descriptions(
|
await _entities_from_descriptions(
|
||||||
hass, name, entities, COMPRESSOR_SENSORS, api.compressors, config_entry
|
hass, entities, COMPRESSOR_SENSORS, api.compressors, config_entry
|
||||||
)
|
)
|
||||||
except PyViCareNotSupportedFeatureError:
|
except PyViCareNotSupportedFeatureError:
|
||||||
_LOGGER.info("No compressors found")
|
_LOGGER.info("No compressors found")
|
||||||
|
|
|
@ -19,7 +19,7 @@ from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
|
||||||
from . import ViCareRequiredKeysMixinWithSet
|
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
|
from .entity import ViCareEntity
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
@ -73,7 +73,6 @@ async def async_setup_entry(
|
||||||
async_add_entities: AddEntitiesCallback,
|
async_add_entities: AddEntitiesCallback,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Create the ViCare button entities."""
|
"""Create the ViCare button entities."""
|
||||||
name = VICARE_NAME
|
|
||||||
api = hass.data[DOMAIN][config_entry.entry_id][VICARE_API]
|
api = hass.data[DOMAIN][config_entry.entry_id][VICARE_API]
|
||||||
|
|
||||||
entities = []
|
entities = []
|
||||||
|
@ -81,7 +80,7 @@ async def async_setup_entry(
|
||||||
for description in BUTTON_DESCRIPTIONS:
|
for description in BUTTON_DESCRIPTIONS:
|
||||||
entity = await hass.async_add_executor_job(
|
entity = await hass.async_add_executor_job(
|
||||||
_build_entity,
|
_build_entity,
|
||||||
f"{name} {description.name}",
|
description.name,
|
||||||
api,
|
api,
|
||||||
hass.data[DOMAIN][config_entry.entry_id][VICARE_DEVICE_CONFIG],
|
hass.data[DOMAIN][config_entry.entry_id][VICARE_DEVICE_CONFIG],
|
||||||
description,
|
description,
|
||||||
|
|
|
@ -35,7 +35,7 @@ from homeassistant.helpers import entity_platform
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
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
|
from .entity import ViCareEntity
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
@ -105,7 +105,6 @@ async def async_setup_entry(
|
||||||
async_add_entities: AddEntitiesCallback,
|
async_add_entities: AddEntitiesCallback,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Set up the ViCare climate platform."""
|
"""Set up the ViCare climate platform."""
|
||||||
name = VICARE_NAME
|
|
||||||
entities = []
|
entities = []
|
||||||
api = hass.data[DOMAIN][config_entry.entry_id][VICARE_API]
|
api = hass.data[DOMAIN][config_entry.entry_id][VICARE_API]
|
||||||
circuits = await hass.async_add_executor_job(_get_circuits, api)
|
circuits = await hass.async_add_executor_job(_get_circuits, api)
|
||||||
|
@ -116,7 +115,7 @@ async def async_setup_entry(
|
||||||
suffix = f" {circuit.id}"
|
suffix = f" {circuit.id}"
|
||||||
|
|
||||||
entity = ViCareClimate(
|
entity = ViCareClimate(
|
||||||
f"{name} Heating{suffix}",
|
f"Heating{suffix}",
|
||||||
api,
|
api,
|
||||||
circuit,
|
circuit,
|
||||||
hass.data[DOMAIN][config_entry.entry_id][VICARE_DEVICE_CONFIG],
|
hass.data[DOMAIN][config_entry.entry_id][VICARE_DEVICE_CONFIG],
|
||||||
|
|
|
@ -8,6 +8,8 @@ from .const import DOMAIN
|
||||||
class ViCareEntity(Entity):
|
class ViCareEntity(Entity):
|
||||||
"""Base class for ViCare entities."""
|
"""Base class for ViCare entities."""
|
||||||
|
|
||||||
|
_attr_has_entity_name = True
|
||||||
|
|
||||||
def __init__(self, device_config) -> None:
|
def __init__(self, device_config) -> None:
|
||||||
"""Initialize the entity."""
|
"""Initialize the entity."""
|
||||||
|
|
||||||
|
|
|
@ -39,7 +39,6 @@ from .const import (
|
||||||
VICARE_CUBIC_METER,
|
VICARE_CUBIC_METER,
|
||||||
VICARE_DEVICE_CONFIG,
|
VICARE_DEVICE_CONFIG,
|
||||||
VICARE_KWH,
|
VICARE_KWH,
|
||||||
VICARE_NAME,
|
|
||||||
VICARE_UNIT_TO_UNIT_OF_MEASUREMENT,
|
VICARE_UNIT_TO_UNIT_OF_MEASUREMENT,
|
||||||
)
|
)
|
||||||
from .entity import ViCareEntity
|
from .entity import ViCareEntity
|
||||||
|
@ -596,7 +595,7 @@ def _build_entity(name, vicare_api, device_config, sensor):
|
||||||
|
|
||||||
|
|
||||||
async def _entities_from_descriptions(
|
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."""
|
"""Create entities from descriptions and list of burners/circuits."""
|
||||||
for description in sensor_descriptions:
|
for description in sensor_descriptions:
|
||||||
|
@ -606,7 +605,7 @@ async def _entities_from_descriptions(
|
||||||
suffix = f" {current.id}"
|
suffix = f" {current.id}"
|
||||||
entity = await hass.async_add_executor_job(
|
entity = await hass.async_add_executor_job(
|
||||||
_build_entity,
|
_build_entity,
|
||||||
f"{name} {description.name}{suffix}",
|
f"{description.name}{suffix}",
|
||||||
current,
|
current,
|
||||||
hass.data[DOMAIN][config_entry.entry_id][VICARE_DEVICE_CONFIG],
|
hass.data[DOMAIN][config_entry.entry_id][VICARE_DEVICE_CONFIG],
|
||||||
description,
|
description,
|
||||||
|
@ -621,14 +620,13 @@ async def async_setup_entry(
|
||||||
async_add_entities: AddEntitiesCallback,
|
async_add_entities: AddEntitiesCallback,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Create the ViCare sensor devices."""
|
"""Create the ViCare sensor devices."""
|
||||||
name = VICARE_NAME
|
|
||||||
api = hass.data[DOMAIN][config_entry.entry_id][VICARE_API]
|
api = hass.data[DOMAIN][config_entry.entry_id][VICARE_API]
|
||||||
|
|
||||||
entities = []
|
entities = []
|
||||||
for description in GLOBAL_SENSORS:
|
for description in GLOBAL_SENSORS:
|
||||||
entity = await hass.async_add_executor_job(
|
entity = await hass.async_add_executor_job(
|
||||||
_build_entity,
|
_build_entity,
|
||||||
f"{name} {description.name}",
|
description.name,
|
||||||
api,
|
api,
|
||||||
hass.data[DOMAIN][config_entry.entry_id][VICARE_DEVICE_CONFIG],
|
hass.data[DOMAIN][config_entry.entry_id][VICARE_DEVICE_CONFIG],
|
||||||
description,
|
description,
|
||||||
|
@ -638,21 +636,21 @@ async def async_setup_entry(
|
||||||
|
|
||||||
try:
|
try:
|
||||||
await _entities_from_descriptions(
|
await _entities_from_descriptions(
|
||||||
hass, name, entities, CIRCUIT_SENSORS, api.circuits, config_entry
|
hass, entities, CIRCUIT_SENSORS, api.circuits, config_entry
|
||||||
)
|
)
|
||||||
except PyViCareNotSupportedFeatureError:
|
except PyViCareNotSupportedFeatureError:
|
||||||
_LOGGER.info("No circuits found")
|
_LOGGER.info("No circuits found")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
await _entities_from_descriptions(
|
await _entities_from_descriptions(
|
||||||
hass, name, entities, BURNER_SENSORS, api.burners, config_entry
|
hass, entities, BURNER_SENSORS, api.burners, config_entry
|
||||||
)
|
)
|
||||||
except PyViCareNotSupportedFeatureError:
|
except PyViCareNotSupportedFeatureError:
|
||||||
_LOGGER.info("No burners found")
|
_LOGGER.info("No burners found")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
await _entities_from_descriptions(
|
await _entities_from_descriptions(
|
||||||
hass, name, entities, COMPRESSOR_SENSORS, api.compressors, config_entry
|
hass, entities, COMPRESSOR_SENSORS, api.compressors, config_entry
|
||||||
)
|
)
|
||||||
except PyViCareNotSupportedFeatureError:
|
except PyViCareNotSupportedFeatureError:
|
||||||
_LOGGER.info("No compressors found")
|
_LOGGER.info("No compressors found")
|
||||||
|
|
|
@ -19,7 +19,7 @@ from homeassistant.const import ATTR_TEMPERATURE, PRECISION_TENTHS, UnitOfTemper
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
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
|
from .entity import ViCareEntity
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
@ -69,7 +69,6 @@ async def async_setup_entry(
|
||||||
async_add_entities: AddEntitiesCallback,
|
async_add_entities: AddEntitiesCallback,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Set up the ViCare climate platform."""
|
"""Set up the ViCare climate platform."""
|
||||||
name = VICARE_NAME
|
|
||||||
entities = []
|
entities = []
|
||||||
api = hass.data[DOMAIN][config_entry.entry_id][VICARE_API]
|
api = hass.data[DOMAIN][config_entry.entry_id][VICARE_API]
|
||||||
circuits = await hass.async_add_executor_job(_get_circuits, api)
|
circuits = await hass.async_add_executor_job(_get_circuits, api)
|
||||||
|
@ -80,7 +79,7 @@ async def async_setup_entry(
|
||||||
suffix = f" {circuit.id}"
|
suffix = f" {circuit.id}"
|
||||||
|
|
||||||
entity = ViCareWater(
|
entity = ViCareWater(
|
||||||
f"{name} Water{suffix}",
|
f"Water{suffix}",
|
||||||
api,
|
api,
|
||||||
circuit,
|
circuit,
|
||||||
hass.data[DOMAIN][config_entry.entry_id][VICARE_DEVICE_CONFIG],
|
hass.data[DOMAIN][config_entry.entry_id][VICARE_DEVICE_CONFIG],
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue