Repository: home-assistant/core
File: homeassistant/components/waterfurnace/sensor.py (Python)

Code before:
    """Implementing the Waterfurnace sensor."""

    _attr_should_poll = False
    _attr_has_entity_name = True

    def __init__(
        self, client: WaterFurnaceData, description: SensorEntityDescription
    ) -> None:
        """Initialize the sensor."""
        self.client = client
        self.entity_description = description

        # This ensures that the sensors are isolated per waterfurnace unit
        self.entity_id = ENTITY_ID_FORMAT.format(
            f"wf_{slugify(self.client.unit)}_{slugify(description.key)}"
        )
        self._attr_unique_id = f"{self.client.unit}_{description.key}"

    @property
    def device_info(self) -> DeviceInfo:
        """Return device information."""
        device_info = DeviceInfo(
            identifiers={(DOMAIN, self.client.unit)},
            manufacturer="WaterFurnace",
        )

        if self.client.client.devices:
            for device in self.client.client.devices:
                if device.gwid == self.client.unit:
                    if device.description:
                        # Eg. Series 7
                        device_info["model"] = device.description
                    if device.awlabctypedesc:
                        # Eg. Series 7, 5 Ton
                        device_info["name"] = device.awlabctypedesc

                    break

        # Fallback name if no information found
        if "name" not in device_info:
            device_info["name"] = "WaterFurnace System"

        return device_info

    async def async_added_to_hass(self) -> None:
        """Register callbacks."""
        self.async_on_remove(
            async_dispatcher_connect(
                self.hass, UPDATE_TOPIC, self.async_update_callback
            )
        )

Review comment (suggestion):
Can this be set during initialisation?
Also, I suggest to set the name directly in the constructor
```python
        self._attr_device_info = DeviceInfo(
            identifiers={(DOMAIN, self.client.unit)},
            manufacturer="WaterFurnace",
            name = "WaterFurnace System",
        )
        if ...:
            self._attr_device_info["name"] = device.xxx
```

Code after:
    )


class WaterFurnaceSensor(SensorEntity):
    """Implementing the Waterfurnace sensor."""

    _attr_should_poll = False
    _attr_has_entity_name = True

    def __init__(
        self, client: WaterFurnaceData, description: SensorEntityDescription
    ) -> None:
        """Initialize the sensor."""
        self.client = client
        self.entity_description = description

        # This ensures that the sensors are isolated per waterfurnace unit
        self.entity_id = ENTITY_ID_FORMAT.format(
            f"wf_{slugify(self.client.unit)}_{slugify(description.key)}"
        )
        self._attr_unique_id = f"{self.client.unit}_{description.key}"
        device_info = DeviceInfo(
            identifiers={(DOMAIN, self.client.unit)},
            manufacturer="WaterFurnace",
            name="WaterFurnace System",
        )

        if self.client.device_metadata:
            if self.client.device_metadata.description:
                # Eg. Series 7
                device_info["model"] = self.client.device_metadata.description
            if self.client.device_metadata.awlabctypedesc:
                # Eg. Series 7, 5 Ton
                device_info["name"] = self.client.device_metadata.awlabctypedesc

        self._attr_device_info = device_info

    async def async_added_to_hass(self) -> None:
        """Register callbacks."""
        self.async_on_remove(
            async_dispatcher_connect(
                self.hass, UPDATE_TOPIC, self.async_update_callback
            )
        )

    @callback
    def async_update_callback(self):
        """Update state."""
        if self.client.data is not None:
            self._attr_native_value = getattr(
                self.client.data, self.entity_description.key, None