-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from dwradcliffe/chlorine_output
add number entity for chlorinator output
- Loading branch information
Showing
5 changed files
with
121 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
"""Pentair Intellicenter numbers.""" | ||
|
||
import logging | ||
from typing import Optional | ||
|
||
from homeassistant.components.number import ( | ||
NumberEntity, | ||
DEFAULT_MIN_VALUE, | ||
DEFAULT_MAX_VALUE, | ||
DEFAULT_STEP, | ||
) | ||
from homeassistant.config_entries import ConfigEntry | ||
from homeassistant.helpers.typing import HomeAssistantType | ||
|
||
from . import PoolEntity | ||
from .const import CONST_RPM, DOMAIN | ||
from homeassistant.const import PERCENTAGE | ||
from .pyintellicenter import ( | ||
CHEM_TYPE, | ||
PRIM_ATTR, | ||
ModelController, | ||
PoolObject, | ||
) | ||
|
||
_LOGGER = logging.getLogger(__name__) | ||
|
||
# ------------------------------------------------------------------------------------- | ||
|
||
|
||
async def async_setup_entry( | ||
hass: HomeAssistantType, entry: ConfigEntry, async_add_entities | ||
): | ||
"""Load pool numbers based on a config entry.""" | ||
|
||
controller: ModelController = hass.data[DOMAIN][entry.entry_id].controller | ||
|
||
numbers = [] | ||
|
||
object: PoolObject | ||
for object in controller.model.objectList: | ||
if ( | ||
object.objtype == CHEM_TYPE | ||
and object.subtype == "ICHLOR" | ||
and PRIM_ATTR in object.attributes | ||
): | ||
numbers.append( | ||
PoolNumber( | ||
entry, | ||
controller, | ||
object, | ||
unit_of_measurement=PERCENTAGE, | ||
attribute_key=PRIM_ATTR, | ||
name="+ Output %", | ||
icon="mdi:gauge", | ||
) | ||
) | ||
async_add_entities(numbers) | ||
|
||
|
||
# ------------------------------------------------------------------------------------- | ||
|
||
|
||
class PoolNumber(PoolEntity, NumberEntity): | ||
"""Representation of a number.""" | ||
|
||
def __init__( | ||
self, | ||
entry: ConfigEntry, | ||
controller: ModelController, | ||
poolObject: PoolObject, | ||
min_value: float = DEFAULT_MIN_VALUE, | ||
max_value: float = DEFAULT_MAX_VALUE, | ||
step: float = DEFAULT_STEP, | ||
**kwargs, | ||
): | ||
"""Initialize.""" | ||
super().__init__(entry, controller, poolObject, **kwargs) | ||
self._min_value = min_value | ||
self._max_value = max_value | ||
self._step = step | ||
|
||
@property | ||
def min_value(self) -> float: | ||
"""Return the minimum value.""" | ||
return self._min_value | ||
|
||
@property | ||
def max_value(self) -> float: | ||
"""Return the maximum value.""" | ||
return self._max_value | ||
|
||
@property | ||
def step(self) -> float: | ||
"""Return the increment/decrement step.""" | ||
return self._step | ||
|
||
@property | ||
def value(self) -> float: | ||
"""Return the current value.""" | ||
return self._poolObject[self._attribute_key] | ||
|
||
def set_value(self, value: float) -> None: | ||
"""Update the current value.""" | ||
changes = {self._attribute_key: str(int(value))} | ||
self.requestChanges(changes) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters