Repository: home-assistant/core
File: homeassistant/components/route_b_smart_meter/coordinator.py (Python)

Code before:
    def __init__(
        self,
        hass: HomeAssistant,
        entry: BRouteConfigEntry,
    ) -> None:
        """Initialize."""

        self.device = entry.data[CONF_DEVICE]
        self.bid = entry.data[CONF_ID]
        self._password = entry.data[CONF_PASSWORD]

        self.api = Momonga(dev=self.device, rbid=self.bid, pwd=self._password)

        super().__init__(
            hass,
            _LOGGER,
            name=DOMAIN,
            config_entry=entry,
            update_interval=DEFAULT_SCAN_INTERVAL,
        )

        self.device_info_data = BRouteDeviceInfo()

    async def _async_setup(self) -> None:
        await self.hass.async_add_executor_job(self.api.open)
        await self.hass.async_add_executor_job(self._fetch_device_info)

    def _fetch_device_info(self) -> None:
        """Fetch static device information from the smart meter."""
        try:
            self.device_info_data.serial_number = self.api.get_serial_number()
        except MomongaError:
            _LOGGER.debug("Failed to fetch serial number", exc_info=True)

        time.sleep(self.api.internal_xmit_interval)
        try:
            raw = self.api.get_manufacturer_code()
            self.device_info_data.manufacturer_code = raw.hex().upper()
        except MomongaError:
            _LOGGER.debug("Failed to fetch manufacturer code", exc_info=True)

        time.sleep(self.api.internal_xmit_interval)
        try:
            self.device_info_data.echonet_version = (
                self.api.get_standard_version()
            )
        except MomongaError:
            _LOGGER.debug("Failed to fetch ECHONET Lite version", exc_info=True)

    def _get_data(self) -> BRouteData:
        """Get the data from API."""

Review comment (performance):
```suggestion
        def fetch() -> None:
            self.api.open()
            self._fetch_device_info()

        await self.hass.async_add_executor_job(fetch)
```

Running each job independently in the executor is expensive as creating and scheduling a job as also cost. Therefore if possible run everything in a single job

Code after:
        self,
        hass: HomeAssistant,
        entry: BRouteConfigEntry,
    ) -> None:
        """Initialize."""

        self.device = entry.data[CONF_DEVICE]
        self.bid = entry.data[CONF_ID]
        self._password = entry.data[CONF_PASSWORD]

        self.api = Momonga(dev=self.device, rbid=self.bid, pwd=self._password)

        super().__init__(
            hass,
            _LOGGER,
            name=DOMAIN,
            config_entry=entry,
            update_interval=DEFAULT_SCAN_INTERVAL,
        )

        self.device_info_data = BRouteDeviceInfo()

    async def _async_setup(self) -> None:
        def fetch() -> None:
            self.api.open()
            self._fetch_device_info()

        await self.hass.async_add_executor_job(fetch)

    def _fetch_device_info(self) -> None:
        """Fetch static device information from the smart meter."""
        try:
            self.device_info_data.serial_number = self.api.get_serial_number()
        except MomongaError:
            _LOGGER.debug("Failed to fetch serial number", exc_info=True)

        time.sleep(self.api.internal_xmit_interval)
        try:
            raw = self.api.get_manufacturer_code()
            self.device_info_data.manufacturer_code = raw.hex().upper()
        except MomongaError:
            _LOGGER.debug("Failed to fetch manufacturer code", exc_info=True)

        time.sleep(self.api.internal_xmit_interval)
        try:
            self.device_info_data.echonet_version = self.api.get_standard_version()
        except MomongaError:
            _LOGGER.debug("Failed to fetch ECHONET Lite version", exc_info=True)

    def _get_data(self) -> BRouteData:
        """Get the data from API."""