generated from ludeeus/integration_blueprint
-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support dynamic icons for binary sensors (#336)
* Move icons to own module * Remove icons from const * Update sensors to use new icons module * Add dynamic binary sensor icons * Support switch icons * Format files and fix tests * Cleanup return Co-authored-by: Dermot Duffy <dermot.duffy@gmail.com> * Cleanup return Co-authored-by: Dermot Duffy <dermot.duffy@gmail.com> * Cleanup return Co-authored-by: Dermot Duffy <dermot.duffy@gmail.com> * Remove odd boolean type * Fix indentation Co-authored-by: Dermot Duffy <dermot.duffy@gmail.com>
- Loading branch information
1 parent
1c96743
commit 387af4d
Showing
9 changed files
with
136 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
"""Handles icons for different entity types.""" | ||
|
||
ICON_BICYCLE = "mdi:bicycle" | ||
ICON_CAR = "mdi:car" | ||
ICON_CAT = "mdi:cat" | ||
ICON_CONTRAST = "mdi:contrast-circle" | ||
ICON_CORAL = "mdi:scoreboard-outline" | ||
ICON_COW = "mdi:cow" | ||
ICON_DOG = "mdi:dog-side" | ||
ICON_FILM_MULTIPLE = "mdi:filmstrip-box-multiple" | ||
ICON_HORSE = "mdi:horse" | ||
ICON_IMAGE_MULTIPLE = "mdi:image-multiple" | ||
ICON_MOTION_SENSOR = "mdi:motion-sensor" | ||
ICON_MOTORCYCLE = "mdi:motorbike" | ||
ICON_OTHER = "mdi:shield-alert" | ||
ICON_PERSON = "mdi:human" | ||
ICON_SERVER = "mdi:server" | ||
ICON_SPEEDOMETER = "mdi:speedometer" | ||
|
||
ICON_DEFAULT_ON = "mdi:home" | ||
|
||
ICON_CAR_OFF = "mdi:car-off" | ||
ICON_DEFAULT_OFF = "mdi:home-outline" | ||
ICON_DOG_OFF = "mdi:dog-side-off" | ||
|
||
|
||
def get_dynamic_icon_from_type(obj_type: str, is_on: bool) -> str: | ||
"""Get icon for a specific object type and current state.""" | ||
|
||
if obj_type == "car": | ||
return ICON_CAR if is_on else ICON_CAR_OFF | ||
if obj_type == "dog": | ||
return ICON_DOG if is_on else ICON_DOG_OFF | ||
|
||
return ICON_DEFAULT_ON if is_on else ICON_DEFAULT_OFF | ||
|
||
|
||
def get_icon_from_switch(switch_type: str) -> str: | ||
"""Get icon for a specific switch type.""" | ||
if switch_type == "snapshots": | ||
return ICON_IMAGE_MULTIPLE | ||
if switch_type == "recordings": | ||
return ICON_FILM_MULTIPLE | ||
if switch_type == "improve_contrast": | ||
return ICON_CONTRAST | ||
|
||
return ICON_MOTION_SENSOR | ||
|
||
|
||
def get_icon_from_type(obj_type: str) -> str: | ||
"""Get icon for a specific object type.""" | ||
|
||
if obj_type == "person": | ||
return ICON_PERSON | ||
if obj_type == "car": | ||
return ICON_CAR | ||
if obj_type == "dog": | ||
return ICON_DOG | ||
if obj_type == "cat": | ||
return ICON_CAT | ||
if obj_type == "motorcycle": | ||
return ICON_MOTORCYCLE | ||
if obj_type == "bicycle": | ||
return ICON_BICYCLE | ||
if obj_type == "cow": | ||
return ICON_COW | ||
if obj_type == "horse": | ||
return ICON_HORSE | ||
|
||
return ICON_OTHER |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
"""Tests frigate icons.""" | ||
|
||
from custom_components.frigate.icons import ( | ||
get_dynamic_icon_from_type, | ||
get_icon_from_switch, | ||
get_icon_from_type, | ||
) | ||
|
||
|
||
async def test_get_binary_sensor_icons() -> None: | ||
"""Test sensor icon logic.""" | ||
assert get_dynamic_icon_from_type("person", True) == "mdi:home" | ||
assert get_dynamic_icon_from_type("person", False) == "mdi:home-outline" | ||
assert get_dynamic_icon_from_type("car", True) == "mdi:car" | ||
assert get_dynamic_icon_from_type("car", False) == "mdi:car-off" | ||
assert get_dynamic_icon_from_type("dog", True) == "mdi:dog-side" | ||
assert get_dynamic_icon_from_type("dog", False) == "mdi:dog-side-off" | ||
assert get_dynamic_icon_from_type("cat", True) == "mdi:home" | ||
assert get_dynamic_icon_from_type("cat", False) == "mdi:home-outline" | ||
assert get_dynamic_icon_from_type("motorcycle", True) == "mdi:home" | ||
assert get_dynamic_icon_from_type("motorcycle", False) == "mdi:home-outline" | ||
assert get_dynamic_icon_from_type("bicycle", True) == "mdi:home" | ||
assert get_dynamic_icon_from_type("bycicle", False) == "mdi:home-outline" | ||
assert get_dynamic_icon_from_type("cow", True) == "mdi:home" | ||
assert get_dynamic_icon_from_type("cow", False) == "mdi:home-outline" | ||
assert get_dynamic_icon_from_type("horse", True) == "mdi:home" | ||
assert get_dynamic_icon_from_type("horse", False) == "mdi:home-outline" | ||
assert get_dynamic_icon_from_type("other", True) == "mdi:home" | ||
assert get_dynamic_icon_from_type("other", False) == "mdi:home-outline" | ||
|
||
|
||
async def test_get_sensor_icons() -> None: | ||
"""Test sensor icon logic.""" | ||
assert get_icon_from_type("person") == "mdi:human" | ||
assert get_icon_from_type("car") == "mdi:car" | ||
assert get_icon_from_type("dog") == "mdi:dog-side" | ||
assert get_icon_from_type("cat") == "mdi:cat" | ||
assert get_icon_from_type("motorcycle") == "mdi:motorbike" | ||
assert get_icon_from_type("bicycle") == "mdi:bicycle" | ||
assert get_icon_from_type("cow") == "mdi:cow" | ||
assert get_icon_from_type("horse") == "mdi:horse" | ||
assert get_icon_from_type("other") == "mdi:shield-alert" | ||
|
||
|
||
async def test_get_switch_icons() -> None: | ||
"""Test switch icon logic.""" | ||
assert get_icon_from_switch("improve_contrast") == "mdi:contrast-circle" | ||
assert get_icon_from_switch("snapshots") == "mdi:image-multiple" | ||
assert get_icon_from_switch("recordings") == "mdi:filmstrip-box-multiple" | ||
assert get_icon_from_switch("motion") == "mdi:motion-sensor" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters