mirror of
https://github.com/home-assistant/core.git
synced 2026-09-09 23:21:00 +01:00
* Add BThome BLE * Update BThome to latest version * 0.3.4 * Rename to bthome 2 * Fix uuids not being found * Make energy a total increasing state class * Change unit of measurement of VOC * Use short identifier * Fix the reauth flow * Bump bthome_ble * Parameterize sensor tests * Remove Move function to parameter Co-authored-by: Paulus Schoutsen <balloob@gmail.com>
32 lines
1.1 KiB
Python
32 lines
1.1 KiB
Python
"""Support for BThome Bluetooth devices."""
|
|
from __future__ import annotations
|
|
|
|
from bthome_ble import DeviceKey, SensorDeviceInfo
|
|
|
|
from homeassistant.components.bluetooth.passive_update_processor import (
|
|
PassiveBluetoothEntityKey,
|
|
)
|
|
from homeassistant.const import ATTR_MANUFACTURER, ATTR_MODEL, ATTR_NAME
|
|
from homeassistant.helpers.entity import DeviceInfo
|
|
|
|
|
|
def device_key_to_bluetooth_entity_key(
|
|
device_key: DeviceKey,
|
|
) -> PassiveBluetoothEntityKey:
|
|
"""Convert a device key to an entity key."""
|
|
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
|