Skip to content

Commit

Permalink
Fix for issue #25
Browse files Browse the repository at this point in the history
  • Loading branch information
gody01 committed Dec 14, 2024
1 parent da99196 commit 3d3d025
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 55 deletions.
50 changes: 4 additions & 46 deletions custom_components/ecovent_v2/__init__.py
Original file line number Diff line number Diff line change
@@ -1,34 +1,24 @@
"""The EcoVent_v2 integration."""
# from __future__ import annotations
from datetime import timedelta
import logging

from ecoventv2 import Fan

from homeassistant.config_entries import ConfigEntry
from homeassistant.const import (
CONF_DEVICE_ID,
CONF_IP_ADDRESS,
CONF_NAME,
CONF_PASSWORD,
CONF_PORT,
Platform,
)
from homeassistant.const import Platform
from homeassistant.core import HomeAssistant
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator

from .const import DOMAIN
from .coordinator import VentoFanDataUpdateCoordinator

_LOGGER = logging.getLogger(__name__)

# PLATFORMS: list[str] = ["sensor", "binary_sensor", "switch", "fan"]

PLATFORMS = [
PLATFORMS: list[Platform] = [
Platform.SENSOR,
Platform.BINARY_SENSOR,
Platform.SWITCH,
Platform.FAN,
Platform.NUMBER,
Platform.FAN,
]


Expand Down Expand Up @@ -56,35 +46,3 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS)

return unload_ok


class VentoFanDataUpdateCoordinator(DataUpdateCoordinator):
def __init__(
self,
hass: HomeAssistant,
config: ConfigEntry,
) -> None:
"""Initialize global Venstar data updater."""
self._fan = Fan(
config.data[CONF_IP_ADDRESS],
config.data[CONF_PASSWORD],
config.data[CONF_DEVICE_ID],
config.data[CONF_NAME],
config.data[CONF_PORT],
)
self._fan.init_device()

super().__init__(
hass,
_LOGGER,
name=DOMAIN,
update_interval=timedelta(seconds=60),
update_method=self._fan.update(),
)

async def _async_update_data(self) -> None:
"""Fetch data from API endpoint.
This is the place to pre-process the data to lookup tables
so entities can quickly look up their data.
"""
self._fan.update()
7 changes: 6 additions & 1 deletion custom_components/ecovent_v2/binary_sensor.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Vento fan binary sensors."""

from __future__ import annotations

from ecoventv2 import Fan
Expand All @@ -11,7 +12,11 @@
from homeassistant.core import HomeAssistant
from homeassistant.helpers.device_registry import DeviceInfo
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.update_coordinator import CoordinatorEntity
from homeassistant.helpers.update_coordinator import (
CoordinatorEntity,
DataUpdateCoordinator,
UpdateFailed,
)

from .const import DOMAIN
from .coordinator import VentoFanDataUpdateCoordinator
Expand Down
11 changes: 10 additions & 1 deletion custom_components/ecovent_v2/coordinator.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"""VentoUpdateCoordinator class."""

# from __future__ import annotations
from datetime import timedelta
import logging
Expand All @@ -13,14 +15,20 @@
CONF_PORT,
)
from homeassistant.core import HomeAssistant
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator
from homeassistant.helpers.update_coordinator import (
CoordinatorEntity,
DataUpdateCoordinator,
UpdateFailed,
)

from .const import DOMAIN

_LOGGER = logging.getLogger(__name__)


class VentoFanDataUpdateCoordinator(DataUpdateCoordinator):
"""Class for Vento Fan Update Coordinator."""

def __init__(
self,
hass: HomeAssistant,
Expand All @@ -46,6 +54,7 @@ def __init__(

async def _async_update_data(self) -> None:
"""Fetch data from API endpoint.
This is the place to pre-process the data to lookup tables
so entities can quickly look up their data.
"""
Expand Down
17 changes: 12 additions & 5 deletions custom_components/ecovent_v2/fan.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,17 @@
from homeassistant.core import HomeAssistant
from homeassistant.helpers import entity_platform
from homeassistant.helpers.device_registry import DeviceInfo
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.update_coordinator import CoordinatorEntity

from .const import DOMAIN, SERVICE_FILTER_TIMER_RESET, SERVICE_RESET_ALARMS
from .const import SERVICE_FILTER_TIMER_RESET
from .const import SERVICE_RESET_ALARMS
from .const import DOMAIN
from .coordinator import VentoFanDataUpdateCoordinator

# _LOGGER = logging.getLogger(__name__)
from homeassistant.helpers.update_coordinator import (
CoordinatorEntity,
DataUpdateCoordinator,
UpdateFailed,
)


DEFAULT_ON_PERCENTAGE = 5
SPEED_RANGE = (1, 3) # off is not included
Expand All @@ -25,8 +29,11 @@
| FanEntityFeature.PRESET_MODE
| FanEntityFeature.OSCILLATE
| FanEntityFeature.DIRECTION
| FanEntityFeature.TURN_OFF
| FanEntityFeature.TURN_ON
)


PRESET_MODES = ["low", "medium", "high", "manual"]
DIRECTIONS = ["ventilation", "air_supply", "heat_recovery"]

Expand Down
2 changes: 1 addition & 1 deletion custom_components/ecovent_v2/manifest.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"domain": "ecovent_v2",
"name": "Vento Eco Vent v 2.0",
"version": "1.0.1",
"codeowners": ["@gody01"],
"version": "1.0.2",
"config_flow": true,
"documentation": "https://www.home-assistant.io/integrations/ecovent_v2",
"iot_class": "local_polling",
Expand Down
2 changes: 1 addition & 1 deletion custom_components/ecovent_v2/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ def __init__(
self._attr_icon = icon
self._attr_device_info = DeviceInfo(
identifiers={(DOMAIN, self._fan.id)},
name=name,
name=self._fan.name,
)

@property
Expand Down

0 comments on commit 3d3d025

Please sign in to comment.