Add entity translations for Aladdin Connect (#95051)

pull/95061/head^2
Joost Lekkerkerker 2023-06-22 16:01:51 +02:00 committed by GitHub
parent ede84d74c7
commit acdf309c47
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 30 additions and 27 deletions

View File

@ -40,26 +40,24 @@ class AladdinDevice(CoverEntity):
_attr_device_class = CoverDeviceClass.GARAGE
_attr_supported_features = SUPPORTED_FEATURES
_attr_has_entity_name = True
_attr_name = None
def __init__(
self, acc: AladdinConnectClient, device: DoorDevice, entry: ConfigEntry
) -> None:
"""Initialize the Aladdin Connect cover."""
self._acc = acc
self._entry_id = entry.entry_id
self._device_id = device["device_id"]
self._number = device["door_number"]
self._name = device["name"]
self._serial = device["serial"]
self._model = device["model"]
self._attr_device_info = DeviceInfo(
identifiers={(DOMAIN, f"{self._device_id}-{self._number}")},
name=self._name,
name=device["name"],
manufacturer="Overhead Door",
model=self._model,
model=device["model"],
)
self._attr_has_entity_name = True
self._attr_unique_id = f"{self._device_id}-{self._number}"
async def async_added_to_hass(self) -> None:

View File

@ -40,7 +40,6 @@ class AccSensorEntityDescription(
SENSORS: tuple[AccSensorEntityDescription, ...] = (
AccSensorEntityDescription(
key="battery_level",
name="Battery level",
device_class=SensorDeviceClass.BATTERY,
entity_registry_enabled_default=False,
native_unit_of_measurement=PERCENTAGE,
@ -49,7 +48,7 @@ SENSORS: tuple[AccSensorEntityDescription, ...] = (
),
AccSensorEntityDescription(
key="rssi",
name="Wi-Fi RSSI",
translation_key="wifi_strength",
device_class=SensorDeviceClass.SIGNAL_STRENGTH,
entity_registry_enabled_default=False,
native_unit_of_measurement=SIGNAL_STRENGTH_DECIBELS,
@ -58,7 +57,7 @@ SENSORS: tuple[AccSensorEntityDescription, ...] = (
),
AccSensorEntityDescription(
key="ble_strength",
name="BLE Strength",
translation_key="ble_strength",
device_class=SensorDeviceClass.SIGNAL_STRENGTH,
entity_registry_enabled_default=False,
native_unit_of_measurement=SIGNAL_STRENGTH_DECIBELS,
@ -89,8 +88,8 @@ async def async_setup_entry(
class AladdinConnectSensor(SensorEntity):
"""A sensor implementation for Aladdin Connect devices."""
_device: AladdinConnectSensor
entity_description: AccSensorEntityDescription
_attr_has_entity_name = True
def __init__(
self,
@ -101,24 +100,20 @@ class AladdinConnectSensor(SensorEntity):
"""Initialize a sensor for an Aladdin Connect device."""
self._device_id = device["device_id"]
self._number = device["door_number"]
self._name = device["name"]
self._model = device["model"]
self._acc = acc
self.entity_description = description
self._attr_unique_id = f"{self._device_id}-{self._number}-{description.key}"
self._attr_has_entity_name = True
if self._model == "01" and description.key in ("battery_level", "ble_strength"):
self._attr_entity_registry_enabled_default = True
@property
def device_info(self) -> DeviceInfo | None:
"""Device information for Aladdin Connect sensors."""
return DeviceInfo(
self._attr_device_info = DeviceInfo(
identifiers={(DOMAIN, f"{self._device_id}-{self._number}")},
name=self._name,
name=device["name"],
manufacturer="Overhead Door",
model=self._model,
model=device["model"],
)
if device["model"] == "01" and description.key in (
"battery_level",
"ble_strength",
):
self._attr_entity_registry_enabled_default = True
@property
def native_value(self) -> float | None:

View File

@ -25,5 +25,15 @@
"already_configured": "[%key:common::config_flow::abort::already_configured_device%]",
"reauth_successful": "[%key:common::config_flow::abort::reauth_successful%]"
}
},
"entity": {
"sensor": {
"wifi_strength": {
"name": "Wi-Fi RSSI"
},
"ble_strength": {
"name": "BLE Strength"
}
}
}
}

View File

@ -47,7 +47,7 @@ async def test_sensors(
await hass.config_entries.async_setup(config_entry.entry_id)
await hass.async_block_till_done()
entry = entity_registry.async_get("sensor.home_battery_level")
entry = entity_registry.async_get("sensor.home_battery")
assert entry
assert entry.disabled
assert entry.disabled_by is er.RegistryEntryDisabler.INTEGRATION
@ -57,7 +57,7 @@ async def test_sensors(
await hass.async_block_till_done()
assert update_entry != entry
assert update_entry.disabled is False
state = hass.states.get("sensor.home_battery_level")
state = hass.states.get("sensor.home_battery")
assert state is None
async_fire_time_changed(
@ -65,7 +65,7 @@ async def test_sensors(
utcnow() + SCAN_INTERVAL,
)
await hass.async_block_till_done()
state = hass.states.get("sensor.home_battery_level")
state = hass.states.get("sensor.home_battery")
assert state
entry = entity_registry.async_get("sensor.home_wi_fi_rssi")
@ -121,11 +121,11 @@ async def test_sensors_model_01(
await hass.config_entries.async_setup(config_entry.entry_id)
await hass.async_block_till_done()
entry = entity_registry.async_get("sensor.home_battery_level")
entry = entity_registry.async_get("sensor.home_battery")
assert entry
assert entry.disabled is False
assert entry.disabled_by is None
state = hass.states.get("sensor.home_battery_level")
state = hass.states.get("sensor.home_battery")
assert state
entry = entity_registry.async_get("sensor.home_wi_fi_rssi")