Skip to content

Commit

Permalink
Revert music
Browse files Browse the repository at this point in the history
  • Loading branch information
Galorhallen committed Oct 20, 2024
1 parent c813500 commit 5e36949
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 78 deletions.
6 changes: 3 additions & 3 deletions example/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ async def print_status(controller: GoveeController, device: GoveeDevice):
while True:
if not device or not device.capabilities:
continue
for music in device.capabilities.available_musics:
print(f"Music: {music}")
await device.set_music(music)
for scene in device.capabilities.available_scenes:
print(f"scene: {scene}")
await device.set_scene(scene)
await asyncio.sleep(10)

await asyncio.sleep(1)
Expand Down
17 changes: 0 additions & 17 deletions src/govee_local_api/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
BrightnessMessage,
ColorMessage,
SceneMessages,
MusicMessage,
GoveeMessage,
MessageResponseFactory,
OnOffMessage,
Expand Down Expand Up @@ -262,22 +261,6 @@ async def set_scene(self, device: GoveeDevice, scene: str) -> None:
return
self._send_message(SceneMessages(scene_code), device)

async def set_music(self, device: GoveeDevice, music: str) -> None:
if (
not device.capabilities
or device.capabilities.features & GoveeLightFeatures.MUSIC == 0
):
self._logger.warning("Music is not supported by device %s", device)
return

music_code: bytes | None = device.capabilities.musics.get(music.lower(), None)
if not music_code:
self._logger.warning(
"Music %s is not available for device %s", music, device
)
return
self._send_message(MusicMessage(music_code), device)

async def set_brightness(self, device: GoveeDevice, brightness: int) -> None:
self._send_message(BrightnessMessage(brightness), device)

Expand Down
65 changes: 19 additions & 46 deletions src/govee_local_api/light_capabilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ class GoveeLightFeatures(IntFlag):
BRIGHTNESS = 0x04
SEGMENT_CONTROL = 0x08
SCENES = 0x10
MUSIC = 0x20


COMMON_FEATURES: GoveeLightFeatures = (
Expand All @@ -25,14 +24,12 @@ def __init__(
features: GoveeLightFeatures,
segments: list[bytes] = [],
scenes: dict[str, bytes] = {},
musics: dict[str, bytes] = {},
) -> None:
self.features = features
self.segments = (
segments if features & GoveeLightFeatures.SEGMENT_CONTROL else []
)
self.scenes = scenes if features & GoveeLightFeatures.SCENES else {}
self.musics = musics if features & GoveeLightFeatures.MUSIC else {}

@property
def segments_count(self) -> int:
Expand All @@ -42,10 +39,6 @@ def segments_count(self) -> int:
def available_scenes(self) -> list[str]:
return list(self.scenes.keys())

@property
def available_musics(self) -> list[str]:
return list(self.musics.keys())

def __repr__(self) -> str:
return f"GoveeLightCapabilities(features={self.features!r}, segments={self.segments!r}, scenes={self.scenes!r})"

Expand Down Expand Up @@ -86,19 +79,9 @@ def __str__(self) -> str:
"rainbow": b"\x15",
}

MUSIC_MODES: dict[str, bytes] = {
"energetic": b"\x00",
"rhythm": b"\x03",
}


def create_with_capabilities(
rgb: bool,
temperature: bool,
brightness: bool,
segments: int,
scenes: bool,
music: bool,
rgb: bool, temperature: bool, brightness: bool, segments: int, scenes: bool
) -> GoveeLightCapabilities:
features: GoveeLightFeatures = GoveeLightFeatures(0)
segments_codes = []
Expand All @@ -115,24 +98,14 @@ def create_with_capabilities(

if scenes:
features = features | GoveeLightFeatures.SCENES
if music:
features = features | GoveeLightFeatures.MUSIC

return GoveeLightCapabilities(
features,
segments_codes,
SCENE_CODES if scenes else {},
MUSIC_MODES if music else {},
features, segments_codes, SCENE_CODES if scenes else {}
)


COMMON_CAPABILITIES = create_with_capabilities(
rgb=True,
temperature=True,
brightness=True,
segments=0,
scenes=True,
music=True,
rgb=True, temperature=True, brightness=True, segments=0, scenes=True
)

GOVEE_LIGHT_CAPABILITIES: dict[str, GoveeLightCapabilities] = {
Expand All @@ -157,24 +130,24 @@ def create_with_capabilities(
"H6110": COMMON_CAPABILITIES,
"H6117": COMMON_CAPABILITIES,
"H6159": COMMON_CAPABILITIES,
"H615A": create_with_capabilities(True, True, True, 0, True, True),
"H615B": create_with_capabilities(True, True, True, 0, True, True),
"H615C": create_with_capabilities(True, True, True, 0, True, True),
"H615D": create_with_capabilities(True, True, True, 0, True, True),
"H615E": create_with_capabilities(True, True, True, 0, True, True),
"H615A": create_with_capabilities(True, True, True, 0, True),
"H615B": create_with_capabilities(True, True, True, 0, True),
"H615C": create_with_capabilities(True, True, True, 0, True),
"H615D": create_with_capabilities(True, True, True, 0, True),
"H615E": create_with_capabilities(True, True, True, 0, True),
"H6163": COMMON_CAPABILITIES,
"H6168": COMMON_CAPABILITIES,
"H6172": COMMON_CAPABILITIES,
"H6173": COMMON_CAPABILITIES,
"H618A": create_with_capabilities(True, True, True, 15, True, True),
"H618C": create_with_capabilities(True, True, True, 15, True, True),
"H618E": create_with_capabilities(True, True, True, 15, True, True),
"H618F": create_with_capabilities(True, True, True, 15, True, True),
"H619A": create_with_capabilities(True, True, True, 10, True, True),
"H619B": create_with_capabilities(True, True, True, 10, True, True),
"H619C": create_with_capabilities(True, True, True, 10, True, True),
"H619D": create_with_capabilities(True, True, True, 10, True, True),
"H619E": create_with_capabilities(True, True, True, 10, True, True),
"H618A": create_with_capabilities(True, True, True, 15, True),
"H618C": create_with_capabilities(True, True, True, 15, True),
"H618E": create_with_capabilities(True, True, True, 15, True),
"H618F": create_with_capabilities(True, True, True, 15, True),
"H619A": create_with_capabilities(True, True, True, 10, True),
"H619B": create_with_capabilities(True, True, True, 10, True),
"H619C": create_with_capabilities(True, True, True, 10, True),
"H619D": create_with_capabilities(True, True, True, 10, True),
"H619E": create_with_capabilities(True, True, True, 10, True),
"H619Z": COMMON_CAPABILITIES,
"H61A0": COMMON_CAPABILITIES,
"H61A1": COMMON_CAPABILITIES,
Expand Down Expand Up @@ -233,6 +206,6 @@ def create_with_capabilities(
"H70B1": COMMON_CAPABILITIES,
"H70A1": COMMON_CAPABILITIES,
# Models with only brightness
"H7012": create_with_capabilities(False, False, True, 0, False, False),
"H7013": create_with_capabilities(False, False, True, 0, False, False),
"H7012": create_with_capabilities(False, False, True, 0, False),
"H7013": create_with_capabilities(False, False, True, 0, False),
}
12 changes: 0 additions & 12 deletions src/govee_local_api/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,18 +136,6 @@ def __init__(self, scene: bytes) -> None:
super().__init__([data])


class MusicMessage(GoveeMessage):
command = "ptReal"

def __init__(self, music: bytes) -> None:
data = (
b"\x33\x05\x13"
+ b"\x05\x63"
+ b"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
)
super().__init__([data])


class ScanResponse(GoveeMessage):
command = "scan"

Expand Down

0 comments on commit 5e36949

Please sign in to comment.