Skip to content

Commit 1731a25

Browse files
bieniuCopilot
andauthored
Implement base entity class for Brother integration (#155714)
Co-authored-by: Copilot <[email protected]>
1 parent ec0edf4 commit 1731a25

File tree

2 files changed

+34
-17
lines changed

2 files changed

+34
-17
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
"""Define the Brother entity."""
2+
3+
from homeassistant.helpers.device_registry import CONNECTION_NETWORK_MAC, DeviceInfo
4+
from homeassistant.helpers.update_coordinator import CoordinatorEntity
5+
6+
from .const import DOMAIN
7+
from .coordinator import BrotherDataUpdateCoordinator
8+
9+
10+
class BrotherPrinterEntity(CoordinatorEntity[BrotherDataUpdateCoordinator]):
11+
"""Define a Brother Printer entity."""
12+
13+
_attr_has_entity_name = True
14+
15+
def __init__(
16+
self,
17+
coordinator: BrotherDataUpdateCoordinator,
18+
) -> None:
19+
"""Initialize."""
20+
super().__init__(coordinator)
21+
self._attr_device_info = DeviceInfo(
22+
configuration_url=f"http://{coordinator.brother.host}/",
23+
identifiers={(DOMAIN, coordinator.brother.serial)},
24+
connections={(CONNECTION_NETWORK_MAC, coordinator.brother.mac)},
25+
serial_number=coordinator.brother.serial,
26+
manufacturer="Brother",
27+
model=coordinator.brother.model,
28+
name=coordinator.brother.model,
29+
sw_version=coordinator.brother.firmware,
30+
)

homeassistant/components/brother/sensor.py

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,12 @@
1919
from homeassistant.const import PERCENTAGE, EntityCategory
2020
from homeassistant.core import HomeAssistant, callback
2121
from homeassistant.helpers import entity_registry as er
22-
from homeassistant.helpers.device_registry import CONNECTION_NETWORK_MAC, DeviceInfo
2322
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
2423
from homeassistant.helpers.typing import StateType
25-
from homeassistant.helpers.update_coordinator import CoordinatorEntity
2624

2725
from .const import DOMAIN
2826
from .coordinator import BrotherConfigEntry, BrotherDataUpdateCoordinator
27+
from .entity import BrotherPrinterEntity
2928

3029
# Coordinator is used to centralize the data updates
3130
PARALLEL_UPDATES = 0
@@ -333,12 +332,9 @@ async def async_setup_entry(
333332
)
334333

335334

336-
class BrotherPrinterSensor(
337-
CoordinatorEntity[BrotherDataUpdateCoordinator], SensorEntity
338-
):
339-
"""Define an Brother Printer sensor."""
335+
class BrotherPrinterSensor(BrotherPrinterEntity, SensorEntity):
336+
"""Define a Brother Printer sensor."""
340337

341-
_attr_has_entity_name = True
342338
entity_description: BrotherSensorEntityDescription
343339

344340
def __init__(
@@ -348,16 +344,7 @@ def __init__(
348344
) -> None:
349345
"""Initialize."""
350346
super().__init__(coordinator)
351-
self._attr_device_info = DeviceInfo(
352-
configuration_url=f"http://{coordinator.brother.host}/",
353-
identifiers={(DOMAIN, coordinator.brother.serial)},
354-
connections={(CONNECTION_NETWORK_MAC, coordinator.brother.mac)},
355-
serial_number=coordinator.brother.serial,
356-
manufacturer="Brother",
357-
model=coordinator.brother.model,
358-
name=coordinator.brother.model,
359-
sw_version=coordinator.brother.firmware,
360-
)
347+
361348
self._attr_native_value = description.value(coordinator.data)
362349
self._attr_unique_id = f"{coordinator.brother.serial.lower()}_{description.key}"
363350
self.entity_description = description

0 commit comments

Comments
 (0)