1
mirror of https://github.com/home-assistant/core synced 2024-10-07 10:13:38 +02:00

Deduplicate sensor_device_info_to_device_info (#81905)

Co-authored-by: J. Nick Koston <nick@koston.org>
This commit is contained in:
Aarni Koskela 2022-11-14 20:12:53 +02:00 committed by GitHub
parent af73afa2e2
commit 3d29638804
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
27 changed files with 89 additions and 299 deletions

View File

@ -1,13 +1,11 @@
"""Support for BlueMaestro devices.""" """Support for BlueMaestro devices."""
from __future__ import annotations from __future__ import annotations
from bluemaestro_ble import DeviceKey, SensorDeviceInfo from bluemaestro_ble import DeviceKey
from homeassistant.components.bluetooth.passive_update_processor import ( from homeassistant.components.bluetooth.passive_update_processor import (
PassiveBluetoothEntityKey, PassiveBluetoothEntityKey,
) )
from homeassistant.const import ATTR_MANUFACTURER, ATTR_MODEL, ATTR_NAME
from homeassistant.helpers.entity import DeviceInfo
def device_key_to_bluetooth_entity_key( def device_key_to_bluetooth_entity_key(
@ -15,17 +13,3 @@ def device_key_to_bluetooth_entity_key(
) -> PassiveBluetoothEntityKey: ) -> PassiveBluetoothEntityKey:
"""Convert a device key to an entity key.""" """Convert a device key to an entity key."""
return PassiveBluetoothEntityKey(device_key.key, device_key.device_id) return PassiveBluetoothEntityKey(device_key.key, device_key.device_id)
def sensor_device_info_to_hass(
sensor_device_info: SensorDeviceInfo,
) -> DeviceInfo:
"""Convert a bluemaestro device info to a sensor device info."""
hass_device_info = DeviceInfo({})
if sensor_device_info.name is not None:
hass_device_info[ATTR_NAME] = sensor_device_info.name
if sensor_device_info.manufacturer is not None:
hass_device_info[ATTR_MANUFACTURER] = sensor_device_info.manufacturer
if sensor_device_info.model is not None:
hass_device_info[ATTR_MODEL] = sensor_device_info.model
return hass_device_info

View File

@ -31,9 +31,10 @@ from homeassistant.const import (
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
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
from homeassistant.helpers.sensor import sensor_device_info_to_hass_device_info
from .const import DOMAIN from .const import DOMAIN
from .device import device_key_to_bluetooth_entity_key, sensor_device_info_to_hass from .device import device_key_to_bluetooth_entity_key
SENSOR_DESCRIPTIONS = { SENSOR_DESCRIPTIONS = {
(BlueMaestroSensorDeviceClass.BATTERY, Units.PERCENTAGE): SensorEntityDescription( (BlueMaestroSensorDeviceClass.BATTERY, Units.PERCENTAGE): SensorEntityDescription(
@ -96,7 +97,7 @@ def sensor_update_to_bluetooth_data_update(
"""Convert a sensor update to a bluetooth data update.""" """Convert a sensor update to a bluetooth data update."""
return PassiveBluetoothDataUpdate( return PassiveBluetoothDataUpdate(
devices={ devices={
device_id: sensor_device_info_to_hass(device_info) device_id: sensor_device_info_to_hass_device_info(device_info)
for device_id, device_info in sensor_update.devices.items() for device_id, device_info in sensor_update.devices.items()
}, },
entity_descriptions={ entity_descriptions={

View File

@ -22,9 +22,10 @@ from homeassistant.components.bluetooth.passive_update_processor import (
) )
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.sensor import sensor_device_info_to_hass_device_info
from .const import DOMAIN from .const import DOMAIN
from .device import device_key_to_bluetooth_entity_key, sensor_device_info_to_hass from .device import device_key_to_bluetooth_entity_key
BINARY_SENSOR_DESCRIPTIONS = { BINARY_SENSOR_DESCRIPTIONS = {
BTHomeBinarySensorDeviceClass.BATTERY: BinarySensorEntityDescription( BTHomeBinarySensorDeviceClass.BATTERY: BinarySensorEntityDescription(
@ -147,7 +148,7 @@ def sensor_update_to_bluetooth_data_update(
"""Convert a binary sensor update to a bluetooth data update.""" """Convert a binary sensor update to a bluetooth data update."""
return PassiveBluetoothDataUpdate( return PassiveBluetoothDataUpdate(
devices={ devices={
device_id: sensor_device_info_to_hass(device_info) device_id: sensor_device_info_to_hass_device_info(device_info)
for device_id, device_info in sensor_update.devices.items() for device_id, device_info in sensor_update.devices.items()
}, },
entity_descriptions={ entity_descriptions={

View File

@ -1,13 +1,11 @@
"""Support for BTHome Bluetooth devices.""" """Support for BTHome Bluetooth devices."""
from __future__ import annotations from __future__ import annotations
from bthome_ble import DeviceKey, SensorDeviceInfo from bthome_ble import DeviceKey
from homeassistant.components.bluetooth.passive_update_processor import ( from homeassistant.components.bluetooth.passive_update_processor import (
PassiveBluetoothEntityKey, PassiveBluetoothEntityKey,
) )
from homeassistant.const import ATTR_MANUFACTURER, ATTR_MODEL, ATTR_NAME
from homeassistant.helpers.entity import DeviceInfo
def device_key_to_bluetooth_entity_key( def device_key_to_bluetooth_entity_key(
@ -15,17 +13,3 @@ def device_key_to_bluetooth_entity_key(
) -> PassiveBluetoothEntityKey: ) -> PassiveBluetoothEntityKey:
"""Convert a device key to an entity key.""" """Convert a device key to an entity key."""
return PassiveBluetoothEntityKey(device_key.key, device_key.device_id) return PassiveBluetoothEntityKey(device_key.key, device_key.device_id)
def sensor_device_info_to_hass(
sensor_device_info: SensorDeviceInfo,
) -> DeviceInfo:
"""Convert a sensor device info to a sensor device info."""
hass_device_info = DeviceInfo({})
if sensor_device_info.name is not None:
hass_device_info[ATTR_NAME] = sensor_device_info.name
if sensor_device_info.manufacturer is not None:
hass_device_info[ATTR_MANUFACTURER] = sensor_device_info.manufacturer
if sensor_device_info.model is not None:
hass_device_info[ATTR_MODEL] = sensor_device_info.model
return hass_device_info

View File

@ -39,9 +39,10 @@ from homeassistant.const import (
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
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
from homeassistant.helpers.sensor import sensor_device_info_to_hass_device_info
from .const import DOMAIN from .const import DOMAIN
from .device import device_key_to_bluetooth_entity_key, sensor_device_info_to_hass from .device import device_key_to_bluetooth_entity_key
SENSOR_DESCRIPTIONS = { SENSOR_DESCRIPTIONS = {
(BTHomeSensorDeviceClass.TEMPERATURE, Units.TEMP_CELSIUS): SensorEntityDescription( (BTHomeSensorDeviceClass.TEMPERATURE, Units.TEMP_CELSIUS): SensorEntityDescription(
@ -243,7 +244,7 @@ def sensor_update_to_bluetooth_data_update(
"""Convert a sensor update to a bluetooth data update.""" """Convert a sensor update to a bluetooth data update."""
return PassiveBluetoothDataUpdate( return PassiveBluetoothDataUpdate(
devices={ devices={
device_id: sensor_device_info_to_hass(device_info) device_id: sensor_device_info_to_hass_device_info(device_info)
for device_id, device_info in sensor_update.devices.items() for device_id, device_info in sensor_update.devices.items()
}, },
entity_descriptions={ entity_descriptions={

View File

@ -3,7 +3,7 @@ from __future__ import annotations
from typing import Optional, Union from typing import Optional, Union
from govee_ble import DeviceClass, DeviceKey, SensorDeviceInfo, SensorUpdate, Units from govee_ble import DeviceClass, DeviceKey, SensorUpdate, Units
from homeassistant import config_entries from homeassistant import config_entries
from homeassistant.components.bluetooth.passive_update_processor import ( from homeassistant.components.bluetooth.passive_update_processor import (
@ -20,16 +20,13 @@ from homeassistant.components.sensor import (
SensorStateClass, SensorStateClass,
) )
from homeassistant.const import ( from homeassistant.const import (
ATTR_MANUFACTURER,
ATTR_MODEL,
ATTR_NAME,
PERCENTAGE, PERCENTAGE,
SIGNAL_STRENGTH_DECIBELS_MILLIWATT, SIGNAL_STRENGTH_DECIBELS_MILLIWATT,
TEMP_CELSIUS, TEMP_CELSIUS,
) )
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity import DeviceInfo
from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.sensor import sensor_device_info_to_hass_device_info
from .const import DOMAIN from .const import DOMAIN
@ -72,27 +69,13 @@ def _device_key_to_bluetooth_entity_key(
return PassiveBluetoothEntityKey(device_key.key, device_key.device_id) return PassiveBluetoothEntityKey(device_key.key, device_key.device_id)
def _sensor_device_info_to_hass(
sensor_device_info: SensorDeviceInfo,
) -> DeviceInfo:
"""Convert a sensor device info to hass device info."""
hass_device_info = DeviceInfo({})
if sensor_device_info.name is not None:
hass_device_info[ATTR_NAME] = sensor_device_info.name
if sensor_device_info.manufacturer is not None:
hass_device_info[ATTR_MANUFACTURER] = sensor_device_info.manufacturer
if sensor_device_info.model is not None:
hass_device_info[ATTR_MODEL] = sensor_device_info.model
return hass_device_info
def sensor_update_to_bluetooth_data_update( def sensor_update_to_bluetooth_data_update(
sensor_update: SensorUpdate, sensor_update: SensorUpdate,
) -> PassiveBluetoothDataUpdate: ) -> PassiveBluetoothDataUpdate:
"""Convert a sensor update to a bluetooth data update.""" """Convert a sensor update to a bluetooth data update."""
return PassiveBluetoothDataUpdate( return PassiveBluetoothDataUpdate(
devices={ devices={
device_id: _sensor_device_info_to_hass(device_info) device_id: sensor_device_info_to_hass_device_info(device_info)
for device_id, device_info in sensor_update.devices.items() for device_id, device_info in sensor_update.devices.items()
}, },
entity_descriptions={ entity_descriptions={

View File

@ -3,7 +3,7 @@ from __future__ import annotations
from typing import Optional, Union from typing import Optional, Union
from inkbird_ble import DeviceClass, DeviceKey, SensorDeviceInfo, SensorUpdate, Units from inkbird_ble import DeviceClass, DeviceKey, SensorUpdate, Units
from homeassistant import config_entries from homeassistant import config_entries
from homeassistant.components.bluetooth.passive_update_processor import ( from homeassistant.components.bluetooth.passive_update_processor import (
@ -20,16 +20,13 @@ from homeassistant.components.sensor import (
SensorStateClass, SensorStateClass,
) )
from homeassistant.const import ( from homeassistant.const import (
ATTR_MANUFACTURER,
ATTR_MODEL,
ATTR_NAME,
PERCENTAGE, PERCENTAGE,
SIGNAL_STRENGTH_DECIBELS_MILLIWATT, SIGNAL_STRENGTH_DECIBELS_MILLIWATT,
TEMP_CELSIUS, TEMP_CELSIUS,
) )
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity import DeviceInfo
from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.sensor import sensor_device_info_to_hass_device_info
from .const import DOMAIN from .const import DOMAIN
@ -72,27 +69,13 @@ def _device_key_to_bluetooth_entity_key(
return PassiveBluetoothEntityKey(device_key.key, device_key.device_id) return PassiveBluetoothEntityKey(device_key.key, device_key.device_id)
def _sensor_device_info_to_hass(
sensor_device_info: SensorDeviceInfo,
) -> DeviceInfo:
"""Convert a sensor device info to a sensor device info."""
hass_device_info = DeviceInfo({})
if sensor_device_info.name is not None:
hass_device_info[ATTR_NAME] = sensor_device_info.name
if sensor_device_info.manufacturer is not None:
hass_device_info[ATTR_MANUFACTURER] = sensor_device_info.manufacturer
if sensor_device_info.model is not None:
hass_device_info[ATTR_MODEL] = sensor_device_info.model
return hass_device_info
def sensor_update_to_bluetooth_data_update( def sensor_update_to_bluetooth_data_update(
sensor_update: SensorUpdate, sensor_update: SensorUpdate,
) -> PassiveBluetoothDataUpdate: ) -> PassiveBluetoothDataUpdate:
"""Convert a sensor update to a bluetooth data update.""" """Convert a sensor update to a bluetooth data update."""
return PassiveBluetoothDataUpdate( return PassiveBluetoothDataUpdate(
devices={ devices={
device_id: _sensor_device_info_to_hass(device_info) device_id: sensor_device_info_to_hass_device_info(device_info)
for device_id, device_info in sensor_update.devices.items() for device_id, device_info in sensor_update.devices.items()
}, },
entity_descriptions={ entity_descriptions={

View File

@ -3,13 +3,11 @@ from __future__ import annotations
import logging import logging
from kegtron_ble import DeviceKey, SensorDeviceInfo from kegtron_ble import DeviceKey
from homeassistant.components.bluetooth.passive_update_processor import ( from homeassistant.components.bluetooth.passive_update_processor import (
PassiveBluetoothEntityKey, PassiveBluetoothEntityKey,
) )
from homeassistant.const import ATTR_MANUFACTURER, ATTR_MODEL, ATTR_NAME
from homeassistant.helpers.entity import DeviceInfo
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
@ -19,17 +17,3 @@ def device_key_to_bluetooth_entity_key(
) -> PassiveBluetoothEntityKey: ) -> PassiveBluetoothEntityKey:
"""Convert a device key to an entity key.""" """Convert a device key to an entity key."""
return PassiveBluetoothEntityKey(device_key.key, device_key.device_id) return PassiveBluetoothEntityKey(device_key.key, device_key.device_id)
def sensor_device_info_to_hass(
sensor_device_info: SensorDeviceInfo,
) -> DeviceInfo:
"""Convert a sensor device info to a sensor device info."""
hass_device_info = DeviceInfo({})
if sensor_device_info.name is not None:
hass_device_info[ATTR_NAME] = sensor_device_info.name
if sensor_device_info.manufacturer is not None:
hass_device_info[ATTR_MANUFACTURER] = sensor_device_info.manufacturer
if sensor_device_info.model is not None:
hass_device_info[ATTR_MODEL] = sensor_device_info.model
return hass_device_info

View File

@ -26,9 +26,10 @@ from homeassistant.const import SIGNAL_STRENGTH_DECIBELS_MILLIWATT, VOLUME_LITER
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
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
from homeassistant.helpers.sensor import sensor_device_info_to_hass_device_info
from .const import DOMAIN from .const import DOMAIN
from .device import device_key_to_bluetooth_entity_key, sensor_device_info_to_hass from .device import device_key_to_bluetooth_entity_key
SENSOR_DESCRIPTIONS = { SENSOR_DESCRIPTIONS = {
KegtronSensorDeviceClass.PORT_COUNT: SensorEntityDescription( KegtronSensorDeviceClass.PORT_COUNT: SensorEntityDescription(
@ -85,7 +86,7 @@ def sensor_update_to_bluetooth_data_update(
"""Convert a sensor update to a bluetooth data update.""" """Convert a sensor update to a bluetooth data update."""
return PassiveBluetoothDataUpdate( return PassiveBluetoothDataUpdate(
devices={ devices={
device_id: sensor_device_info_to_hass(device_info) device_id: sensor_device_info_to_hass_device_info(device_info)
for device_id, device_info in sensor_update.devices.items() for device_id, device_info in sensor_update.devices.items()
}, },
entity_descriptions={ entity_descriptions={

View File

@ -3,7 +3,7 @@ from __future__ import annotations
from typing import Optional, Union from typing import Optional, Union
from moat_ble import DeviceClass, DeviceKey, SensorDeviceInfo, SensorUpdate, Units from moat_ble import DeviceClass, DeviceKey, SensorUpdate, Units
from homeassistant import config_entries from homeassistant import config_entries
from homeassistant.components.bluetooth.passive_update_processor import ( from homeassistant.components.bluetooth.passive_update_processor import (
@ -20,17 +20,14 @@ from homeassistant.components.sensor import (
SensorStateClass, SensorStateClass,
) )
from homeassistant.const import ( from homeassistant.const import (
ATTR_MANUFACTURER,
ATTR_MODEL,
ATTR_NAME,
ELECTRIC_POTENTIAL_VOLT, ELECTRIC_POTENTIAL_VOLT,
PERCENTAGE, PERCENTAGE,
SIGNAL_STRENGTH_DECIBELS_MILLIWATT, SIGNAL_STRENGTH_DECIBELS_MILLIWATT,
TEMP_CELSIUS, TEMP_CELSIUS,
) )
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity import DeviceInfo
from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.sensor import sensor_device_info_to_hass_device_info
from .const import DOMAIN from .const import DOMAIN
@ -79,27 +76,13 @@ def _device_key_to_bluetooth_entity_key(
return PassiveBluetoothEntityKey(device_key.key, device_key.device_id) return PassiveBluetoothEntityKey(device_key.key, device_key.device_id)
def _sensor_device_info_to_hass(
sensor_device_info: SensorDeviceInfo,
) -> DeviceInfo:
"""Convert a sensor device info to hass device info."""
hass_device_info = DeviceInfo({})
if sensor_device_info.name is not None:
hass_device_info[ATTR_NAME] = sensor_device_info.name
if sensor_device_info.manufacturer is not None:
hass_device_info[ATTR_MANUFACTURER] = sensor_device_info.manufacturer
if sensor_device_info.model is not None:
hass_device_info[ATTR_MODEL] = sensor_device_info.model
return hass_device_info
def sensor_update_to_bluetooth_data_update( def sensor_update_to_bluetooth_data_update(
sensor_update: SensorUpdate, sensor_update: SensorUpdate,
) -> PassiveBluetoothDataUpdate: ) -> PassiveBluetoothDataUpdate:
"""Convert a sensor update to a bluetooth data update.""" """Convert a sensor update to a bluetooth data update."""
return PassiveBluetoothDataUpdate( return PassiveBluetoothDataUpdate(
devices={ devices={
device_id: _sensor_device_info_to_hass(device_info) device_id: sensor_device_info_to_hass_device_info(device_info)
for device_id, device_info in sensor_update.devices.items() for device_id, device_info in sensor_update.devices.items()
}, },
entity_descriptions={ entity_descriptions={

View File

@ -1,13 +1,11 @@
"""Support for OralB devices.""" """Support for OralB devices."""
from __future__ import annotations from __future__ import annotations
from oralb_ble import DeviceKey, SensorDeviceInfo from oralb_ble import DeviceKey
from homeassistant.components.bluetooth.passive_update_processor import ( from homeassistant.components.bluetooth.passive_update_processor import (
PassiveBluetoothEntityKey, PassiveBluetoothEntityKey,
) )
from homeassistant.const import ATTR_MANUFACTURER, ATTR_MODEL, ATTR_NAME
from homeassistant.helpers.entity import DeviceInfo
def device_key_to_bluetooth_entity_key( def device_key_to_bluetooth_entity_key(
@ -15,17 +13,3 @@ def device_key_to_bluetooth_entity_key(
) -> PassiveBluetoothEntityKey: ) -> PassiveBluetoothEntityKey:
"""Convert a device key to an entity key.""" """Convert a device key to an entity key."""
return PassiveBluetoothEntityKey(device_key.key, device_key.device_id) return PassiveBluetoothEntityKey(device_key.key, device_key.device_id)
def sensor_device_info_to_hass(
sensor_device_info: SensorDeviceInfo,
) -> DeviceInfo:
"""Convert a oralb device info to a sensor device info."""
hass_device_info = DeviceInfo({})
if sensor_device_info.name is not None:
hass_device_info[ATTR_NAME] = sensor_device_info.name
if sensor_device_info.manufacturer is not None:
hass_device_info[ATTR_MANUFACTURER] = sensor_device_info.manufacturer
if sensor_device_info.model is not None:
hass_device_info[ATTR_MODEL] = sensor_device_info.model
return hass_device_info

View File

@ -22,9 +22,10 @@ from homeassistant.const import SIGNAL_STRENGTH_DECIBELS_MILLIWATT, TIME_SECONDS
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
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
from homeassistant.helpers.sensor import sensor_device_info_to_hass_device_info
from .const import DOMAIN from .const import DOMAIN
from .device import device_key_to_bluetooth_entity_key, sensor_device_info_to_hass from .device import device_key_to_bluetooth_entity_key
SENSOR_DESCRIPTIONS: dict[str, SensorEntityDescription] = { SENSOR_DESCRIPTIONS: dict[str, SensorEntityDescription] = {
OralBSensor.TIME: SensorEntityDescription( OralBSensor.TIME: SensorEntityDescription(
@ -67,7 +68,7 @@ def sensor_update_to_bluetooth_data_update(
"""Convert a sensor update to a bluetooth data update.""" """Convert a sensor update to a bluetooth data update."""
return PassiveBluetoothDataUpdate( return PassiveBluetoothDataUpdate(
devices={ devices={
device_id: sensor_device_info_to_hass(device_info) device_id: sensor_device_info_to_hass_device_info(device_info)
for device_id, device_info in sensor_update.devices.items() for device_id, device_info in sensor_update.devices.items()
}, },
entity_descriptions={ entity_descriptions={

View File

@ -22,9 +22,10 @@ from homeassistant.components.bluetooth.passive_update_processor import (
) )
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.sensor import sensor_device_info_to_hass_device_info
from .const import DOMAIN from .const import DOMAIN
from .device import device_key_to_bluetooth_entity_key, sensor_device_info_to_hass from .device import device_key_to_bluetooth_entity_key
BINARY_SENSOR_DESCRIPTIONS = { BINARY_SENSOR_DESCRIPTIONS = {
QingpingBinarySensorDeviceClass.MOTION: BinarySensorEntityDescription( QingpingBinarySensorDeviceClass.MOTION: BinarySensorEntityDescription(
@ -52,7 +53,7 @@ def sensor_update_to_bluetooth_data_update(
"""Convert a sensor update to a bluetooth data update.""" """Convert a sensor update to a bluetooth data update."""
return PassiveBluetoothDataUpdate( return PassiveBluetoothDataUpdate(
devices={ devices={
device_id: sensor_device_info_to_hass(device_info) device_id: sensor_device_info_to_hass_device_info(device_info)
for device_id, device_info in sensor_update.devices.items() for device_id, device_info in sensor_update.devices.items()
}, },
entity_descriptions={ entity_descriptions={

View File

@ -1,13 +1,11 @@
"""Support for Qingping devices.""" """Support for Qingping devices."""
from __future__ import annotations from __future__ import annotations
from qingping_ble import DeviceKey, SensorDeviceInfo from qingping_ble import DeviceKey
from homeassistant.components.bluetooth.passive_update_processor import ( from homeassistant.components.bluetooth.passive_update_processor import (
PassiveBluetoothEntityKey, PassiveBluetoothEntityKey,
) )
from homeassistant.const import ATTR_MANUFACTURER, ATTR_MODEL, ATTR_NAME
from homeassistant.helpers.entity import DeviceInfo
def device_key_to_bluetooth_entity_key( def device_key_to_bluetooth_entity_key(
@ -15,17 +13,3 @@ def device_key_to_bluetooth_entity_key(
) -> PassiveBluetoothEntityKey: ) -> PassiveBluetoothEntityKey:
"""Convert a device key to an entity key.""" """Convert a device key to an entity key."""
return PassiveBluetoothEntityKey(device_key.key, device_key.device_id) return PassiveBluetoothEntityKey(device_key.key, device_key.device_id)
def sensor_device_info_to_hass(
sensor_device_info: SensorDeviceInfo,
) -> DeviceInfo:
"""Convert a qingping device info to a sensor device info."""
hass_device_info = DeviceInfo({})
if sensor_device_info.name is not None:
hass_device_info[ATTR_NAME] = sensor_device_info.name
if sensor_device_info.manufacturer is not None:
hass_device_info[ATTR_MANUFACTURER] = sensor_device_info.manufacturer
if sensor_device_info.model is not None:
hass_device_info[ATTR_MODEL] = sensor_device_info.model
return hass_device_info

View File

@ -34,9 +34,10 @@ from homeassistant.const import (
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
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
from homeassistant.helpers.sensor import sensor_device_info_to_hass_device_info
from .const import DOMAIN from .const import DOMAIN
from .device import device_key_to_bluetooth_entity_key, sensor_device_info_to_hass from .device import device_key_to_bluetooth_entity_key
SENSOR_DESCRIPTIONS = { SENSOR_DESCRIPTIONS = {
(QingpingSensorDeviceClass.BATTERY, Units.PERCENTAGE): SensorEntityDescription( (QingpingSensorDeviceClass.BATTERY, Units.PERCENTAGE): SensorEntityDescription(
@ -120,7 +121,7 @@ def sensor_update_to_bluetooth_data_update(
"""Convert a sensor update to a bluetooth data update.""" """Convert a sensor update to a bluetooth data update."""
return PassiveBluetoothDataUpdate( return PassiveBluetoothDataUpdate(
devices={ devices={
device_id: sensor_device_info_to_hass(device_info) device_id: sensor_device_info_to_hass_device_info(device_info)
for device_id, device_info in sensor_update.devices.items() for device_id, device_info in sensor_update.devices.items()
}, },
entity_descriptions={ entity_descriptions={

View File

@ -7,7 +7,6 @@ from sensor_state_data import (
DeviceKey, DeviceKey,
SensorDescription, SensorDescription,
SensorDeviceClass, SensorDeviceClass,
SensorDeviceInfo,
SensorUpdate, SensorUpdate,
Units, Units,
) )
@ -26,8 +25,8 @@ from homeassistant.components.sensor import (
SensorStateClass, SensorStateClass,
) )
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity import DeviceInfo
from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.sensor import sensor_device_info_to_hass_device_info
from .const import DOMAIN from .const import DOMAIN
@ -85,20 +84,6 @@ def _device_key_to_bluetooth_entity_key(
return PassiveBluetoothEntityKey(device_key.key, device_key.device_id) return PassiveBluetoothEntityKey(device_key.key, device_key.device_id)
def _sensor_device_info_to_hass(
sensor_device_info: SensorDeviceInfo,
) -> DeviceInfo:
"""Convert a sensor device info to a sensor device info."""
hass_device_info = DeviceInfo()
if sensor_device_info.name is not None:
hass_device_info[const.ATTR_NAME] = sensor_device_info.name
if sensor_device_info.manufacturer is not None:
hass_device_info[const.ATTR_MANUFACTURER] = sensor_device_info.manufacturer
if sensor_device_info.model is not None:
hass_device_info[const.ATTR_MODEL] = sensor_device_info.model
return hass_device_info
def _to_sensor_key( def _to_sensor_key(
description: SensorDescription, description: SensorDescription,
) -> tuple[SensorDeviceClass, Units | None]: ) -> tuple[SensorDeviceClass, Units | None]:
@ -112,7 +97,7 @@ def sensor_update_to_bluetooth_data_update(
"""Convert a sensor update to a bluetooth data update.""" """Convert a sensor update to a bluetooth data update."""
return PassiveBluetoothDataUpdate( return PassiveBluetoothDataUpdate(
devices={ devices={
device_id: _sensor_device_info_to_hass(device_info) device_id: sensor_device_info_to_hass_device_info(device_info)
for device_id, device_info in sensor_update.devices.items() for device_id, device_info in sensor_update.devices.items()
}, },
entity_descriptions={ entity_descriptions={

View File

@ -1,13 +1,11 @@
"""Support for SensorPro devices.""" """Support for SensorPro devices."""
from __future__ import annotations from __future__ import annotations
from sensorpro_ble import DeviceKey, SensorDeviceInfo from sensorpro_ble import DeviceKey
from homeassistant.components.bluetooth.passive_update_processor import ( from homeassistant.components.bluetooth.passive_update_processor import (
PassiveBluetoothEntityKey, PassiveBluetoothEntityKey,
) )
from homeassistant.const import ATTR_MANUFACTURER, ATTR_MODEL, ATTR_NAME
from homeassistant.helpers.entity import DeviceInfo
def device_key_to_bluetooth_entity_key( def device_key_to_bluetooth_entity_key(
@ -15,17 +13,3 @@ def device_key_to_bluetooth_entity_key(
) -> PassiveBluetoothEntityKey: ) -> PassiveBluetoothEntityKey:
"""Convert a device key to an entity key.""" """Convert a device key to an entity key."""
return PassiveBluetoothEntityKey(device_key.key, device_key.device_id) return PassiveBluetoothEntityKey(device_key.key, device_key.device_id)
def sensor_device_info_to_hass(
sensor_device_info: SensorDeviceInfo,
) -> DeviceInfo:
"""Convert a sensorpro device info to a sensor device info."""
hass_device_info = DeviceInfo({})
if sensor_device_info.name is not None:
hass_device_info[ATTR_NAME] = sensor_device_info.name
if sensor_device_info.manufacturer is not None:
hass_device_info[ATTR_MANUFACTURER] = sensor_device_info.manufacturer
if sensor_device_info.model is not None:
hass_device_info[ATTR_MODEL] = sensor_device_info.model
return hass_device_info

View File

@ -31,9 +31,10 @@ from homeassistant.const import (
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
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
from homeassistant.helpers.sensor import sensor_device_info_to_hass_device_info
from .const import DOMAIN from .const import DOMAIN
from .device import device_key_to_bluetooth_entity_key, sensor_device_info_to_hass from .device import device_key_to_bluetooth_entity_key
SENSOR_DESCRIPTIONS = { SENSOR_DESCRIPTIONS = {
(SensorProSensorDeviceClass.BATTERY, Units.PERCENTAGE): SensorEntityDescription( (SensorProSensorDeviceClass.BATTERY, Units.PERCENTAGE): SensorEntityDescription(
@ -87,7 +88,7 @@ def sensor_update_to_bluetooth_data_update(
"""Convert a sensor update to a bluetooth data update.""" """Convert a sensor update to a bluetooth data update."""
return PassiveBluetoothDataUpdate( return PassiveBluetoothDataUpdate(
devices={ devices={
device_id: sensor_device_info_to_hass(device_info) device_id: sensor_device_info_to_hass_device_info(device_info)
for device_id, device_info in sensor_update.devices.items() for device_id, device_info in sensor_update.devices.items()
}, },
entity_descriptions={ entity_descriptions={

View File

@ -3,7 +3,7 @@ from __future__ import annotations
from typing import Optional, Union from typing import Optional, Union
from sensorpush_ble import DeviceClass, DeviceKey, SensorDeviceInfo, SensorUpdate, Units from sensorpush_ble import DeviceClass, DeviceKey, SensorUpdate, Units
from homeassistant import config_entries from homeassistant import config_entries
from homeassistant.components.bluetooth.passive_update_processor import ( from homeassistant.components.bluetooth.passive_update_processor import (
@ -20,17 +20,14 @@ from homeassistant.components.sensor import (
SensorStateClass, SensorStateClass,
) )
from homeassistant.const import ( from homeassistant.const import (
ATTR_MANUFACTURER,
ATTR_MODEL,
ATTR_NAME,
PERCENTAGE, PERCENTAGE,
PRESSURE_MBAR, PRESSURE_MBAR,
SIGNAL_STRENGTH_DECIBELS_MILLIWATT, SIGNAL_STRENGTH_DECIBELS_MILLIWATT,
TEMP_CELSIUS, TEMP_CELSIUS,
) )
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity import DeviceInfo
from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.sensor import sensor_device_info_to_hass_device_info
from .const import DOMAIN from .const import DOMAIN
@ -73,27 +70,13 @@ def _device_key_to_bluetooth_entity_key(
return PassiveBluetoothEntityKey(device_key.key, device_key.device_id) return PassiveBluetoothEntityKey(device_key.key, device_key.device_id)
def _sensor_device_info_to_hass(
sensor_device_info: SensorDeviceInfo,
) -> DeviceInfo:
"""Convert a sensor device info to a sensor device info."""
hass_device_info = DeviceInfo({})
if sensor_device_info.name is not None:
hass_device_info[ATTR_NAME] = sensor_device_info.name
if sensor_device_info.manufacturer is not None:
hass_device_info[ATTR_MANUFACTURER] = sensor_device_info.manufacturer
if sensor_device_info.model is not None:
hass_device_info[ATTR_MODEL] = sensor_device_info.model
return hass_device_info
def sensor_update_to_bluetooth_data_update( def sensor_update_to_bluetooth_data_update(
sensor_update: SensorUpdate, sensor_update: SensorUpdate,
) -> PassiveBluetoothDataUpdate: ) -> PassiveBluetoothDataUpdate:
"""Convert a sensor update to a bluetooth data update.""" """Convert a sensor update to a bluetooth data update."""
return PassiveBluetoothDataUpdate( return PassiveBluetoothDataUpdate(
devices={ devices={
device_id: _sensor_device_info_to_hass(device_info) device_id: sensor_device_info_to_hass_device_info(device_info)
for device_id, device_info in sensor_update.devices.items() for device_id, device_info in sensor_update.devices.items()
}, },
entity_descriptions={ entity_descriptions={

View File

@ -1,13 +1,11 @@
"""Support for ThermoBeacon devices.""" """Support for ThermoBeacon devices."""
from __future__ import annotations from __future__ import annotations
from thermobeacon_ble import DeviceKey, SensorDeviceInfo from thermobeacon_ble import DeviceKey
from homeassistant.components.bluetooth.passive_update_processor import ( from homeassistant.components.bluetooth.passive_update_processor import (
PassiveBluetoothEntityKey, PassiveBluetoothEntityKey,
) )
from homeassistant.const import ATTR_MANUFACTURER, ATTR_MODEL, ATTR_NAME
from homeassistant.helpers.entity import DeviceInfo
def device_key_to_bluetooth_entity_key( def device_key_to_bluetooth_entity_key(
@ -15,17 +13,3 @@ def device_key_to_bluetooth_entity_key(
) -> PassiveBluetoothEntityKey: ) -> PassiveBluetoothEntityKey:
"""Convert a device key to an entity key.""" """Convert a device key to an entity key."""
return PassiveBluetoothEntityKey(device_key.key, device_key.device_id) return PassiveBluetoothEntityKey(device_key.key, device_key.device_id)
def sensor_device_info_to_hass(
sensor_device_info: SensorDeviceInfo,
) -> DeviceInfo:
"""Convert a thermobeacon device info to a sensor device info."""
hass_device_info = DeviceInfo({})
if sensor_device_info.name is not None:
hass_device_info[ATTR_NAME] = sensor_device_info.name
if sensor_device_info.manufacturer is not None:
hass_device_info[ATTR_MANUFACTURER] = sensor_device_info.manufacturer
if sensor_device_info.model is not None:
hass_device_info[ATTR_MODEL] = sensor_device_info.model
return hass_device_info

View File

@ -31,9 +31,10 @@ from homeassistant.const import (
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
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
from homeassistant.helpers.sensor import sensor_device_info_to_hass_device_info
from .const import DOMAIN from .const import DOMAIN
from .device import device_key_to_bluetooth_entity_key, sensor_device_info_to_hass from .device import device_key_to_bluetooth_entity_key
SENSOR_DESCRIPTIONS = { SENSOR_DESCRIPTIONS = {
(ThermoBeaconSensorDeviceClass.BATTERY, Units.PERCENTAGE): SensorEntityDescription( (ThermoBeaconSensorDeviceClass.BATTERY, Units.PERCENTAGE): SensorEntityDescription(
@ -87,7 +88,7 @@ def sensor_update_to_bluetooth_data_update(
"""Convert a sensor update to a bluetooth data update.""" """Convert a sensor update to a bluetooth data update."""
return PassiveBluetoothDataUpdate( return PassiveBluetoothDataUpdate(
devices={ devices={
device_id: sensor_device_info_to_hass(device_info) device_id: sensor_device_info_to_hass_device_info(device_info)
for device_id, device_info in sensor_update.devices.items() for device_id, device_info in sensor_update.devices.items()
}, },
entity_descriptions={ entity_descriptions={

View File

@ -6,7 +6,6 @@ from typing import Optional, Union
from thermopro_ble import ( from thermopro_ble import (
DeviceKey, DeviceKey,
SensorDeviceClass as ThermoProSensorDeviceClass, SensorDeviceClass as ThermoProSensorDeviceClass,
SensorDeviceInfo,
SensorUpdate, SensorUpdate,
Units, Units,
) )
@ -26,16 +25,13 @@ from homeassistant.components.sensor import (
SensorStateClass, SensorStateClass,
) )
from homeassistant.const import ( from homeassistant.const import (
ATTR_MANUFACTURER,
ATTR_MODEL,
ATTR_NAME,
PERCENTAGE, PERCENTAGE,
SIGNAL_STRENGTH_DECIBELS_MILLIWATT, SIGNAL_STRENGTH_DECIBELS_MILLIWATT,
TEMP_CELSIUS, TEMP_CELSIUS,
) )
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity import DeviceInfo
from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.sensor import sensor_device_info_to_hass_device_info
from .const import DOMAIN from .const import DOMAIN
@ -75,27 +71,13 @@ def _device_key_to_bluetooth_entity_key(
return PassiveBluetoothEntityKey(device_key.key, device_key.device_id) return PassiveBluetoothEntityKey(device_key.key, device_key.device_id)
def _sensor_device_info_to_hass(
sensor_device_info: SensorDeviceInfo,
) -> DeviceInfo:
"""Convert a sensor device info to a sensor device info."""
hass_device_info = DeviceInfo({})
if sensor_device_info.name is not None:
hass_device_info[ATTR_NAME] = sensor_device_info.name
if sensor_device_info.manufacturer is not None:
hass_device_info[ATTR_MANUFACTURER] = sensor_device_info.manufacturer
if sensor_device_info.model is not None:
hass_device_info[ATTR_MODEL] = sensor_device_info.model
return hass_device_info
def sensor_update_to_bluetooth_data_update( def sensor_update_to_bluetooth_data_update(
sensor_update: SensorUpdate, sensor_update: SensorUpdate,
) -> PassiveBluetoothDataUpdate: ) -> PassiveBluetoothDataUpdate:
"""Convert a sensor update to a bluetooth data update.""" """Convert a sensor update to a bluetooth data update."""
return PassiveBluetoothDataUpdate( return PassiveBluetoothDataUpdate(
devices={ devices={
device_id: _sensor_device_info_to_hass(device_info) device_id: sensor_device_info_to_hass_device_info(device_info)
for device_id, device_info in sensor_update.devices.items() for device_id, device_info in sensor_update.devices.items()
}, },
entity_descriptions={ entity_descriptions={

View File

@ -3,7 +3,7 @@ from __future__ import annotations
from typing import Optional, Union from typing import Optional, Union
from tilt_ble import DeviceClass, DeviceKey, SensorDeviceInfo, SensorUpdate, Units from tilt_ble import DeviceClass, DeviceKey, SensorUpdate, Units
from homeassistant import config_entries from homeassistant import config_entries
from homeassistant.components.bluetooth.passive_update_processor import ( from homeassistant.components.bluetooth.passive_update_processor import (
@ -19,16 +19,10 @@ from homeassistant.components.sensor import (
SensorEntityDescription, SensorEntityDescription,
SensorStateClass, SensorStateClass,
) )
from homeassistant.const import ( from homeassistant.const import SIGNAL_STRENGTH_DECIBELS_MILLIWATT, TEMP_FAHRENHEIT
ATTR_MANUFACTURER,
ATTR_MODEL,
ATTR_NAME,
SIGNAL_STRENGTH_DECIBELS_MILLIWATT,
TEMP_FAHRENHEIT,
)
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity import DeviceInfo
from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.sensor import sensor_device_info_to_hass_device_info
from .const import DOMAIN from .const import DOMAIN
@ -63,27 +57,13 @@ def _device_key_to_bluetooth_entity_key(
return PassiveBluetoothEntityKey(device_key.key, device_key.device_id) return PassiveBluetoothEntityKey(device_key.key, device_key.device_id)
def _sensor_device_info_to_hass(
sensor_device_info: SensorDeviceInfo,
) -> DeviceInfo:
"""Convert a sensor device info to a sensor device info."""
hass_device_info = DeviceInfo({})
if sensor_device_info.name is not None:
hass_device_info[ATTR_NAME] = sensor_device_info.name
if sensor_device_info.manufacturer is not None:
hass_device_info[ATTR_MANUFACTURER] = sensor_device_info.manufacturer
if sensor_device_info.model is not None:
hass_device_info[ATTR_MODEL] = sensor_device_info.model
return hass_device_info
def sensor_update_to_bluetooth_data_update( def sensor_update_to_bluetooth_data_update(
sensor_update: SensorUpdate, sensor_update: SensorUpdate,
) -> PassiveBluetoothDataUpdate: ) -> PassiveBluetoothDataUpdate:
"""Convert a sensor update to a bluetooth data update.""" """Convert a sensor update to a bluetooth data update."""
return PassiveBluetoothDataUpdate( return PassiveBluetoothDataUpdate(
devices={ devices={
device_id: _sensor_device_info_to_hass(device_info) device_id: sensor_device_info_to_hass_device_info(device_info)
for device_id, device_info in sensor_update.devices.items() for device_id, device_info in sensor_update.devices.items()
}, },
entity_descriptions={ entity_descriptions={

View File

@ -22,9 +22,10 @@ from homeassistant.components.bluetooth.passive_update_processor import (
) )
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.sensor import sensor_device_info_to_hass_device_info
from .const import DOMAIN from .const import DOMAIN
from .device import device_key_to_bluetooth_entity_key, sensor_device_info_to_hass from .device import device_key_to_bluetooth_entity_key
BINARY_SENSOR_DESCRIPTIONS = { BINARY_SENSOR_DESCRIPTIONS = {
XiaomiBinarySensorDeviceClass.MOTION: BinarySensorEntityDescription( XiaomiBinarySensorDeviceClass.MOTION: BinarySensorEntityDescription(
@ -51,7 +52,7 @@ def sensor_update_to_bluetooth_data_update(
"""Convert a sensor update to a bluetooth data update.""" """Convert a sensor update to a bluetooth data update."""
return PassiveBluetoothDataUpdate( return PassiveBluetoothDataUpdate(
devices={ devices={
device_id: sensor_device_info_to_hass(device_info) device_id: sensor_device_info_to_hass_device_info(device_info)
for device_id, device_info in sensor_update.devices.items() for device_id, device_info in sensor_update.devices.items()
}, },
entity_descriptions={ entity_descriptions={

View File

@ -1,13 +1,11 @@
"""Support for Xioami BLE devices.""" """Support for Xioami BLE devices."""
from __future__ import annotations from __future__ import annotations
from xiaomi_ble import DeviceKey, SensorDeviceInfo from xiaomi_ble import DeviceKey
from homeassistant.components.bluetooth.passive_update_processor import ( from homeassistant.components.bluetooth.passive_update_processor import (
PassiveBluetoothEntityKey, PassiveBluetoothEntityKey,
) )
from homeassistant.const import ATTR_MANUFACTURER, ATTR_MODEL, ATTR_NAME
from homeassistant.helpers.entity import DeviceInfo
def device_key_to_bluetooth_entity_key( def device_key_to_bluetooth_entity_key(
@ -15,17 +13,3 @@ def device_key_to_bluetooth_entity_key(
) -> PassiveBluetoothEntityKey: ) -> PassiveBluetoothEntityKey:
"""Convert a device key to an entity key.""" """Convert a device key to an entity key."""
return PassiveBluetoothEntityKey(device_key.key, device_key.device_id) return PassiveBluetoothEntityKey(device_key.key, device_key.device_id)
def sensor_device_info_to_hass(
sensor_device_info: SensorDeviceInfo,
) -> DeviceInfo:
"""Convert a sensor device info to a sensor device info."""
hass_device_info = DeviceInfo({})
if sensor_device_info.name is not None:
hass_device_info[ATTR_NAME] = sensor_device_info.name
if sensor_device_info.manufacturer is not None:
hass_device_info[ATTR_MANUFACTURER] = sensor_device_info.manufacturer
if sensor_device_info.model is not None:
hass_device_info[ATTR_MODEL] = sensor_device_info.model
return hass_device_info

View File

@ -31,9 +31,10 @@ from homeassistant.const import (
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
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
from homeassistant.helpers.sensor import sensor_device_info_to_hass_device_info
from .const import DOMAIN from .const import DOMAIN
from .device import device_key_to_bluetooth_entity_key, sensor_device_info_to_hass from .device import device_key_to_bluetooth_entity_key
SENSOR_DESCRIPTIONS = { SENSOR_DESCRIPTIONS = {
(DeviceClass.BATTERY, Units.PERCENTAGE): SensorEntityDescription( (DeviceClass.BATTERY, Units.PERCENTAGE): SensorEntityDescription(
@ -121,7 +122,7 @@ def sensor_update_to_bluetooth_data_update(
"""Convert a sensor update to a bluetooth data update.""" """Convert a sensor update to a bluetooth data update."""
return PassiveBluetoothDataUpdate( return PassiveBluetoothDataUpdate(
devices={ devices={
device_id: sensor_device_info_to_hass(device_info) device_id: sensor_device_info_to_hass_device_info(device_info)
for device_id, device_info in sensor_update.devices.items() for device_id, device_info in sensor_update.devices.items()
}, },
entity_descriptions={ entity_descriptions={

View File

@ -0,0 +1,28 @@
"""Common functions related to sensor device management."""
from __future__ import annotations
from typing import TYPE_CHECKING
from homeassistant import const
from .entity import DeviceInfo
if TYPE_CHECKING:
# `sensor_state_data` is a second-party library (i.e. maintained by Home Assistant
# core members) which is not strictly required by Home Assistant.
# Therefore, we import it as a type hint only.
from sensor_state_data import SensorDeviceInfo
def sensor_device_info_to_hass_device_info(
sensor_device_info: SensorDeviceInfo,
) -> DeviceInfo:
"""Convert a sensor_state_data sensor device info to a Home Assistant device info."""
device_info = DeviceInfo()
if sensor_device_info.name is not None:
device_info[const.ATTR_NAME] = sensor_device_info.name
if sensor_device_info.manufacturer is not None:
device_info[const.ATTR_MANUFACTURER] = sensor_device_info.manufacturer
if sensor_device_info.model is not None:
device_info[const.ATTR_MODEL] = sensor_device_info.model
return device_info