Skip to content

Commit

Permalink
Revert number fix for next release
Browse files Browse the repository at this point in the history
  • Loading branch information
dannerph authored Jun 20, 2022
1 parent 8e70559 commit 1b8cae2
Showing 1 changed file with 22 additions and 13 deletions.
35 changes: 22 additions & 13 deletions custom_components/keba/number.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
"""Number entities for keba."""

from keba_kecontact.connection import KebaKeContact
from keba_kecontact.wallbox import Wallbox

from homeassistant.components.number import NumberEntity, NumberEntityDescription
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import CONF_HOST, ELECTRIC_CURRENT_AMPERE
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback

from homeassistant.const import ELECTRIC_CURRENT_AMPERE, CONF_HOST

from . import KebaBaseEntity
from .const import DOMAIN, KEBA_CONNECTION

from keba_kecontact.connection import KebaKeContact
from keba_kecontact.wallbox import Wallbox


async def async_setup_entry(
hass: HomeAssistant,
Expand All @@ -26,17 +27,14 @@ async def async_setup_entry(
number_description = NumberEntityDescription(
key="Curr user",
name="Charging current",
native_unit_of_measurement=ELECTRIC_CURRENT_AMPERE,
native_min_value=6, # technical minimum
native_max_value=63, # technical maximum
native_step=1, # tehcnically possible step
unit_of_measurement=ELECTRIC_CURRENT_AMPERE,
)
entities.extend([KebaNumber(wallbox, number_description)])
async_add_entities(entities, True)


class KebaNumber(KebaBaseEntity, NumberEntity):
"""Representation of a keba Number entity."""
"""Representation of a MusicCast Number entity."""

def __init__(
self,
Expand All @@ -45,12 +43,23 @@ def __init__(
) -> None:
"""Initialize the number entity."""
super().__init__(wallbox, description)
self._attr_min_value = 6
self._attr_max_value = (
63
if self._wallbox.get_value("Curr HW") is None
else self._wallbox.get_value("Curr HW")
)
self._attr_step = 1

@property
def value(self):
"""Return the current value."""
return self._wallbox.get_value(self.entity_description.key)

async def async_update(self):
"""Update the number with latest cached states from the device."""
self._attr_native_max_value = self._wallbox.get_value("Curr HW")
self._attr_native_value = self._wallbox.get_value(self.entity_description.key)
"""Get latest cached states from the device."""
self._attr_max_value = self._wallbox.get_value("Curr HW")

async def async_set_native_value(self, value: float) -> None:
async def async_set_value(self, value: float):
"""Set a new value."""
await self._wallbox.set_current(value)

0 comments on commit 1b8cae2

Please sign in to comment.