Skip to content

Commit

Permalink
add state_class config option
Browse files Browse the repository at this point in the history
  • Loading branch information
Bouni committed Mar 28, 2022
1 parent 03277f3 commit d8e21a5
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 11 deletions.
8 changes: 5 additions & 3 deletions custom_components/luxtronik/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@
vol.Required(CONF_PORT, default=8889): cv.port,
vol.Optional(CONF_SAFE, default=True): cv.boolean,
vol.Optional(CONF_LOCK_TIMEOUT, default=30): cv.positive_int,
vol.Optional(CONF_UPDATE_IMMEDIATELY_AFTER_WRITE, default=False): cv.boolean,
vol.Optional(
CONF_UPDATE_IMMEDIATELY_AFTER_WRITE, default=False
): cv.boolean,
}
)
},
Expand Down Expand Up @@ -123,7 +125,7 @@ def write(self, parameter, value, update_immediately_after_write):
"Couldn't write luxtronik parameter %s with value %s because of lock timeout %s",
parameter,
value,
self._lock_timeout_sec
self._lock_timeout_sec,
)
finally:
self.lock.release()
Expand All @@ -137,7 +139,7 @@ def update(self):
else:
_LOGGER.warning(
"Couldn't read luxtronik data because of lock timeout %s",
self._lock_timeout_sec
self._lock_timeout_sec,
)
finally:
self.lock.release()
1 change: 1 addition & 0 deletions custom_components/luxtronik/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
ATTR_PARAMETER = "parameter"
ATTR_VALUE = "value"

CONF_STATE_CLASS = "state_class"
CONF_INVERT_STATE = "invert"
CONF_SAFE = "safe"
CONF_GROUP = "group"
Expand Down
28 changes: 20 additions & 8 deletions custom_components/luxtronik/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,27 @@

import homeassistant.helpers.config_validation as cv
import voluptuous as vol
from homeassistant.components.sensor import PLATFORM_SCHEMA
from homeassistant.const import (CONF_FRIENDLY_NAME, CONF_ICON, CONF_ID,
CONF_SENSORS, CONF_STATE_CLASS)
from homeassistant.components.sensor import PLATFORM_SCHEMA, STATE_CLASSES_SCHEMA
from homeassistant.const import (
CONF_FRIENDLY_NAME,
CONF_ICON,
CONF_ID,
CONF_SENSORS,
)
from homeassistant.helpers.entity import Entity
from homeassistant.util import slugify

from . import DOMAIN, ENTITY_ID_FORMAT
from .const import (CONF_CALCULATIONS, CONF_GROUP, CONF_PARAMETERS,
CONF_VISIBILITIES, DEVICE_CLASSES, ICONS, UNITS)
from .const import (
CONF_CALCULATIONS,
CONF_GROUP,
CONF_PARAMETERS,
CONF_VISIBILITIES,
CONF_STATE_CLASS,
DEVICE_CLASSES,
ICONS,
UNITS,
)

_LOGGER = logging.getLogger(__name__)

Expand All @@ -31,7 +43,7 @@
vol.Required(CONF_ID): cv.string,
vol.Optional(CONF_FRIENDLY_NAME): cv.string,
vol.Optional(CONF_ICON): cv.string,
vol.Optional(CONF_STATE_CLASSS): cv.string,
vol.Optional(CONF_STATE_CLASS): STATE_CLASSES_SCHEMA,
}
],
)
Expand Down Expand Up @@ -110,10 +122,10 @@ def state(self):
@property
def state_class(self):
"""Return the state class of this sensor."""
if not self._state_class
if not self._state_class:
return DEFAULT_STATE_CLASS
return self._state_class

@property
def device_class(self):
"""Return the class of this sensor."""
Expand Down

0 comments on commit d8e21a5

Please sign in to comment.