Permalink
Cannot retrieve contributors at this time
31 lines (27 sloc)
1007 Bytes
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
core/homeassistant/helpers/icon.py
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
"""Icon helper methods.""" | |
from __future__ import annotations | |
def icon_for_battery_level( | |
battery_level: int | None = None, charging: bool = False | |
) -> str: | |
"""Return a battery icon valid identifier.""" | |
icon = "mdi:battery" | |
if battery_level is None: | |
return f"{icon}-unknown" | |
if charging and battery_level > 10: | |
icon += f"-charging-{int(round(battery_level / 20 - 0.01)) * 20}" | |
elif charging: | |
icon += "-outline" | |
elif battery_level <= 5: | |
icon += "-alert" | |
elif 5 < battery_level < 95: | |
icon += f"-{int(round(battery_level / 10 - 0.01)) * 10}" | |
return icon | |
def icon_for_signal_level(signal_level: int | None = None) -> str: | |
"""Return a signal icon valid identifier.""" | |
if signal_level is None or signal_level == 0: | |
return "mdi:signal-cellular-outline" | |
if signal_level > 70: | |
return "mdi:signal-cellular-3" | |
if signal_level > 30: | |
return "mdi:signal-cellular-2" | |
return "mdi:signal-cellular-1" |