Repository: home-assistant/core
File: homeassistant/components/google_assistant/trait.py (Python)

Code before:

@register_trait
class FanSpeedTrait(_Trait):
    """Trait to control speed of Fan.

    https://developers.google.com/actions/smarthome/traits/fanspeed
    """

    name = TRAIT_FAN_SPEED
    commands = [COMMAND_SET_FAN_SPEED, COMMAND_REVERSE]

    def __init__(self, hass, state, config):
        """Initialize a trait for a state."""
        super().__init__(hass, state, config)
        if state.domain == fan.DOMAIN:
            speed_count = round(
                100
                / (self.state.attributes.get(fan.ATTR_PERCENTAGE_STEP) or 1.0)
            )
            self._ordered_speed = (
                [
                    f"{speed}/{speed_count}"
                    for speed in range(1, speed_count + 1)
                ]
                if 0 < speed_count <= FAN_SPEED_MAX_SPEED_COUNT
                else []
            )

    @staticmethod
    def supported(domain, features, device_class, _):
        """Test if state is supported."""
        if domain == fan.DOMAIN:
            return features & FanEntityFeature.SET_SPEED
        if domain == climate.DOMAIN:
            return features & ClimateEntityFeature.FAN_MODE
        return False

    def sync_attributes(self) -> dict[str, Any]:
        """Return speed point and modes attributes for a sync request."""
        domain = self.state.domain
        speeds = []
        result: dict[str, Any] = {}

        if domain == fan.DOMAIN:
            reversible = bool(
                self.state.attributes.get(ATTR_SUPPORTED_FEATURES, 0)
                & FanEntityFeature.DIRECTION
            )

            result.update(
                {

Review comment (suggestion):
```suggestion
            if speed_count <= FAN_SPEED_MAX_SPEED_COUNT:
	            self._ordered_speed = [
	                    f"{speed}/{speed_count}"
	                    for speed in range(1, speed_count + 1)
	                ]
            else:
                self._ordered_speed = []
```
nitpick, but I think it makes it bit easier to read. we can also drop the `> 0` one.

Code after:

@register_trait
class FanSpeedTrait(_Trait):
    """Trait to control speed of Fan.

    https://developers.google.com/actions/smarthome/traits/fanspeed
    """

    name = TRAIT_FAN_SPEED
    commands = [COMMAND_SET_FAN_SPEED, COMMAND_REVERSE]

    def __init__(self, hass, state, config):
        """Initialize a trait for a state."""
        super().__init__(hass, state, config)
        if state.domain == fan.DOMAIN:
            speed_count = round(
                100 / (self.state.attributes.get(fan.ATTR_PERCENTAGE_STEP) or 1.0)
            )
            if speed_count <= FAN_SPEED_MAX_SPEED_COUNT:
                self._ordered_speed = [
                    f"{speed}/{speed_count}" for speed in range(1, speed_count + 1)
                ]
            else:
                self._ordered_speed = []

    @staticmethod
    def supported(domain, features, device_class, _):
        """Test if state is supported."""
        if domain == fan.DOMAIN:
            return features & FanEntityFeature.SET_SPEED
        if domain == climate.DOMAIN:
            return features & ClimateEntityFeature.FAN_MODE
        return False

    def sync_attributes(self) -> dict[str, Any]:
        """Return speed point and modes attributes for a sync request."""
        domain = self.state.domain
        speeds = []
        result: dict[str, Any] = {}

        if domain == fan.DOMAIN:
            reversible = bool(
                self.state.attributes.get(ATTR_SUPPORTED_FEATURES, 0)
                & FanEntityFeature.DIRECTION
            )

            result.update(
                {
                    "reversible": reversible,
                    # supportsFanSpeedPercent is mutually exclusive with
                    # availableFanSpeeds, where supportsFanSpeedPercent takes