Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unify usage of Icons #2814

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
8 changes: 5 additions & 3 deletions .github/workflows/validate.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ jobs:

steps:
- uses: actions/checkout@v4
- name: Set up Python 3.10
- name: Set up Python 3.11
uses: actions/setup-python@v5
with:
python-version: "3.10"
python-version: "3.11"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
Expand All @@ -39,4 +39,6 @@ jobs:
- name: check for changed files
run: |
git diff --exit-code || (echo "looks like the update_docu_links.py did not run" && false)

- name: check no custom icon definitions in sources
run: |
./script/check_icon_use.sh || (echo "looks like some source is not properly configured for icon declaration, check log" && false)
19 changes: 19 additions & 0 deletions custom_components/waste_collection_schedule/const.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Constants for the Waste Collection Schedule component."""

from enum import StrEnum
from typing import Final

# Component domain, used to store component data in hass data.
Expand Down Expand Up @@ -53,3 +54,21 @@


CONF_SENSORS: Final = "sensors"


class Icons(StrEnum):
"""Standard icons for sensors."""

ICON_BIOHAZARD = "mdi:biohazard"
ICON_CLEAR_GLASS = "mdi:bottle-wine-outline"
ICON_COLORED_GLASS = "mdi:bottle-wine"
ICON_COMPOST = "mdi:food"
ICON_ELECTRONICS = "mdi:desktop-classic"
ICON_GARDEN_WASTE = "mdi:leaf"
ICON_GENERAL_TRASH = "mdi:trash-can"
ICON_LANDFILL = "mdi:delete-empty"
ICON_METAL = "mdi:nail"
ICON_NEWSPAPER = "mdi:newspaper"
ICON_PAPER_PACKAGING = "mdi:package-variant"
ICON_PLASTIC = "mdi:bottle-soda-classic-outline"
ICON_RECYCLE = "mdi:recycle"
13 changes: 5 additions & 8 deletions custom_components/waste_collection_schedule/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
)

from .const import (
Icons,
CONF_ADD_DAYS_TO,
CONF_COLLECTION_TYPES,
CONF_COUNT,
Expand Down Expand Up @@ -83,15 +84,11 @@ async def async_setup_entry(hass, config: ConfigEntry, async_add_entities):
date_template = sensor.get(CONF_DATE_TEMPLATE)
try:
value_template = cv.template(value_template)
except (
vol.Invalid
): # should only happen if value_template = None, as it is already validated in the config flow if it is not None
except vol.Invalid: # should only happen if value_template = None, as it is already validated in the config flow if it is not None
value_template = None
try:
date_template = cv.template(date_template)
except (
vol.Invalid
): # should only happen if value_template = None, as it is already validated in the config flow if it is not None
except vol.Invalid: # should only happen if value_template = None, as it is already validated in the config flow if it is not None
date_template = None
details_format = sensor.get(CONF_DETAILS_FORMAT)
if isinstance(details_format, str):
Expand Down Expand Up @@ -263,7 +260,7 @@ def _set_state(self, upcoming: list[CollectionGroup]):
"""Set entity state with default format."""
if len(upcoming) == 0:
self._value = None
self._attr_icon = "mdi:trash-can"
self._attr_icon = Icons.ICON_GENERAL_TRASH
self._attr_entity_picture = None
return

Expand All @@ -279,7 +276,7 @@ def _set_state(self, upcoming: list[CollectionGroup]):
f"{self._separator.join(collection.types)} in {collection.daysTo} days"
)

self._attr_icon = collection.icon or "mdi:trash-can"
self._attr_icon = collection.icon or Icons.ICON_GENERAL_TRASH
self._attr_entity_picture = collection.picture

def _render_date(self, collection: Collection):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@

from bs4 import BeautifulSoup
from waste_collection_schedule import Collection # type: ignore[attr-defined]

# Include work around for SSL UNSAFE_LEGACY_RENEGOTIATION_DISABLED error
from waste_collection_schedule.service.SSLError import get_legacy_session
from const import (
Icons,
)

TITLE = "Aberdeenshire Council"
DESCRIPTION = "Source for Aberdeenshire Council, UK."
Expand All @@ -15,8 +19,8 @@
"Test_004": {"uprn": 151170625},
}
ICON_MAP = {
"Mixed recycling and food waste": "mdi:recycle",
"Refuse and food waste": "mdi:trash-can",
"Mixed recycling and food waste": Icons.ICON_RECYCLE,
"Refuse and food waste": Icons.ICON_GENERAL_TRASH,
}

PARAM_DESCRIPTIONS = {
Expand Down
9 changes: 5 additions & 4 deletions doc/contributing_source.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ The script should have the following general structure
```py
import datetime
from waste_collection_schedule import Collection
from const import Icons

TITLE = "My Council" # Title will show up in README.md and info.md
DESCRIPTION = "Source script for abc.com" # Describe your source
Expand All @@ -33,10 +34,10 @@ TEST_CASES = { # Insert arguments for test cases to be used by test_sources.py
}

API_URL = "https://abc.com/search/"
ICON_MAP = { # Optional: Dict of waste types and suitable mdi icons
"DOMESTIC": "mdi:trash-can",
"RECYCLE": "mdi:recycle",
"ORGANIC": "mdi:leaf",
ICON_MAP = { # Optional: Dict of waste types and suitable icons
"DOMESTIC": Icons.ICON_GENERAL_TRASH,
"RECYCLE": Icons.ICON_RECYCLE,
"ORGANIC": Icond.ICON_COMPOST,
}

#### Arguments affecting the configuration GUI ####
Expand Down
Loading