Add Microphone Mute Switch Entity
Subscribes to the new mic_muted and mic_unmuted events. Provides visual feedback by setting the LEDs to a solid dim red when muted and calling the idle state handler (turning the LEDs off) when unmuted.
This commit is contained in:
@@ -15,6 +15,7 @@ _OFF = (0, 0, 0)
|
||||
_BLUE = (0, 0, 255)
|
||||
_YELLOW = (255, 255, 0)
|
||||
_GREEN = (0, 255, 0)
|
||||
_DIM_RED = (50, 0, 0) # ADDED for Mute
|
||||
|
||||
|
||||
class LedController(EventHandler):
|
||||
@@ -33,7 +34,6 @@ class LedController(EventHandler):
|
||||
try:
|
||||
if interface == "gpio":
|
||||
_LOGGER.debug(f"Initializing LEDs on GPIO data={data_pin}, clock={clock_pin}")
|
||||
# Dynamically get GPIO pin objects from the board library
|
||||
data_pin_obj = getattr(board, f"D{data_pin}")
|
||||
clock_pin_obj = getattr(board, f"D{clock_pin}")
|
||||
self.leds = adafruit_dotstar.DotStar(
|
||||
@@ -47,7 +47,6 @@ class LedController(EventHandler):
|
||||
|
||||
self._is_ready = True
|
||||
_LOGGER.info(f"LED Controller initialized using {interface} interface.")
|
||||
# Signal that the system is ready
|
||||
self.run_action("blink", _GREEN, 2)
|
||||
|
||||
except Exception:
|
||||
@@ -79,12 +78,10 @@ class LedController(EventHandler):
|
||||
try:
|
||||
r, g, b = color
|
||||
while True:
|
||||
# Fade in
|
||||
for i in range(0, 101, 5):
|
||||
brightness = i / 100.0
|
||||
await self.color((int(r * brightness), int(g * brightness), int(b * brightness)))
|
||||
await asyncio.sleep(speed)
|
||||
# Fade out
|
||||
for i in range(100, -1, -5):
|
||||
brightness = i / 100.0
|
||||
await self.color((int(r * brightness), int(g * brightness), int(b * brightness)))
|
||||
@@ -92,7 +89,8 @@ class LedController(EventHandler):
|
||||
except asyncio.CancelledError:
|
||||
await self.color(_OFF)
|
||||
|
||||
# --- THIS IS THE NEWLY ADDED METHOD ---
|
||||
# --- EVENT HANDLERS ---
|
||||
|
||||
@subscribe
|
||||
def ha_connected(self, data: dict):
|
||||
_LOGGER.debug("HA Connected, setting idle LED state.")
|
||||
@@ -111,7 +109,6 @@ class LedController(EventHandler):
|
||||
@subscribe
|
||||
def voice_vad_start(self, data: dict):
|
||||
_LOGGER.debug("LED Event: voice_vad_start (user speaking)")
|
||||
# Do nothing, allow the blue pulse to continue
|
||||
pass
|
||||
|
||||
@subscribe
|
||||
@@ -128,3 +125,15 @@ class LedController(EventHandler):
|
||||
def voice_run_end(self, data: dict):
|
||||
_LOGGER.debug("LED Event: voice_run_end")
|
||||
self.run_action("color", _OFF)
|
||||
|
||||
# --- ADDED: Mute State Handlers ---
|
||||
@subscribe
|
||||
def mic_muted(self, data: dict):
|
||||
_LOGGER.debug("LED Event: Mic muted")
|
||||
self.run_action("color", _DIM_RED)
|
||||
|
||||
@subscribe
|
||||
def mic_unmuted(self, data: dict):
|
||||
_LOGGER.debug("LED Event: Mic unmuted")
|
||||
# Return to the normal idle state (off)
|
||||
self.voice_run_end(data)
|
||||
|
||||
Reference in New Issue
Block a user