Skip to content

Commit

Permalink
Merge pull request #11 from jaroschek/feature/cleanup
Browse files Browse the repository at this point in the history
Cleanup unnecessary code for config entry migration
  • Loading branch information
jaroschek committed Feb 8, 2024
2 parents fcb82c5 + 72eaf31 commit 3fdff89
Showing 1 changed file with 1 addition and 32 deletions.
33 changes: 1 addition & 32 deletions custom_components/eaton_ups/__init__.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,13 @@
"""The Eaton UPS integration."""
from __future__ import annotations

import logging

from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
from homeassistant.helpers.typing import ConfigType

from .api import SnmpApi
from .const import (
DOMAIN,
PLATFORMS,
SNMP_OID_IDENT_PRODUCT_NAME,
SNMP_OID_IDENT_SERIAL_NUMBER,
)
from .const import DOMAIN, PLATFORMS
from .coordinator import SnmpCoordinator

_LOGGER = logging.getLogger(__name__)


async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
"""Set up Eaton UPS."""
Expand All @@ -44,24 +34,3 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
hass.data[DOMAIN].pop(entry.entry_id)

return unload_ok


async def async_migrate_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Migrate old entry."""
_LOGGER.debug("Migrating from version %s", entry.version)

if entry.version == 1:
api = SnmpApi(entry.data)
result = api.get([SNMP_OID_IDENT_PRODUCT_NAME, SNMP_OID_IDENT_SERIAL_NUMBER])

hass.config_entries.async_update_entry(
entry,
unique_id=result.get(SNMP_OID_IDENT_SERIAL_NUMBER),
title=result.get(SNMP_OID_IDENT_PRODUCT_NAME),
)

entry.version = 2

_LOGGER.info("Migration to version %s successful", entry.version)

return True

0 comments on commit 3fdff89

Please sign in to comment.