diff --git a/homeassistant/components/brother/diagnostics.py b/homeassistant/components/brother/diagnostics.py index 4e2b64b4f56..4733431f8e2 100644 --- a/homeassistant/components/brother/diagnostics.py +++ b/homeassistant/components/brother/diagnostics.py @@ -22,6 +22,8 @@ async def async_get_config_entry_diagnostics( diagnostics_data = { "info": dict(config_entry.data), "data": asdict(coordinator.data), + "model": coordinator.brother.model, + "firmware": coordinator.brother.firmware, } return diagnostics_data diff --git a/homeassistant/components/brother/manifest.json b/homeassistant/components/brother/manifest.json index 06b8574dbb4..26317b39ab5 100644 --- a/homeassistant/components/brother/manifest.json +++ b/homeassistant/components/brother/manifest.json @@ -8,7 +8,7 @@ "iot_class": "local_polling", "loggers": ["brother", "pyasn1", "pysmi", "pysnmp"], "quality_scale": "platinum", - "requirements": ["brother==3.0.0"], + "requirements": ["brother==4.0.0"], "zeroconf": [ { "type": "_printer._tcp.local.", diff --git a/homeassistant/components/brother/sensor.py b/homeassistant/components/brother/sensor.py index d91eb606bae..198fe621246 100644 --- a/homeassistant/components/brother/sensor.py +++ b/homeassistant/components/brother/sensor.py @@ -16,10 +16,10 @@ from homeassistant.components.sensor import ( SensorStateClass, ) from homeassistant.config_entries import ConfigEntry -from homeassistant.const import CONF_HOST, PERCENTAGE, EntityCategory +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 DeviceInfo +from homeassistant.helpers.device_registry import CONNECTION_NETWORK_MAC, DeviceInfo from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.typing import StateType from homeassistant.helpers.update_coordinator import CoordinatorEntity @@ -332,11 +332,11 @@ async def async_setup_entry( # Due to the change of the attribute name of one sensor, it is necessary to migrate # the unique_id to the new one. entity_registry = er.async_get(hass) - old_unique_id = f"{coordinator.data.serial.lower()}_b/w_counter" + old_unique_id = f"{coordinator.brother.serial.lower()}_b/w_counter" if entity_id := entity_registry.async_get_entity_id( PLATFORM, DOMAIN, old_unique_id ): - new_unique_id = f"{coordinator.data.serial.lower()}_bw_counter" + new_unique_id = f"{coordinator.brother.serial.lower()}_bw_counter" _LOGGER.debug( "Migrating entity %s from old unique ID '%s' to new unique ID '%s'", entity_id, @@ -347,19 +347,9 @@ async def async_setup_entry( sensors = [] - device_info = DeviceInfo( - configuration_url=f"http://{entry.data[CONF_HOST]}/", - identifiers={(DOMAIN, coordinator.data.serial)}, - serial_number=coordinator.data.serial, - manufacturer="Brother", - model=coordinator.data.model, - name=coordinator.data.model, - sw_version=coordinator.data.firmware, - ) - for description in SENSOR_TYPES: if description.value(coordinator.data) is not None: - sensors.append(BrotherPrinterSensor(coordinator, description, device_info)) + sensors.append(BrotherPrinterSensor(coordinator, description)) async_add_entities(sensors, False) @@ -375,13 +365,21 @@ class BrotherPrinterSensor( self, coordinator: BrotherDataUpdateCoordinator, description: BrotherSensorEntityDescription, - device_info: DeviceInfo, ) -> None: """Initialize.""" super().__init__(coordinator) - self._attr_device_info = device_info + 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.data.serial.lower()}_{description.key}" + self._attr_unique_id = f"{coordinator.brother.serial.lower()}_{description.key}" self.entity_description = description @callback diff --git a/requirements_all.txt b/requirements_all.txt index 64ae288cf85..e8bc0d0b2ac 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -606,7 +606,7 @@ bring-api==0.4.1 broadlink==0.18.3 # homeassistant.components.brother -brother==3.0.0 +brother==4.0.0 # homeassistant.components.brottsplatskartan brottsplatskartan==1.0.5 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index b94a8b61155..006c6ae8cd2 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -514,7 +514,7 @@ bring-api==0.4.1 broadlink==0.18.3 # homeassistant.components.brother -brother==3.0.0 +brother==4.0.0 # homeassistant.components.brottsplatskartan brottsplatskartan==1.0.5 diff --git a/tests/components/brother/fixtures/printer_data.json b/tests/components/brother/fixtures/printer_data.json index c6fd5042330..aa9ce8cac62 100644 --- a/tests/components/brother/fixtures/printer_data.json +++ b/tests/components/brother/fixtures/printer_data.json @@ -72,5 +72,6 @@ ], "1.3.6.1.4.1.2435.2.3.9.4.2.1.5.5.1.0": "0123456789", "1.3.6.1.4.1.2435.2.3.9.4.2.1.5.4.5.2.0": "WAITING ", - "1.3.6.1.2.1.43.7.1.1.4.1.1": "2004" + "1.3.6.1.2.1.43.7.1.1.4.1.1": "2004", + "1.3.6.1.2.1.2.2.1.6.1": "aa:bb:cc:dd:ee:ff" } diff --git a/tests/components/brother/snapshots/test_diagnostics.ambr b/tests/components/brother/snapshots/test_diagnostics.ambr index 1bff613e557..262f9c75fd6 100644 --- a/tests/components/brother/snapshots/test_diagnostics.ambr +++ b/tests/components/brother/snapshots/test_diagnostics.ambr @@ -31,7 +31,6 @@ 'drum_remaining_pages': 11014, 'drum_status': 1, 'duplex_unit_pages_counter': 538, - 'firmware': '1.17', 'fuser_remaining_life': 97, 'fuser_unit_remaining_pages': None, 'image_counter': None, @@ -47,13 +46,11 @@ 'magenta_toner': 10, 'magenta_toner_remaining': 8, 'magenta_toner_status': 2, - 'model': 'HL-L2340DW', 'page_counter': 986, 'pf_kit_1_remaining_life': 98, 'pf_kit_1_remaining_pages': 48741, 'pf_kit_mp_remaining_life': None, 'pf_kit_mp_remaining_pages': None, - 'serial': '0123456789', 'status': 'waiting', 'uptime': '2019-09-24T12:14:56+00:00', 'yellow_counter': None, @@ -67,9 +64,11 @@ 'yellow_toner_remaining': 2, 'yellow_toner_status': 2, }), + 'firmware': '1.17', 'info': dict({ 'host': 'localhost', 'type': 'laser', }), + 'model': 'HL-L2340DW', }) # ---