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:
cnico 2022-11-16 09:42:31 +01:00 committed by GitHub
parent 532c6b74d4
commit c7dfd6b15a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 33 additions and 12 deletions

View File

@ -45,7 +45,7 @@ class FliprBinarySensor(FliprEntity, BinarySensorEntity):
"""Representation of Flipr binary sensors."""
@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 (
self.coordinator.data[self.entity_description.key] == "TooLow"

View File

@ -9,6 +9,7 @@ import voluptuous as vol
from homeassistant import config_entries
from homeassistant.const import CONF_EMAIL, CONF_PASSWORD
from homeassistant.data_entry_flow import FlowResult
from .const import CONF_FLIPR_ID, DOMAIN
@ -20,12 +21,14 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
VERSION = 1
_username: str | None = None
_password: str | None = None
_flipr_id: str | None = None
_possible_flipr_ids: list[str] | None = None
_username: str
_password: str
_flipr_id: str = ""
_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."""
if user_input is None:
return self._show_setup_form()
@ -92,7 +95,9 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
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."""
if not user_input:
# Creation of a select with the proposal of flipr ids values found by API.

View File

@ -3,7 +3,7 @@
"name": "Flipr",
"config_flow": true,
"documentation": "https://www.home-assistant.io/integrations/flipr",
"requirements": ["flipr-api==1.4.2"],
"requirements": ["flipr-api==1.4.4"],
"codeowners": ["@cnico"],
"iot_class": "cloud_polling",
"loggers": ["flipr_api"]

View File

@ -8,7 +8,7 @@ from homeassistant.components.sensor import (
SensorStateClass,
)
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.helpers.entity_platform import AddEntitiesCallback
@ -48,6 +48,13 @@ SENSOR_TYPES: tuple[SensorEntityDescription, ...] = (
icon="mdi:pool",
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."""
@property
def native_value(self):
def native_value(self) -> str:
"""State of the sensor."""
return self.coordinator.data[self.entity_description.key]

View File

@ -705,7 +705,7 @@ fixerio==1.0.0a0
fjaraskupan==2.2.0
# homeassistant.components.flipr
flipr-api==1.4.2
flipr-api==1.4.4
# homeassistant.components.flux_led
flux_led==0.28.32

View File

@ -527,7 +527,7 @@ fivem-api==0.1.2
fjaraskupan==2.2.0
# homeassistant.components.flipr
flipr-api==1.4.2
flipr-api==1.4.4
# homeassistant.components.flux_led
flux_led==0.28.32

View File

@ -11,6 +11,7 @@ from homeassistant.const import (
ATTR_UNIT_OF_MEASUREMENT,
CONF_EMAIL,
CONF_PASSWORD,
PERCENTAGE,
TEMP_CELSIUS,
)
from homeassistant.core import HomeAssistant
@ -29,6 +30,7 @@ MOCK_FLIPR_MEASURE = {
"date_time": MOCK_DATE_TIME,
"ph_status": "TooLow",
"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.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:
"""Test the Flipr sensors error."""