Add flipr battery level sensor (#81389)
* Addition of battery level sensor. Correction of pylint errors * Review improvement for typing * Review improvement for typing * Correction following review
This commit is contained in:
parent
532c6b74d4
commit
c7dfd6b15a
7 changed files with 33 additions and 12 deletions
|
@ -45,7 +45,7 @@ class FliprBinarySensor(FliprEntity, BinarySensorEntity):
|
||||||
"""Representation of Flipr binary sensors."""
|
"""Representation of Flipr binary sensors."""
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_on(self):
|
def is_on(self) -> bool:
|
||||||
"""Return true if the binary sensor is on in case of a Problem is detected."""
|
"""Return true if the binary sensor is on in case of a Problem is detected."""
|
||||||
return (
|
return (
|
||||||
self.coordinator.data[self.entity_description.key] == "TooLow"
|
self.coordinator.data[self.entity_description.key] == "TooLow"
|
||||||
|
|
|
@ -9,6 +9,7 @@ import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant import config_entries
|
from homeassistant import config_entries
|
||||||
from homeassistant.const import CONF_EMAIL, CONF_PASSWORD
|
from homeassistant.const import CONF_EMAIL, CONF_PASSWORD
|
||||||
|
from homeassistant.data_entry_flow import FlowResult
|
||||||
|
|
||||||
from .const import CONF_FLIPR_ID, DOMAIN
|
from .const import CONF_FLIPR_ID, DOMAIN
|
||||||
|
|
||||||
|
@ -20,12 +21,14 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
||||||
|
|
||||||
VERSION = 1
|
VERSION = 1
|
||||||
|
|
||||||
_username: str | None = None
|
_username: str
|
||||||
_password: str | None = None
|
_password: str
|
||||||
_flipr_id: str | None = None
|
_flipr_id: str = ""
|
||||||
_possible_flipr_ids: list[str] | None = None
|
_possible_flipr_ids: list[str]
|
||||||
|
|
||||||
async def async_step_user(self, user_input=None):
|
async def async_step_user(
|
||||||
|
self, user_input: dict[str, str] | None = None
|
||||||
|
) -> FlowResult:
|
||||||
"""Handle the initial step."""
|
"""Handle the initial step."""
|
||||||
if user_input is None:
|
if user_input is None:
|
||||||
return self._show_setup_form()
|
return self._show_setup_form()
|
||||||
|
@ -92,7 +95,9 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
||||||
|
|
||||||
return flipr_ids
|
return flipr_ids
|
||||||
|
|
||||||
async def async_step_flipr_id(self, user_input=None):
|
async def async_step_flipr_id(
|
||||||
|
self, user_input: dict[str, str] | None = None
|
||||||
|
) -> FlowResult:
|
||||||
"""Handle the initial step."""
|
"""Handle the initial step."""
|
||||||
if not user_input:
|
if not user_input:
|
||||||
# Creation of a select with the proposal of flipr ids values found by API.
|
# Creation of a select with the proposal of flipr ids values found by API.
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
"name": "Flipr",
|
"name": "Flipr",
|
||||||
"config_flow": true,
|
"config_flow": true,
|
||||||
"documentation": "https://www.home-assistant.io/integrations/flipr",
|
"documentation": "https://www.home-assistant.io/integrations/flipr",
|
||||||
"requirements": ["flipr-api==1.4.2"],
|
"requirements": ["flipr-api==1.4.4"],
|
||||||
"codeowners": ["@cnico"],
|
"codeowners": ["@cnico"],
|
||||||
"iot_class": "cloud_polling",
|
"iot_class": "cloud_polling",
|
||||||
"loggers": ["flipr_api"]
|
"loggers": ["flipr_api"]
|
||||||
|
|
|
@ -8,7 +8,7 @@ from homeassistant.components.sensor import (
|
||||||
SensorStateClass,
|
SensorStateClass,
|
||||||
)
|
)
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import ELECTRIC_POTENTIAL_MILLIVOLT, TEMP_CELSIUS
|
from homeassistant.const import ELECTRIC_POTENTIAL_MILLIVOLT, PERCENTAGE, TEMP_CELSIUS
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
|
||||||
|
@ -48,6 +48,13 @@ SENSOR_TYPES: tuple[SensorEntityDescription, ...] = (
|
||||||
icon="mdi:pool",
|
icon="mdi:pool",
|
||||||
state_class=SensorStateClass.MEASUREMENT,
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
),
|
),
|
||||||
|
SensorEntityDescription(
|
||||||
|
key="battery",
|
||||||
|
name="Battery Level",
|
||||||
|
native_unit_of_measurement=PERCENTAGE,
|
||||||
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
|
device_class=SensorDeviceClass.BATTERY,
|
||||||
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -67,6 +74,6 @@ class FliprSensor(FliprEntity, SensorEntity):
|
||||||
"""Sensor representing FliprSensor data."""
|
"""Sensor representing FliprSensor data."""
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def native_value(self):
|
def native_value(self) -> str:
|
||||||
"""State of the sensor."""
|
"""State of the sensor."""
|
||||||
return self.coordinator.data[self.entity_description.key]
|
return self.coordinator.data[self.entity_description.key]
|
||||||
|
|
|
@ -705,7 +705,7 @@ fixerio==1.0.0a0
|
||||||
fjaraskupan==2.2.0
|
fjaraskupan==2.2.0
|
||||||
|
|
||||||
# homeassistant.components.flipr
|
# homeassistant.components.flipr
|
||||||
flipr-api==1.4.2
|
flipr-api==1.4.4
|
||||||
|
|
||||||
# homeassistant.components.flux_led
|
# homeassistant.components.flux_led
|
||||||
flux_led==0.28.32
|
flux_led==0.28.32
|
||||||
|
|
|
@ -527,7 +527,7 @@ fivem-api==0.1.2
|
||||||
fjaraskupan==2.2.0
|
fjaraskupan==2.2.0
|
||||||
|
|
||||||
# homeassistant.components.flipr
|
# homeassistant.components.flipr
|
||||||
flipr-api==1.4.2
|
flipr-api==1.4.4
|
||||||
|
|
||||||
# homeassistant.components.flux_led
|
# homeassistant.components.flux_led
|
||||||
flux_led==0.28.32
|
flux_led==0.28.32
|
||||||
|
|
|
@ -11,6 +11,7 @@ from homeassistant.const import (
|
||||||
ATTR_UNIT_OF_MEASUREMENT,
|
ATTR_UNIT_OF_MEASUREMENT,
|
||||||
CONF_EMAIL,
|
CONF_EMAIL,
|
||||||
CONF_PASSWORD,
|
CONF_PASSWORD,
|
||||||
|
PERCENTAGE,
|
||||||
TEMP_CELSIUS,
|
TEMP_CELSIUS,
|
||||||
)
|
)
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
|
@ -29,6 +30,7 @@ MOCK_FLIPR_MEASURE = {
|
||||||
"date_time": MOCK_DATE_TIME,
|
"date_time": MOCK_DATE_TIME,
|
||||||
"ph_status": "TooLow",
|
"ph_status": "TooLow",
|
||||||
"chlorine_status": "Medium",
|
"chlorine_status": "Medium",
|
||||||
|
"battery": 95.0,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -94,6 +96,13 @@ async def test_sensors(hass: HomeAssistant) -> None:
|
||||||
assert state.attributes.get(ATTR_STATE_CLASS) is SensorStateClass.MEASUREMENT
|
assert state.attributes.get(ATTR_STATE_CLASS) is SensorStateClass.MEASUREMENT
|
||||||
assert state.state == "0.23654886"
|
assert state.state == "0.23654886"
|
||||||
|
|
||||||
|
state = hass.states.get("sensor.flipr_myfliprid_battery_level")
|
||||||
|
assert state
|
||||||
|
assert state.attributes.get(ATTR_ICON) is None
|
||||||
|
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == PERCENTAGE
|
||||||
|
assert state.attributes.get(ATTR_STATE_CLASS) is SensorStateClass.MEASUREMENT
|
||||||
|
assert state.state == "95.0"
|
||||||
|
|
||||||
|
|
||||||
async def test_error_flipr_api_sensors(hass: HomeAssistant) -> None:
|
async def test_error_flipr_api_sensors(hass: HomeAssistant) -> None:
|
||||||
"""Test the Flipr sensors error."""
|
"""Test the Flipr sensors error."""
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue