mirror of
https://github.com/home-assistant/core.git
synced 2025-07-27 07:07:28 +00:00
Add support for battery to Yale Access Bluetooth (#83691)
* Add support for battery level to Yale Access Bluetooth * fix * bump * bump * bump * bump * fix * bump * battery level is always an estimate from voltage, but than again it always is for every device * bump * review * bump again to fix slow start * other one
This commit is contained in:
parent
119f2a90b7
commit
5c79dae4c0
@ -2,7 +2,7 @@
|
|||||||
"domain": "august",
|
"domain": "august",
|
||||||
"name": "August",
|
"name": "August",
|
||||||
"documentation": "https://www.home-assistant.io/integrations/august",
|
"documentation": "https://www.home-assistant.io/integrations/august",
|
||||||
"requirements": ["yalexs==1.2.6", "yalexs_ble==1.10.3"],
|
"requirements": ["yalexs==1.2.6", "yalexs_ble==1.11.4"],
|
||||||
"codeowners": ["@bdraco"],
|
"codeowners": ["@bdraco"],
|
||||||
"dhcp": [
|
"dhcp": [
|
||||||
{
|
{
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
"name": "Yale Access Bluetooth",
|
"name": "Yale Access Bluetooth",
|
||||||
"config_flow": true,
|
"config_flow": true,
|
||||||
"documentation": "https://www.home-assistant.io/integrations/yalexs_ble",
|
"documentation": "https://www.home-assistant.io/integrations/yalexs_ble",
|
||||||
"requirements": ["yalexs-ble==1.10.3"],
|
"requirements": ["yalexs-ble==1.11.4"],
|
||||||
"dependencies": ["bluetooth"],
|
"dependencies": ["bluetooth"],
|
||||||
"codeowners": ["@bdraco"],
|
"codeowners": ["@bdraco"],
|
||||||
"bluetooth": [
|
"bluetooth": [
|
||||||
|
@ -1,11 +1,23 @@
|
|||||||
"""Support for yalexs ble sensors."""
|
"""Support for yalexs ble sensors."""
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from collections.abc import Callable
|
||||||
|
from dataclasses import dataclass
|
||||||
|
|
||||||
from yalexs_ble import ConnectionInfo, LockInfo, LockState
|
from yalexs_ble import ConnectionInfo, LockInfo, LockState
|
||||||
|
|
||||||
from homeassistant import config_entries
|
from homeassistant import config_entries
|
||||||
from homeassistant.components.sensor import SensorDeviceClass, SensorEntity
|
from homeassistant.components.sensor import (
|
||||||
from homeassistant.const import SIGNAL_STRENGTH_DECIBELS_MILLIWATT
|
SensorDeviceClass,
|
||||||
|
SensorEntity,
|
||||||
|
SensorEntityDescription,
|
||||||
|
SensorStateClass,
|
||||||
|
)
|
||||||
|
from homeassistant.const import (
|
||||||
|
ELECTRIC_POTENTIAL_VOLT,
|
||||||
|
PERCENTAGE,
|
||||||
|
SIGNAL_STRENGTH_DECIBELS_MILLIWATT,
|
||||||
|
)
|
||||||
from homeassistant.core import HomeAssistant, callback
|
from homeassistant.core import HomeAssistant, callback
|
||||||
from homeassistant.helpers.entity import EntityCategory
|
from homeassistant.helpers.entity import EntityCategory
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
@ -15,6 +27,60 @@ from .entity import YALEXSBLEEntity
|
|||||||
from .models import YaleXSBLEData
|
from .models import YaleXSBLEData
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass
|
||||||
|
class YaleXSBLERequiredKeysMixin:
|
||||||
|
"""Mixin for required keys."""
|
||||||
|
|
||||||
|
value_fn: Callable[[LockState, LockInfo, ConnectionInfo], int | float | None]
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass
|
||||||
|
class YaleXSBLESensorEntityDescription(
|
||||||
|
SensorEntityDescription, YaleXSBLERequiredKeysMixin
|
||||||
|
):
|
||||||
|
"""Describes Yale Access Bluetooth sensor entity."""
|
||||||
|
|
||||||
|
|
||||||
|
SENSORS: tuple[YaleXSBLESensorEntityDescription, ...] = (
|
||||||
|
YaleXSBLESensorEntityDescription(
|
||||||
|
key="", # No key for the original RSSI sensor unique id
|
||||||
|
name="Signal strength",
|
||||||
|
device_class=SensorDeviceClass.SIGNAL_STRENGTH,
|
||||||
|
entity_category=EntityCategory.DIAGNOSTIC,
|
||||||
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
|
has_entity_name=True,
|
||||||
|
native_unit_of_measurement=SIGNAL_STRENGTH_DECIBELS_MILLIWATT,
|
||||||
|
entity_registry_enabled_default=False,
|
||||||
|
value_fn=lambda state, info, connection: connection.rssi,
|
||||||
|
),
|
||||||
|
YaleXSBLESensorEntityDescription(
|
||||||
|
key="battery_level",
|
||||||
|
name="Battery level",
|
||||||
|
device_class=SensorDeviceClass.BATTERY,
|
||||||
|
entity_category=EntityCategory.DIAGNOSTIC,
|
||||||
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
|
has_entity_name=True,
|
||||||
|
native_unit_of_measurement=PERCENTAGE,
|
||||||
|
value_fn=lambda state, info, connection: state.battery.percentage
|
||||||
|
if state.battery
|
||||||
|
else None,
|
||||||
|
),
|
||||||
|
YaleXSBLESensorEntityDescription(
|
||||||
|
key="battery_voltage",
|
||||||
|
name="Battery Voltage",
|
||||||
|
device_class=SensorDeviceClass.VOLTAGE,
|
||||||
|
entity_category=EntityCategory.DIAGNOSTIC,
|
||||||
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
|
has_entity_name=True,
|
||||||
|
native_unit_of_measurement=ELECTRIC_POTENTIAL_VOLT,
|
||||||
|
entity_registry_enabled_default=False,
|
||||||
|
value_fn=lambda state, info, connection: state.battery.voltage
|
||||||
|
if state.battery
|
||||||
|
else None,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(
|
async def async_setup_entry(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
entry: config_entries.ConfigEntry,
|
entry: config_entries.ConfigEntry,
|
||||||
@ -22,23 +88,30 @@ async def async_setup_entry(
|
|||||||
) -> None:
|
) -> None:
|
||||||
"""Set up YALE XS Bluetooth sensors."""
|
"""Set up YALE XS Bluetooth sensors."""
|
||||||
data: YaleXSBLEData = hass.data[DOMAIN][entry.entry_id]
|
data: YaleXSBLEData = hass.data[DOMAIN][entry.entry_id]
|
||||||
async_add_entities([YaleXSBLERSSISensor(data)])
|
async_add_entities(YaleXSBLESensor(description, data) for description in SENSORS)
|
||||||
|
|
||||||
|
|
||||||
class YaleXSBLERSSISensor(YALEXSBLEEntity, SensorEntity):
|
class YaleXSBLESensor(YALEXSBLEEntity, SensorEntity):
|
||||||
"""Yale XS Bluetooth RSSI sensor."""
|
"""Yale XS Bluetooth sensor."""
|
||||||
|
|
||||||
_attr_device_class = SensorDeviceClass.SIGNAL_STRENGTH
|
entity_description: YaleXSBLESensorEntityDescription
|
||||||
_attr_entity_category = EntityCategory.DIAGNOSTIC
|
|
||||||
_attr_entity_registry_enabled_default = False
|
def __init__(
|
||||||
_attr_has_entity_name = True
|
self,
|
||||||
_attr_name = "Signal strength"
|
description: YaleXSBLESensorEntityDescription,
|
||||||
_attr_native_unit_of_measurement = SIGNAL_STRENGTH_DECIBELS_MILLIWATT
|
data: YaleXSBLEData,
|
||||||
|
) -> None:
|
||||||
|
"""Initialize the sensor."""
|
||||||
|
self.entity_description = description
|
||||||
|
super().__init__(data)
|
||||||
|
self._attr_unique_id = f"{data.lock.address}{description.key}"
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def _async_update_state(
|
def _async_update_state(
|
||||||
self, new_state: LockState, lock_info: LockInfo, connection_info: ConnectionInfo
|
self, new_state: LockState, lock_info: LockInfo, connection_info: ConnectionInfo
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Update the state."""
|
"""Update the state."""
|
||||||
self._attr_native_value = connection_info.rssi
|
self._attr_native_value = self.entity_description.value_fn(
|
||||||
|
new_state, lock_info, connection_info
|
||||||
|
)
|
||||||
super()._async_update_state(new_state, lock_info, connection_info)
|
super()._async_update_state(new_state, lock_info, connection_info)
|
||||||
|
@ -2609,13 +2609,13 @@ xs1-api-client==3.0.0
|
|||||||
yalesmartalarmclient==0.3.9
|
yalesmartalarmclient==0.3.9
|
||||||
|
|
||||||
# homeassistant.components.yalexs_ble
|
# homeassistant.components.yalexs_ble
|
||||||
yalexs-ble==1.10.3
|
yalexs-ble==1.11.4
|
||||||
|
|
||||||
# homeassistant.components.august
|
# homeassistant.components.august
|
||||||
yalexs==1.2.6
|
yalexs==1.2.6
|
||||||
|
|
||||||
# homeassistant.components.august
|
# homeassistant.components.august
|
||||||
yalexs_ble==1.10.3
|
yalexs_ble==1.11.4
|
||||||
|
|
||||||
# homeassistant.components.yeelight
|
# homeassistant.components.yeelight
|
||||||
yeelight==0.7.10
|
yeelight==0.7.10
|
||||||
|
@ -1819,13 +1819,13 @@ xmltodict==0.13.0
|
|||||||
yalesmartalarmclient==0.3.9
|
yalesmartalarmclient==0.3.9
|
||||||
|
|
||||||
# homeassistant.components.yalexs_ble
|
# homeassistant.components.yalexs_ble
|
||||||
yalexs-ble==1.10.3
|
yalexs-ble==1.11.4
|
||||||
|
|
||||||
# homeassistant.components.august
|
# homeassistant.components.august
|
||||||
yalexs==1.2.6
|
yalexs==1.2.6
|
||||||
|
|
||||||
# homeassistant.components.august
|
# homeassistant.components.august
|
||||||
yalexs_ble==1.10.3
|
yalexs_ble==1.11.4
|
||||||
|
|
||||||
# homeassistant.components.yeelight
|
# homeassistant.components.yeelight
|
||||||
yeelight==0.7.10
|
yeelight==0.7.10
|
||||||
|
Loading…
x
Reference in New Issue
Block a user