fix cdestyle findings

This commit is contained in:
Christopher Fenner
2023-10-06 09:23:22 +02:00
parent 3c0f19b990
commit d846584bf7
5 changed files with 63 additions and 12 deletions

View File

@@ -93,11 +93,15 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
class ViCareEntity(Entity):
"""Base class for ViCare entities."""
def __init__(self, device_config, has_multiple_devices: bool) -> None:
"""Initialize the entity."""
device_name = device_config.getModel()
if has_multiple_devices:
device_name = f"{device_config.getModel()}-{device_config.getConfig().serial}"
device_name = (
f"{device_config.getModel()}-{device_config.getConfig().serial}"
)
self._attr_device_info = DeviceInfo(
identifiers={(DOMAIN, device_config.getConfig().serial)},

View File

@@ -174,21 +174,36 @@ async def async_setup_entry(
try:
await _entities_from_descriptions(
hass, entities, CIRCUIT_SENSORS, api.circuits, device, has_multiple_devices
hass,
entities,
CIRCUIT_SENSORS,
api.circuits,
device,
has_multiple_devices,
)
except PyViCareNotSupportedFeatureError:
_LOGGER.info("No circuits found")
try:
await _entities_from_descriptions(
hass, entities, BURNER_SENSORS, api.burners, device, has_multiple_devices
hass,
entities,
BURNER_SENSORS,
api.burners,
device,
has_multiple_devices,
)
except PyViCareNotSupportedFeatureError:
_LOGGER.info("No burners found")
try:
await _entities_from_descriptions(
hass, entities, COMPRESSOR_SENSORS, api.compressors, device, has_multiple_devices
hass,
entities,
COMPRESSOR_SENSORS,
api.compressors,
device,
has_multiple_devices,
)
except PyViCareNotSupportedFeatureError:
_LOGGER.info("No compressors found")
@@ -203,7 +218,12 @@ class ViCareBinarySensor(ViCareEntity, BinarySensorEntity):
entity_description: ViCareBinarySensorEntityDescription
def __init__(
self, name, api, device_config, description: ViCareBinarySensorEntityDescription, has_multiple_devices: bool
self,
name,
api,
device_config,
description: ViCareBinarySensorEntityDescription,
has_multiple_devices: bool,
) -> None:
"""Initialize the sensor."""
self.entity_description = description

View File

@@ -51,7 +51,9 @@ BUTTON_DESCRIPTIONS: tuple[ViCareButtonEntityDescription, ...] = (
)
def _build_entity(name, vicare_api, device_config, description, has_multiple_devices: bool):
def _build_entity(
name, vicare_api, device_config, description, has_multiple_devices: bool
):
"""Create a ViCare button entity."""
_LOGGER.debug("Found device %s", name)
try:
@@ -113,7 +115,12 @@ class ViCareButton(ViCareEntity, ButtonEntity):
entity_description: ViCareButtonEntityDescription
def __init__(
self, name, api, device_config, description: ViCareButtonEntityDescription, has_multiple_devices: bool
self,
name,
api,
device_config,
description: ViCareButtonEntityDescription,
has_multiple_devices: bool,
) -> None:
"""Initialize the button."""
self.entity_description = description

View File

@@ -648,21 +648,36 @@ async def async_setup_entry(
try:
await _entities_from_descriptions(
hass, entities, CIRCUIT_SENSORS, api.circuits, device, has_multiple_devices
hass,
entities,
CIRCUIT_SENSORS,
api.circuits,
device,
has_multiple_devices,
)
except PyViCareNotSupportedFeatureError:
_LOGGER.info("No circuits found")
try:
await _entities_from_descriptions(
hass, entities, BURNER_SENSORS, api.burners, device, has_multiple_devices
hass,
entities,
BURNER_SENSORS,
api.burners,
device,
has_multiple_devices,
)
except PyViCareNotSupportedFeatureError:
_LOGGER.info("No burners found")
try:
await _entities_from_descriptions(
hass, entities, COMPRESSOR_SENSORS, api.compressors, device, has_multiple_devices
hass,
entities,
COMPRESSOR_SENSORS,
api.compressors,
device,
has_multiple_devices,
)
except PyViCareNotSupportedFeatureError:
_LOGGER.info("No compressors found")
@@ -677,7 +692,12 @@ class ViCareSensor(ViCareEntity, SensorEntity):
entity_description: ViCareSensorEntityDescription
def __init__(
self, name, api, device_config, description: ViCareSensorEntityDescription, has_multiple_devices: bool
self,
name,
api,
device_config,
description: ViCareSensorEntityDescription,
has_multiple_devices: bool,
) -> None:
"""Initialize the sensor."""
self.entity_description = description

View File

@@ -97,7 +97,7 @@ async def async_setup_entry(
api,
circuit,
device,
has_multiple_devices,
has_multiple_devices,
)
entities.append(entity)