Skip to content

Commit

Permalink
Don't use extra function
Browse files Browse the repository at this point in the history
  • Loading branch information
NickM-27 committed Jul 1, 2023
1 parent 934bd99 commit 484f853
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions custom_components/frigate/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ async def async_setup_entry(
.get("enabled_in_config", False)
):
entities.append(
FrigateSwitch(entry, frigate_config, camera, "audio", True),
FrigateSwitch(
entry, frigate_config, camera, "audio", True, "audio_detection"
),
)

async_add_entities(entities)
Expand All @@ -67,6 +69,7 @@ def __init__(
cam_name: str,
switch_name: str,
default_enabled: bool,
descriptive_name: str = "",
) -> None:
"""Construct a FrigateSwitch."""
self._frigate_config = frigate_config
Expand All @@ -77,6 +80,7 @@ def __init__(
f"{frigate_config['mqtt']['topic_prefix']}"
f"/{self._cam_name}/{self._switch_name}/set"
)
self._descriptive_name = descriptive_name if descriptive_name else switch_name

self._attr_entity_registry_enabled_default = default_enabled
self._icon = get_icon_from_switch(self._switch_name)
Expand Down Expand Up @@ -127,7 +131,7 @@ def device_info(self) -> DeviceInfo:
@property
def name(self) -> str:
"""Return the name of the sensor."""
return f"{get_friendly_name(self._get_descriptive_name())}".title()
return f"{get_friendly_name(self._descriptive_name)}".title()

@property
def is_on(self) -> bool:
Expand Down Expand Up @@ -158,10 +162,3 @@ async def async_turn_off(self, **kwargs: Any) -> None:
0,
False,
)

def _get_descriptive_name(self) -> str:
"""Returns a more descriptive name for the switch."""
if self._switch_name == "audio":
return "audio_detection"

return self._switch_name

0 comments on commit 484f853

Please sign in to comment.