mirror of
https://github.com/home-assistant/core.git
synced 2025-07-22 20:57:21 +00:00
Add text sensor to BTHome (#98355)
This commit is contained in:
parent
32d8d65add
commit
1369874348
@ -20,5 +20,5 @@
|
|||||||
"dependencies": ["bluetooth_adapters"],
|
"dependencies": ["bluetooth_adapters"],
|
||||||
"documentation": "https://www.home-assistant.io/integrations/bthome",
|
"documentation": "https://www.home-assistant.io/integrations/bthome",
|
||||||
"iot_class": "local_push",
|
"iot_class": "local_push",
|
||||||
"requirements": ["bthome-ble==3.0.0"]
|
"requirements": ["bthome-ble==3.1.0"]
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,9 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from bthome_ble import SensorDeviceClass as BTHomeSensorDeviceClass, SensorUpdate, Units
|
from bthome_ble import SensorDeviceClass as BTHomeSensorDeviceClass, SensorUpdate, Units
|
||||||
|
from bthome_ble.const import (
|
||||||
|
ExtendedSensorDeviceClass as BTHomeExtendedSensorDeviceClass,
|
||||||
|
)
|
||||||
|
|
||||||
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 (
|
||||||
@ -66,7 +69,7 @@ SENSOR_DESCRIPTIONS = {
|
|||||||
),
|
),
|
||||||
# Count (-)
|
# Count (-)
|
||||||
(BTHomeSensorDeviceClass.COUNT, None): SensorEntityDescription(
|
(BTHomeSensorDeviceClass.COUNT, None): SensorEntityDescription(
|
||||||
key=f"{BTHomeSensorDeviceClass.COUNT}",
|
key=str(BTHomeSensorDeviceClass.COUNT),
|
||||||
state_class=SensorStateClass.MEASUREMENT,
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
),
|
),
|
||||||
# CO2 (parts per million)
|
# CO2 (parts per million)
|
||||||
@ -186,7 +189,7 @@ SENSOR_DESCRIPTIONS = {
|
|||||||
),
|
),
|
||||||
# Packet Id (-)
|
# Packet Id (-)
|
||||||
(BTHomeSensorDeviceClass.PACKET_ID, None): SensorEntityDescription(
|
(BTHomeSensorDeviceClass.PACKET_ID, None): SensorEntityDescription(
|
||||||
key=f"{BTHomeSensorDeviceClass.PACKET_ID}",
|
key=str(BTHomeSensorDeviceClass.PACKET_ID),
|
||||||
state_class=SensorStateClass.MEASUREMENT,
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
entity_category=EntityCategory.DIAGNOSTIC,
|
entity_category=EntityCategory.DIAGNOSTIC,
|
||||||
entity_registry_enabled_default=False,
|
entity_registry_enabled_default=False,
|
||||||
@ -260,12 +263,16 @@ SENSOR_DESCRIPTIONS = {
|
|||||||
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
|
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
|
||||||
state_class=SensorStateClass.MEASUREMENT,
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
),
|
),
|
||||||
|
# Text (-)
|
||||||
|
(BTHomeExtendedSensorDeviceClass.TEXT, None): SensorEntityDescription(
|
||||||
|
key=str(BTHomeExtendedSensorDeviceClass.TEXT),
|
||||||
|
),
|
||||||
# Timestamp (datetime object)
|
# Timestamp (datetime object)
|
||||||
(
|
(
|
||||||
BTHomeSensorDeviceClass.TIMESTAMP,
|
BTHomeSensorDeviceClass.TIMESTAMP,
|
||||||
None,
|
None,
|
||||||
): SensorEntityDescription(
|
): SensorEntityDescription(
|
||||||
key=f"{BTHomeSensorDeviceClass.TIMESTAMP}",
|
key=str(BTHomeSensorDeviceClass.TIMESTAMP),
|
||||||
device_class=SensorDeviceClass.TIMESTAMP,
|
device_class=SensorDeviceClass.TIMESTAMP,
|
||||||
state_class=SensorStateClass.MEASUREMENT,
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
),
|
),
|
||||||
@ -274,7 +281,7 @@ SENSOR_DESCRIPTIONS = {
|
|||||||
BTHomeSensorDeviceClass.UV_INDEX,
|
BTHomeSensorDeviceClass.UV_INDEX,
|
||||||
None,
|
None,
|
||||||
): SensorEntityDescription(
|
): SensorEntityDescription(
|
||||||
key=f"{BTHomeSensorDeviceClass.UV_INDEX}",
|
key=str(BTHomeSensorDeviceClass.UV_INDEX),
|
||||||
state_class=SensorStateClass.MEASUREMENT,
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
),
|
),
|
||||||
# Volatile organic Compounds (VOC) (µg/m3)
|
# Volatile organic Compounds (VOC) (µg/m3)
|
||||||
|
@ -571,7 +571,7 @@ brunt==1.2.0
|
|||||||
bt-proximity==0.2.1
|
bt-proximity==0.2.1
|
||||||
|
|
||||||
# homeassistant.components.bthome
|
# homeassistant.components.bthome
|
||||||
bthome-ble==3.0.0
|
bthome-ble==3.1.0
|
||||||
|
|
||||||
# homeassistant.components.bt_home_hub_5
|
# homeassistant.components.bt_home_hub_5
|
||||||
bthomehub5-devicelist==0.1.1
|
bthomehub5-devicelist==0.1.1
|
||||||
|
@ -475,7 +475,7 @@ brottsplatskartan==0.0.1
|
|||||||
brunt==1.2.0
|
brunt==1.2.0
|
||||||
|
|
||||||
# homeassistant.components.bthome
|
# homeassistant.components.bthome
|
||||||
bthome-ble==3.0.0
|
bthome-ble==3.1.0
|
||||||
|
|
||||||
# homeassistant.components.buienradar
|
# homeassistant.components.buienradar
|
||||||
buienradar==1.0.5
|
buienradar==1.0.5
|
||||||
|
@ -869,7 +869,6 @@ async def test_v1_sensors(
|
|||||||
{
|
{
|
||||||
"sensor_entity": "sensor.test_device_18b2_timestamp",
|
"sensor_entity": "sensor.test_device_18b2_timestamp",
|
||||||
"friendly_name": "Test Device 18B2 Timestamp",
|
"friendly_name": "Test Device 18B2 Timestamp",
|
||||||
"unit_of_measurement": "s",
|
|
||||||
"state_class": "measurement",
|
"state_class": "measurement",
|
||||||
"expected_state": "2023-05-14T19:41:17+00:00",
|
"expected_state": "2023-05-14T19:41:17+00:00",
|
||||||
},
|
},
|
||||||
@ -943,6 +942,21 @@ async def test_v1_sensors(
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
(
|
||||||
|
"A4:C1:38:8D:18:B2",
|
||||||
|
make_bthome_v2_adv(
|
||||||
|
"A4:C1:38:8D:18:B2",
|
||||||
|
b"\x44\x53\x0C\x48\x65\x6C\x6C\x6F\x20\x57\x6F\x72\x6C\x64\x21",
|
||||||
|
),
|
||||||
|
None,
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"sensor_entity": "sensor.test_device_18b2_text",
|
||||||
|
"friendly_name": "Test Device 18B2 Text",
|
||||||
|
"expected_state": "Hello World!",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
),
|
||||||
(
|
(
|
||||||
"A4:C1:38:8D:18:B2",
|
"A4:C1:38:8D:18:B2",
|
||||||
make_bthome_v2_adv(
|
make_bthome_v2_adv(
|
||||||
@ -1080,7 +1094,9 @@ async def test_v2_sensors(
|
|||||||
if ATTR_UNIT_OF_MEASUREMENT in sensor_attr:
|
if ATTR_UNIT_OF_MEASUREMENT in sensor_attr:
|
||||||
# Some sensors don't have a unit of measurement
|
# Some sensors don't have a unit of measurement
|
||||||
assert sensor_attr[ATTR_UNIT_OF_MEASUREMENT] == meas["unit_of_measurement"]
|
assert sensor_attr[ATTR_UNIT_OF_MEASUREMENT] == meas["unit_of_measurement"]
|
||||||
assert sensor_attr[ATTR_STATE_CLASS] == meas["state_class"]
|
if ATTR_STATE_CLASS in sensor_attr:
|
||||||
|
# Some sensors have state class None
|
||||||
|
assert sensor_attr[ATTR_STATE_CLASS] == meas["state_class"]
|
||||||
assert await hass.config_entries.async_unload(entry.entry_id)
|
assert await hass.config_entries.async_unload(entry.entry_id)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user