Skip to content

Commit

Permalink
Merge pull request #7 from jaroschek/release/1.1.0
Browse files Browse the repository at this point in the history
Update version to 1.1.0
  • Loading branch information
jaroschek committed Jan 19, 2024
2 parents f55aa01 + 82c1442 commit 4349d40
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
33 changes: 32 additions & 1 deletion custom_components/eaton_ups/__init__.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
"""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 .const import DOMAIN, PLATFORMS
from .api import SnmpApi
from .const import (
DOMAIN,
PLATFORMS,
SNMP_OID_IDENT_PRODUCT_NAME,
SNMP_OID_IDENT_SERIAL_NUMBER,
)
from .coordinator import SnmpCoordinator

_LOGGER = logging.getLogger(__name__)


async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
"""Set up Eaton UPS."""
Expand All @@ -34,3 +44,24 @@ 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
2 changes: 1 addition & 1 deletion custom_components/eaton_ups/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
"issue_tracker": "https://github.com/jaroschek/home-assistant-eaton-ups/issues",
"requirements": ["pysnmplib==5.0.21"],
"ssdp": [],
"version": "1.0.0",
"version": "1.1.0",
"zeroconf": []
}

0 comments on commit 4349d40

Please sign in to comment.