Skip to content

Commit

Permalink
Add support for MDI icons (home-assistant#3305)
Browse files Browse the repository at this point in the history
  • Loading branch information
frenck authored Apr 1, 2022
1 parent 81ce293 commit b6aa476
Show file tree
Hide file tree
Showing 118 changed files with 118 additions and 20 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/validate/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM alpine
RUN apk add --no-cache imagemagick bash
RUN apk add --no-cache imagemagick bash git optipng
COPY validate.sh /validate.sh
ENTRYPOINT ["/validate.sh"]
46 changes: 35 additions & 11 deletions .github/workflows/validate/validate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,15 @@ function error() {
fi
}

# Clone MDI icons
rm -f -r mdi
git clone --depth=1 https://github.com/Templarian/MaterialDesign mdi

# Find all files in the src folder (should contain only images)
while read image; do
# Read properties from image
properties=($(identify -format "%w %h %m" "${image}"))
if [[ "$?" -ne 0 ]]; then
error "${image}" "Could not read image file"
continue
fi

# Extract properties into variables
filename=$(basename "${image}")
folderpath=$(dirname "${image}")
foldername=$(basename "${folderpath}")
width="${properties[0]}"
height="${properties[1]}"
type="${properties[2]}"

# Underscore folders are special cases. Instead one should symlink between integration domains
[[ "${foldername}" == _* && "${foldername}" != "_placeholder" && "${foldername}" != "_homeassistant" ]] \
Expand All @@ -43,6 +36,37 @@ while read image; do
&& [[ -d "custom_integrations/${foldername}" ]] \
&& error "${folderpath}" "The integration ${foldername} exists in both core and custom integrations. Core wins."

# If icon filename is icon.txt
if [[ "${filename}" == "icon.txt" ]]; then
mdi=$(<${image})
mdi="${mdi##mdi:}"

# Check if the icon exists
[[ -f "mdi/svg/${mdi}.svg" ]] \
|| error "${image}" "The icon 'mdi:${mdi}' does not exist"

# Ensure icon.png and [email protected] are missing
[[ -f "${folderpath}/icon.png" ]] \
&& error "${image}" "icon.png exists while icon.txt was provided"
[[ -f "${folderpath}/[email protected]" ]] \
&& error "${image}" "[email protected] exists while icon.txt was provided"

# Continue to next image
continue
fi

# Read properties from image
properties=($(identify -format "%w %h %m" "${image}"))
if [[ "$?" -ne 0 ]]; then
error "${image}" "Could not read image file"
continue
fi

# Extract properties into variables
width="${properties[0]}"
height="${properties[1]}"
type="${properties[2]}"

# Ensure file is actually a PNG file
[[ "${type}" != "PNG" ]] \
&& error "${image}" "Invalid file type '${type}' for file"
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
build/*
mdi/*

# macOS Finder
.DS_Store
Expand Down
Binary file removed core_integrations/analytics/icon.png
Binary file not shown.
1 change: 1 addition & 0 deletions core_integrations/analytics/icon.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mdi:chart-timeline-variant
Binary file removed core_integrations/analytics/[email protected]
Binary file not shown.
Binary file removed core_integrations/api/icon.png
Binary file not shown.
1 change: 1 addition & 0 deletions core_integrations/api/icon.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mdi:api
Binary file removed core_integrations/api/[email protected]
Binary file not shown.
Binary file removed core_integrations/auth/icon.png
Binary file not shown.
1 change: 1 addition & 0 deletions core_integrations/auth/icon.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mdi:shield-check
Binary file removed core_integrations/auth/[email protected]
Binary file not shown.
Binary file removed core_integrations/automation/icon.png
Binary file not shown.
1 change: 1 addition & 0 deletions core_integrations/automation/icon.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mdi:robot
Binary file removed core_integrations/automation/[email protected]
Binary file not shown.
Binary file removed core_integrations/camera/icon.png
Binary file not shown.
1 change: 1 addition & 0 deletions core_integrations/camera/icon.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mdi:video
Binary file removed core_integrations/camera/[email protected]
Binary file not shown.
Binary file removed core_integrations/config/icon.png
Binary file not shown.
1 change: 1 addition & 0 deletions core_integrations/config/icon.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mdi:cog
Binary file removed core_integrations/config/[email protected]
Binary file not shown.
Binary file removed core_integrations/counter/icon.png
Binary file not shown.
1 change: 1 addition & 0 deletions core_integrations/counter/icon.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mdi:counter
Binary file removed core_integrations/counter/[email protected]
Binary file not shown.
Binary file removed core_integrations/derivative/icon.png
Binary file not shown.
1 change: 1 addition & 0 deletions core_integrations/derivative/icon.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mdi:function-variant
Binary file removed core_integrations/derivative/[email protected]
Binary file not shown.
Binary file removed core_integrations/group/icon.png
Binary file not shown.
1 change: 1 addition & 0 deletions core_integrations/group/icon.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mdi:google-circles-communities
Binary file removed core_integrations/group/[email protected]
Binary file not shown.
Binary file removed core_integrations/http/icon.png
Binary file not shown.
1 change: 1 addition & 0 deletions core_integrations/http/icon.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mdi:protocol
Binary file removed core_integrations/http/[email protected]
Binary file not shown.
1 change: 0 additions & 1 deletion core_integrations/image

This file was deleted.

1 change: 1 addition & 0 deletions core_integrations/image/icon.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mdi:image
Binary file removed core_integrations/input_boolean/icon.png
Binary file not shown.
1 change: 1 addition & 0 deletions core_integrations/input_boolean/icon.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mdi:toggle-switch-outline
Binary file removed core_integrations/input_boolean/[email protected]
Binary file not shown.
1 change: 0 additions & 1 deletion core_integrations/input_button

This file was deleted.

1 change: 1 addition & 0 deletions core_integrations/input_button/icon.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mdi:gesture-tap-button
Binary file removed core_integrations/input_datetime/icon.png
Binary file not shown.
1 change: 1 addition & 0 deletions core_integrations/input_datetime/icon.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mdi:clock
Binary file removed core_integrations/input_datetime/[email protected]
Binary file not shown.
Binary file removed core_integrations/input_number/icon.png
Binary file not shown.
1 change: 1 addition & 0 deletions core_integrations/input_number/icon.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mdi:ray-vertex
Binary file removed core_integrations/input_number/[email protected]
Diff not rendered.
Binary file removed core_integrations/input_select/icon.png
Diff not rendered.
1 change: 1 addition & 0 deletions core_integrations/input_select/icon.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mdi:form-dropdown
Binary file removed core_integrations/input_select/[email protected]
Diff not rendered.
Binary file removed core_integrations/input_text/icon.png
Diff not rendered.
1 change: 1 addition & 0 deletions core_integrations/input_text/icon.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mdi:form-textbox
Binary file removed core_integrations/input_text/[email protected]
Diff not rendered.
Binary file removed core_integrations/integration/icon.png
Diff not rendered.
1 change: 1 addition & 0 deletions core_integrations/integration/icon.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mdi:math-integral
Binary file removed core_integrations/integration/[email protected]
Diff not rendered.
Binary file removed core_integrations/lovelace/icon.png
Diff not rendered.
1 change: 1 addition & 0 deletions core_integrations/lovelace/icon.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mdi:view-dashboard
Binary file removed core_integrations/lovelace/[email protected]
Diff not rendered.
Binary file removed core_integrations/media_player/icon.png
Diff not rendered.
1 change: 1 addition & 0 deletions core_integrations/media_player/icon.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mdi:play-circle
Binary file removed core_integrations/media_player/[email protected]
Diff not rendered.
Binary file removed core_integrations/media_source/icon.png
Diff not rendered.
1 change: 1 addition & 0 deletions core_integrations/media_source/icon.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mdi:folder-multiple-image
Binary file removed core_integrations/media_source/[email protected]
Diff not rendered.
1 change: 0 additions & 1 deletion core_integrations/min_max

This file was deleted.

1 change: 1 addition & 0 deletions core_integrations/min_max/icon.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mdi:plus-minus-variant
1 change: 0 additions & 1 deletion core_integrations/moon

This file was deleted.

1 change: 1 addition & 0 deletions core_integrations/moon/icon.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mdi:moon-waning-crescent
Binary file removed core_integrations/notify/icon.png
Diff not rendered.
1 change: 1 addition & 0 deletions core_integrations/notify/icon.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mdi:message-alert
Binary file removed core_integrations/notify/[email protected]
Diff not rendered.
Binary file removed core_integrations/onboarding/icon.png
Diff not rendered.
1 change: 1 addition & 0 deletions core_integrations/onboarding/icon.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mdi:card-account-details
Binary file removed core_integrations/onboarding/[email protected]
Diff not rendered.
1 change: 0 additions & 1 deletion core_integrations/persistent_notification

This file was deleted.

1 change: 1 addition & 0 deletions core_integrations/persistent_notification/icon.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mdi:bell
Binary file removed core_integrations/person/icon.png
Diff not rendered.
1 change: 1 addition & 0 deletions core_integrations/person/icon.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mdi:account
Binary file removed core_integrations/person/[email protected]
Diff not rendered.
Binary file removed core_integrations/script/icon.png
Diff not rendered.
1 change: 1 addition & 0 deletions core_integrations/script/icon.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mdi:script-text
Binary file removed core_integrations/script/[email protected]
Diff not rendered.
Binary file removed core_integrations/search/icon.png
Diff not rendered.
1 change: 1 addition & 0 deletions core_integrations/search/icon.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mdi:magnify
Binary file removed core_integrations/search/[email protected]
Diff not rendered.
Binary file removed core_integrations/sensor/icon.png
Diff not rendered.
1 change: 1 addition & 0 deletions core_integrations/sensor/icon.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mdi:eye
Binary file removed core_integrations/sensor/[email protected]
Diff not rendered.
1 change: 0 additions & 1 deletion core_integrations/switch_as_x

This file was deleted.

1 change: 1 addition & 0 deletions core_integrations/switch_as_x/icon.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mdi:swap-horizontal
Binary file removed core_integrations/system_log/icon.png
Diff not rendered.
1 change: 1 addition & 0 deletions core_integrations/system_log/icon.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mdi:format-list-bulleted-type
Binary file removed core_integrations/system_log/[email protected]
Diff not rendered.
1 change: 0 additions & 1 deletion core_integrations/threshold

This file was deleted.

1 change: 1 addition & 0 deletions core_integrations/threshold/icon.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mdi:chart-sankey
Binary file removed core_integrations/timer/icon.png
Diff not rendered.
1 change: 1 addition & 0 deletions core_integrations/timer/icon.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mdi:timer
Binary file removed core_integrations/timer/[email protected]
Diff not rendered.
1 change: 0 additions & 1 deletion core_integrations/tod

This file was deleted.

1 change: 1 addition & 0 deletions core_integrations/tod/icon.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mdi:hours-24
Binary file removed core_integrations/tts/icon.png
Diff not rendered.
1 change: 1 addition & 0 deletions core_integrations/tts/icon.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mdi:text-to-speech
Binary file removed core_integrations/tts/[email protected]
Diff not rendered.
Binary file removed core_integrations/utility_meter/icon.png
Diff not rendered.
1 change: 1 addition & 0 deletions core_integrations/utility_meter/icon.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mdi:gauge
Binary file removed core_integrations/utility_meter/[email protected]
Diff not rendered.
Binary file removed core_integrations/webhook/icon.png
Diff not rendered.
1 change: 1 addition & 0 deletions core_integrations/webhook/icon.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mdi:webhook
Binary file removed core_integrations/webhook/[email protected]
Diff not rendered.
Binary file removed core_integrations/webhook/logo.png
Diff not rendered.
Binary file removed core_integrations/webhook/[email protected]
Diff not rendered.
Binary file removed core_integrations/websocket_api/icon.png
Diff not rendered.
1 change: 1 addition & 0 deletions core_integrations/websocket_api/icon.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mdi:api
Binary file removed core_integrations/websocket_api/[email protected]
Diff not rendered.
Binary file removed core_integrations/zone/icon.png
Diff not rendered.
1 change: 1 addition & 0 deletions core_integrations/zone/icon.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mdi:map-marker-radius
Binary file removed core_integrations/zone/[email protected]
Diff not rendered.
41 changes: 41 additions & 0 deletions scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
# Copy folder, without symlinks, but use actual files instead
mkdir -p build/_

# Clone MDI icons
rm -f -r mdi
git clone --depth=1 https://github.com/Templarian/MaterialDesign mdi

# Copy custom integrations
rsync -aL custom_integrations/ build/_
rsync -aL custom_integrations/ build
Expand All @@ -11,6 +15,43 @@ rsync -aL custom_integrations/ build
rsync -aL --exclude '_homeassistant' core_integrations/ build/_
rsync -aL --exclude '_homeassistant' --exclude '_placeholder' core_integrations/ build

# Generate icons based on MDI
find ./build -type f -name "icon.txt" | while read icon; do
dir=$(dirname "${icon}")
mdi=$(<${icon})
mdi="${mdi##mdi:}"
mogrify \
-format png \
-density 6400 \
-background transparent \
-fill "rgb(0,171,248,1.0)" \
-opaque black \
-trim \
-resize 240x240 \
-gravity center \
-extent 256x256 \
-write "${dir}/icon.png" \
"mdi/svg/${mdi}.svg"

mogrify \
-format png \
-density 6400 \
-background transparent \
-fill "rgb(0,171,248,1.0)" \
-opaque black \
-trim \
-resize 480x480 \
-gravity center \
-extent 512x512 \
-write "${dir}/[email protected]" \
"mdi/svg/${mdi}.svg"

optipng -silent "${dir}/icon.png" "${dir}/[email protected]"

rm "${icon}"
echo "Generated mdi:${mdi} for ${icon}"
done

# Use icon as logo in case of a missing logo
find ./build -type f -name "icon.png" | while read icon; do
dir=$(dirname "${icon}")
Expand Down

0 comments on commit b6aa476

Please sign in to comment.