Skip to content

Commit

Permalink
Address late V2C review comments (#103808)
Browse files Browse the repository at this point in the history
* address review

* missing fixture
  • Loading branch information
dgomes committed Nov 12, 2023
1 parent 6a7e87f commit b9bc6ca
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 17 deletions.
4 changes: 2 additions & 2 deletions homeassistant/components/v2c/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ async def _async_update_data(self) -> TrydanData:
"""Fetch sensor data from api."""
try:
data: TrydanData = await self.evse.get_data()
_LOGGER.debug("Received data: %s", data)
return data
except TrydanError as err:
raise UpdateFailed(f"Error communicating with API: {err}") from err
_LOGGER.debug("Received data: %s", data)
return data
2 changes: 1 addition & 1 deletion homeassistant/components/v2c/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def __init__(
super().__init__(coordinator)

self._attr_device_info = DeviceInfo(
identifiers={(DOMAIN, coordinator.evse.host)},
identifiers={(DOMAIN, coordinator.config_entry.entry_id)},
manufacturer="V2C",
model="Trydan",
name=coordinator.name,
Expand Down
5 changes: 2 additions & 3 deletions homeassistant/components/v2c/number.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,10 @@ async def async_setup_entry(
"""Set up V2C Trydan number platform."""
coordinator: V2CUpdateCoordinator = hass.data[DOMAIN][config_entry.entry_id]

entities: list[NumberEntity] = [
async_add_entities(
V2CSettingsNumberEntity(coordinator, description, config_entry.entry_id)
for description in TRYDAN_NUMBER_SETTINGS
]
async_add_entities(entities)
)


class V2CSettingsNumberEntity(V2CBaseEntity, NumberEntity):
Expand Down
6 changes: 2 additions & 4 deletions homeassistant/components/v2c/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import UnitOfEnergy, UnitOfPower, UnitOfTime
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity import Entity
from homeassistant.helpers.entity_platform import AddEntitiesCallback

from .const import DOMAIN
Expand Down Expand Up @@ -90,11 +89,10 @@ async def async_setup_entry(
"""Set up V2C sensor platform."""
coordinator: V2CUpdateCoordinator = hass.data[DOMAIN][config_entry.entry_id]

entities: list[Entity] = [
async_add_entities(
V2CSensorBaseEntity(coordinator, description, config_entry.entry_id)
for description in TRYDAN_SENSORS
]
async_add_entities(entities)
)


class V2CSensorBaseEntity(V2CBaseEntity, SensorEntity):
Expand Down
3 changes: 0 additions & 3 deletions homeassistant/components/v2c/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@
"error": {
"cannot_connect": "[%key:common::config_flow::error::cannot_connect%]",
"unknown": "[%key:common::config_flow::error::unknown%]"
},
"abort": {
"already_configured": "[%key:common::config_flow::abort::already_configured_device%]"
}
},
"entity": {
Expand Down
5 changes: 2 additions & 3 deletions homeassistant/components/v2c/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,10 @@ async def async_setup_entry(
"""Set up V2C switch platform."""
coordinator: V2CUpdateCoordinator = hass.data[DOMAIN][config_entry.entry_id]

entities: list[SwitchEntity] = [
async_add_entities(
V2CSwitchEntity(coordinator, description, config_entry.entry_id)
for description in TRYDAN_SWITCHES
]
async_add_entities(entities)
)


class V2CSwitchEntity(V2CBaseEntity, SwitchEntity):
Expand Down
2 changes: 1 addition & 1 deletion tests/components/v2c/test_config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ async def test_form(hass: HomeAssistant, mock_setup_entry: AsyncMock) -> None:
],
)
async def test_form_cannot_connect(
hass: HomeAssistant, side_effect: Exception, error: str
hass: HomeAssistant, mock_setup_entry: AsyncMock, side_effect: Exception, error: str
) -> None:
"""Test we handle cannot connect error."""
result = await hass.config_entries.flow.async_init(
Expand Down

0 comments on commit b9bc6ca

Please sign in to comment.