Skip to content

Commit

Permalink
Merge pull request #137 from Snuffy2/Fix-Suggested-Unit-of-Measuremen…
Browse files Browse the repository at this point in the history
…t-ValueError

Fix Suggested Unit of Measurement ValueError
  • Loading branch information
enkama authored Oct 31, 2024
2 parents d2e9195 + 9332b25 commit 0580439
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions custom_components/variable/sensor.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
from collections.abc import MutableMapping
import copy
import logging
from collections.abc import MutableMapping

import homeassistant.helpers.entity_registry as er
import voluptuous as vol
from homeassistant.components.sensor import (
CONF_STATE_CLASS,
PLATFORM_SCHEMA,
UNIT_CONVERTERS,
RestoreSensor,
)
from homeassistant.config_entries import ConfigEntry
Expand All @@ -19,11 +22,10 @@
Platform,
)
from homeassistant.core import HomeAssistant
from homeassistant.helpers import config_validation as cv, entity_platform
from homeassistant.helpers import config_validation as cv
from homeassistant.helpers import entity_platform
from homeassistant.helpers.entity import generate_entity_id
import homeassistant.helpers.entity_registry as er
from homeassistant.util import slugify
import voluptuous as vol

from .const import (
ATTR_ATTRIBUTES,
Expand Down Expand Up @@ -156,7 +158,7 @@ def __init__(
self._value_type = config.get(CONF_VALUE_TYPE)
self._attr_device_class = config.get(CONF_DEVICE_CLASS)
self._attr_native_unit_of_measurement = config.get(CONF_UNIT_OF_MEASUREMENT)
self._attr_suggested_unit_of_measurement = config.get(CONF_UNIT_OF_MEASUREMENT)
self._attr_suggested_unit_of_measurement = None
self._attr_state_class = config.get(CONF_STATE_CLASS)
if (
config.get(CONF_ATTRIBUTES) is not None
Expand All @@ -180,6 +182,10 @@ def __init__(
)
except ValueError:
self._attr_native_value = None
if config.get(CONF_DEVICE_CLASS) in UNIT_CONVERTERS:
self._attr_suggested_unit_of_measurement = config.get(
CONF_UNIT_OF_MEASUREMENT
)

# _LOGGER.debug(f"({self._attr_name}) [init] unrecorded_attributes: {self._unrecorded_attributes}")

Expand Down

0 comments on commit 0580439

Please sign in to comment.