From 1731a2534c573b46f4e3c9dd4e01c92519eb615e Mon Sep 17 00:00:00 2001 From: Maciej Bieniek Date: Tue, 4 Nov 2025 20:28:52 +0100 Subject: [PATCH] Implement base entity class for Brother integration (#155714) Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- homeassistant/components/brother/entity.py | 30 ++++++++++++++++++++++ homeassistant/components/brother/sensor.py | 21 +++------------ 2 files changed, 34 insertions(+), 17 deletions(-) create mode 100644 homeassistant/components/brother/entity.py diff --git a/homeassistant/components/brother/entity.py b/homeassistant/components/brother/entity.py new file mode 100644 index 000000000000..827dac495758 --- /dev/null +++ b/homeassistant/components/brother/entity.py @@ -0,0 +1,30 @@ +"""Define the Brother entity.""" + +from homeassistant.helpers.device_registry import CONNECTION_NETWORK_MAC, DeviceInfo +from homeassistant.helpers.update_coordinator import CoordinatorEntity + +from .const import DOMAIN +from .coordinator import BrotherDataUpdateCoordinator + + +class BrotherPrinterEntity(CoordinatorEntity[BrotherDataUpdateCoordinator]): + """Define a Brother Printer entity.""" + + _attr_has_entity_name = True + + def __init__( + self, + coordinator: BrotherDataUpdateCoordinator, + ) -> None: + """Initialize.""" + super().__init__(coordinator) + self._attr_device_info = DeviceInfo( + configuration_url=f"http://{coordinator.brother.host}/", + identifiers={(DOMAIN, coordinator.brother.serial)}, + connections={(CONNECTION_NETWORK_MAC, coordinator.brother.mac)}, + serial_number=coordinator.brother.serial, + manufacturer="Brother", + model=coordinator.brother.model, + name=coordinator.brother.model, + sw_version=coordinator.brother.firmware, + ) diff --git a/homeassistant/components/brother/sensor.py b/homeassistant/components/brother/sensor.py index 4d18ed047df0..873e734b1d6c 100644 --- a/homeassistant/components/brother/sensor.py +++ b/homeassistant/components/brother/sensor.py @@ -19,13 +19,12 @@ from homeassistant.components.sensor import ( from homeassistant.const import PERCENTAGE, EntityCategory from homeassistant.core import HomeAssistant, callback from homeassistant.helpers import entity_registry as er -from homeassistant.helpers.device_registry import CONNECTION_NETWORK_MAC, DeviceInfo from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback from homeassistant.helpers.typing import StateType -from homeassistant.helpers.update_coordinator import CoordinatorEntity from .const import DOMAIN from .coordinator import BrotherConfigEntry, BrotherDataUpdateCoordinator +from .entity import BrotherPrinterEntity # Coordinator is used to centralize the data updates PARALLEL_UPDATES = 0 @@ -333,12 +332,9 @@ async def async_setup_entry( ) -class BrotherPrinterSensor( - CoordinatorEntity[BrotherDataUpdateCoordinator], SensorEntity -): - """Define an Brother Printer sensor.""" +class BrotherPrinterSensor(BrotherPrinterEntity, SensorEntity): + """Define a Brother Printer sensor.""" - _attr_has_entity_name = True entity_description: BrotherSensorEntityDescription def __init__( @@ -348,16 +344,7 @@ class BrotherPrinterSensor( ) -> None: """Initialize.""" super().__init__(coordinator) - self._attr_device_info = DeviceInfo( - configuration_url=f"http://{coordinator.brother.host}/", - identifiers={(DOMAIN, coordinator.brother.serial)}, - connections={(CONNECTION_NETWORK_MAC, coordinator.brother.mac)}, - serial_number=coordinator.brother.serial, - manufacturer="Brother", - model=coordinator.brother.model, - name=coordinator.brother.model, - sw_version=coordinator.brother.firmware, - ) + self._attr_native_value = description.value(coordinator.data) self._attr_unique_id = f"{coordinator.brother.serial.lower()}_{description.key}" self.entity_description = description