Skip to content

Commit

Permalink
Format files and fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
NickM-27 committed Sep 14, 2022
1 parent 7893f85 commit 0dd2013
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 34 deletions.
3 changes: 1 addition & 2 deletions custom_components/frigate/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

import logging
from typing import Any, cast
from custom_components.frigate.icons import get_dynamic_icon_from_type

from homeassistant.components.binary_sensor import (
DEVICE_CLASS_MOTION,
Expand All @@ -26,6 +25,7 @@
get_zones,
)
from .const import ATTR_CONFIG, DOMAIN, NAME
from .icons import get_dynamic_icon_from_type

_LOGGER: logging.Logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -142,7 +142,6 @@ def icon(self) -> str:
return get_dynamic_icon_from_type(self._obj_name, self._is_on)



class FrigateMotionSensor(FrigateMQTTEntity, BinarySensorEntity): # type: ignore[misc]
"""Frigate Motion Sensor class."""

Expand Down
5 changes: 2 additions & 3 deletions custom_components/frigate/icons.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

from xmlrpc.client import Boolean


ICON_BICYCLE = "mdi:bicycle"
ICON_CAR = "mdi:car"
ICON_CAT = "mdi:cat"
Expand All @@ -13,7 +12,7 @@
ICON_FILM_MULTIPLE = "mdi:filmstrip-box-multiple"
ICON_HORSE = "mdi:horse"
ICON_IMAGE_MULTIPLE = "mdi:image-multiple"
ICON_MOTION_SENSOR = "hass:motion-sensor"
ICON_MOTION_SENSOR = "mdi:motion-sensor"
ICON_MOTORCYCLE = "mdi:motorbike"
ICON_OTHER = "mdi:shield-alert"
ICON_PERSON = "mdi:human"
Expand Down Expand Up @@ -54,7 +53,7 @@ def get_icon_from_switch(switch_type: str) -> str:
return ICON_FILM_MULTIPLE
if switch_type == "improve_contrast":
return ICON_CONTRAST

return ICON_MOTION_SENSOR


Expand Down
2 changes: 1 addition & 1 deletion custom_components/frigate/number.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

import logging
from typing import Any
from custom_components.frigate.icons import ICON_SPEEDOMETER

from homeassistant.components.mqtt import async_publish
from homeassistant.components.number import NumberEntity
Expand All @@ -30,6 +29,7 @@
MIN_THRESHOLD,
NAME,
)
from .icons import ICON_SPEEDOMETER

_LOGGER: logging.Logger = logging.getLogger(__name__)

Expand Down
17 changes: 2 additions & 15 deletions custom_components/frigate/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,15 @@
FrigateDataUpdateCoordinator,
FrigateEntity,
FrigateMQTTEntity,
SensorIcons,
ReceiveMessage,
get_cameras_zones_and_objects,
get_friendly_name,
get_frigate_device_identifier,
get_frigate_entity_unique_id,
get_zones,
)
from .const import (
ATTR_CONFIG,
ATTR_COORDINATOR,
DOMAIN,
FPS,
MS,
NAME,
)
from .icons import (
ICON_CORAL,
ICON_SERVER,
ICON_SPEEDOMETER,
get_icon_from_type,
)
from .const import ATTR_CONFIG, ATTR_COORDINATOR, DOMAIN, FPS, MS, NAME
from .icons import ICON_CORAL, ICON_SERVER, ICON_SPEEDOMETER, get_icon_from_type

_LOGGER: logging.Logger = logging.getLogger(__name__)

Expand Down
11 changes: 4 additions & 7 deletions custom_components/frigate/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

import logging
from typing import Any
from custom_components.frigate.icons import get_icon_from_switch

from homeassistant.components.mqtt import async_publish
from homeassistant.components.switch import SwitchEntity
Expand All @@ -20,11 +19,8 @@
get_frigate_device_identifier,
get_frigate_entity_unique_id,
)
from .const import (
ATTR_CONFIG,
DOMAIN,
NAME,
)
from .const import ATTR_CONFIG, DOMAIN, NAME
from .icons import get_icon_from_switch

_LOGGER: logging.Logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -73,7 +69,8 @@ def __init__(
)

self._attr_entity_registry_enabled_default = default_enabled
self._icon = get_icon_from_switch(self._switch_name)uper().__init__(
self._icon = get_icon_from_switch(self._switch_name)
super().__init__(
config_entry,
frigate_config,
{
Expand Down
50 changes: 50 additions & 0 deletions tests/test_icons.py
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"
7 changes: 2 additions & 5 deletions tests/test_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@

from custom_components.frigate import SCAN_INTERVAL
from custom_components.frigate.api import FrigateApiClientError
from custom_components.frigate.const import (
DOMAIN,
FPS,
from custom_components.frigate.const import DOMAIN, FPS, MS, NAME
from custom_components.frigate.icons import (
ICON_BICYCLE,
ICON_CAR,
ICON_CAT,
Expand All @@ -29,8 +28,6 @@
ICON_PERSON,
ICON_SERVER,
ICON_SPEEDOMETER,
MS,
NAME,
)
from homeassistant.const import TEMP_CELSIUS
from homeassistant.core import HomeAssistant
Expand Down
2 changes: 1 addition & 1 deletion tests/test_switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ async def test_switch_icon(hass: HomeAssistant) -> None:
await setup_mock_frigate_config_entry(hass)

expected_results = {
TEST_SWITCH_FRONT_DOOR_DETECT_ENTITY_ID: "hass:motion-sensor",
TEST_SWITCH_FRONT_DOOR_DETECT_ENTITY_ID: "mdi:motion-sensor",
TEST_SWITCH_FRONT_DOOR_RECORDINGS_ENTITY_ID: "mdi:filmstrip-box-multiple",
TEST_SWITCH_FRONT_DOOR_SNAPSHOTS_ENTITY_ID: "mdi:image-multiple",
}
Expand Down

0 comments on commit 0dd2013

Please sign in to comment.