roborock.devices.traits.v1.volume

 1from dataclasses import dataclass, field
 2
 3from roborock.devices.traits.v1 import common
 4from roborock.roborock_typing import RoborockCommand
 5
 6# TODO: This is currently the pattern for holding all the commands that hold a
 7# single value, but it still seems too verbose. Maybe we can generate these
 8# dynamically or somehow make them less code.
 9
10
11@dataclass
12class SoundVolume(common.RoborockValueBase):
13    """Dataclass for sound volume."""
14
15    volume: int | None = field(default=None, metadata={"roborock_value": True})
16    """Sound volume level (0-100)."""
17
18
19class SoundVolumeTrait(SoundVolume, common.V1TraitMixin):
20    """Trait for controlling the sound volume of a Roborock device."""
21
22    command = RoborockCommand.GET_SOUND_VOLUME
23
24    async def set_volume(self, volume: int) -> None:
25        """Set the sound volume of the device."""
26        await self.rpc_channel.send_command(RoborockCommand.CHANGE_SOUND_VOLUME, params=[volume])
27        self.volume = volume
@dataclass
class SoundVolume(roborock.devices.traits.v1.common.RoborockValueBase):
12@dataclass
13class SoundVolume(common.RoborockValueBase):
14    """Dataclass for sound volume."""
15
16    volume: int | None = field(default=None, metadata={"roborock_value": True})
17    """Sound volume level (0-100)."""

Dataclass for sound volume.

SoundVolume(volume: int | None = None)
volume: int | None = None

Sound volume level (0-100).

class SoundVolumeTrait(SoundVolume, roborock.devices.traits.v1.common.V1TraitMixin):
20class SoundVolumeTrait(SoundVolume, common.V1TraitMixin):
21    """Trait for controlling the sound volume of a Roborock device."""
22
23    command = RoborockCommand.GET_SOUND_VOLUME
24
25    async def set_volume(self, volume: int) -> None:
26        """Set the sound volume of the device."""
27        await self.rpc_channel.send_command(RoborockCommand.CHANGE_SOUND_VOLUME, params=[volume])
28        self.volume = volume

Trait for controlling the sound volume of a Roborock device.

command = <RoborockCommand.GET_SOUND_VOLUME: 'get_sound_volume'>
async def set_volume(self, volume: int) -> None:
25    async def set_volume(self, volume: int) -> None:
26        """Set the sound volume of the device."""
27        await self.rpc_channel.send_command(RoborockCommand.CHANGE_SOUND_VOLUME, params=[volume])
28        self.volume = volume

Set the sound volume of the device.