Skip to content

Commit

Permalink
Use icon translations and placeholders
Browse files Browse the repository at this point in the history
  • Loading branch information
theneweinstein committed Feb 3, 2024
1 parent 157e1c4 commit 4c2158a
Show file tree
Hide file tree
Showing 15 changed files with 221 additions and 1,838 deletions.
2 changes: 1 addition & 1 deletion .devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ludeeus/integration_blueprint",
"image": "mcr.microsoft.com/vscode/devcontainers/python:3.11",
"image": "mcr.microsoft.com/vscode/devcontainers/python:3.12",
"postCreateCommand": "scripts/setup",
"forwardPorts": [
8123
Expand Down
4 changes: 1 addition & 3 deletions custom_components/somneo/button.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback

from .const import DISMISS_ICON, DOMAIN, SNOOZE_ICON
from .const import DOMAIN
from .entity import SomneoEntity

_LOGGER = logging.getLogger(__name__)
Expand Down Expand Up @@ -37,7 +37,6 @@ async def async_setup_entry(
class SomneoDismiss(SomneoEntity, ButtonEntity):
"""Dismiss alarm button."""

_attr_icon = DISMISS_ICON
_attr_should_poll = True
_attr_translation_key = "alarm_dismiss"

Expand All @@ -49,7 +48,6 @@ async def async_press(self) -> None:
class SomneoSnooze(SomneoEntity, ButtonEntity):
"""Snooze alarm button."""

_attr_icon = SNOOZE_ICON
_attr_should_poll = True
_attr_translation_key = "alarm_snooze"

Expand Down
11 changes: 0 additions & 11 deletions custom_components/somneo/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
)

DOMAIN: Final = "somneo"
VERSION: Final = "0.3"

DEFAULT_NAME: Final = "Somneo"

Expand All @@ -28,23 +27,13 @@
CUSTOM: Final = "custom"
PW_DELTA: Final = "powerwake_delta"

ALARMS_ICON: Final = "hass:alarm"
DISMISS_ICON: Final = "hass:alarm-off"
PW_ICON: Final = "hass:alarm-plus"
TIME_ICON: Final = "hass:clock-digital"
SNOOZE_ICON: Final = "hass:alarm-snooze"
WORKDAYS_ICON: Final = "hass:calendar-range"
WEEKEND_ICON: Final = "hass:calendar-range"
SUNSET_ICON: Final = "hass:weather-sunset"

ATTR_ALARM: Final = "alarm"
ATTR_CURVE: Final = "curve"
ATTR_LEVEL: Final = "level"
ATTR_DURATION: Final = "duration"
ATTR_SOURCE: Final = "source"
ATTR_CHANNEL: Final = "channel"


SENSORS: Final = {
"temperature": UnitOfTemperature.CELSIUS,
"humidity": PERCENTAGE,
Expand Down
132 changes: 132 additions & 0 deletions custom_components/somneo/icons.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
{
"entity": {
"button": {
"alarm_dismiss": {
"default": "mdi:alarm-off"
},
"alarm_snooze": {
"default": "mdi:alarm-snooze"
}
},
"light": {
"normal_light": {
"default": "mdi:lightbulb"
},
"night_light": {
"default": "mdi:lightbulb-night"
}
},
"number": {
"powerwake_delta": {
"default": "mdi:clock-start"
},
"snooze_time": {
"default": "mdi:alarm-snooze"
},
"sunset_duration": {
"default": "mdi:clock-end"
},
"sunset_level": {
"default": "mdi:brightness-5"
},
"sunset_volume": {
"default": "mdi:volume-high"
}
},
"select": {
"days": {
"default": "mdi:calendar-range"
},
"sunset_sound": {
"default": "mdi:playlist-music"
},
"sunset_curve": {
"default": "mdi:weather-sunset"
}
},
"sensor": {
"alarm_status": {
"default": "mdi:alarm-off",
"state": {
"off": "mdi:alarm-off",
"on": "mdi:alarm",
"snooze": "mdi:alarm-snooze",
"wake-up": "mdi:weather-sunset-up",
"sunset": "mdi:weather-sunset-down"
}
}
},
"switch": {
"alarm": {
"default": "mdi:alarm",
"state": {
"on": "mdi:alarm-check",
"off": "mdi:alarm-off"
},
"state_attributes": {
"hour": {
"default": "mdi:alpha-d"
},
"minute": {
"default": "mdi:alpha-m"
},
"day": {
"default": "mdi:calendar-range"
},
"powerwake": {
"default": "PowerWake",
"state": {
"on": "mdi:alarm-light",
"off": "mdi:alarm-light-off"
}
},
"powerwake_delta": {
"default": "mdi:clock-start"
}
}
},
"powerwake": {
"default": "mdi:alarm",
"state": {
"on": "mdi:alarm-light",
"off": "mdi:alarm-light-off"
},
"state_attributes": {
"powerwake_delta": {
"default": "mdi:clock-start"
}
}
},
"sunset": {
"default": "mdi:weather-sunset",
"state_attributes": {
"duration": {
"default": "mdi:clock-end"
},
"curve": {
"default": "mdi:weather-sunset"
},
"level": {
"default": "mdi:brightness-5"
},
"sound": {
"default": "mdi:playlist-music"
},
"volume": {
"default": "mdi:volume-high"
}
}
}
},
"text":{
"days_str": {
"default": "mdi:calendar-range"
}
},
"time":{
"time": {
"default": "mdi:clock-digital"
}
}
}
}
2 changes: 1 addition & 1 deletion custom_components/somneo/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@
"modelName": "Wake-up Light"
}
],
"version": "2024.2.0"
"version": "2024.2.1"
}
10 changes: 3 additions & 7 deletions custom_components/somneo/number.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers.entity_platform import AddEntitiesCallback

from .const import DOMAIN, PW_ICON, SNOOZE_ICON, SUNSET_ICON
from .const import DOMAIN
from .entity import SomneoEntity

_LOGGER = logging.getLogger(__name__)
Expand Down Expand Up @@ -53,15 +53,15 @@ class SomneoPowerWake(SomneoEntity, NumberEntity):
_attr_has_entity_name = True
_attr_native_min_value = 0
_attr_native_max_value = 59
_attr_icon = PW_ICON
_attr_translation_key = "powerwake_delta"

def __init__(self, coordinator, unique_id, name, dev_info, alarm):
"""Initialize number entities."""
super().__init__(
coordinator, unique_id, name, dev_info, "alarm" + str(alarm) + "_powerwake_delta"
)

self._attr_translation_key = "alarm" + str(alarm) + "_powerwake_delta"
self._attr_translation_placeholders = {"number": str(alarm)}

self._alarm = alarm

Expand All @@ -86,7 +86,6 @@ class SomneoSnooze(SomneoEntity, NumberEntity):
_attr_native_min_value = 1
_attr_native_max_value = 20
_attr_native_step = 1
_attr_icon = SNOOZE_ICON
_attr_has_entity_name = True

@callback
Expand All @@ -108,7 +107,6 @@ class SomneoSunsetDuration(SomneoEntity, NumberEntity):
_attr_native_min_value = 5
_attr_native_max_value = 60
_attr_native_step = 5
_attr_icon = SUNSET_ICON
_attr_has_entity_name = True

@callback
Expand All @@ -130,7 +128,6 @@ class SomneoSunsetLevel(SomneoEntity, NumberEntity):
_attr_native_min_value = 0
_attr_native_max_value = 25
_attr_native_step = 1
_attr_icon = SUNSET_ICON
_attr_has_entity_name = True

@callback
Expand All @@ -152,7 +149,6 @@ class SomneoSunsetVolume(SomneoEntity, NumberEntity):
_attr_native_min_value = 1
_attr_native_max_value = 25
_attr_native_step = 1
_attr_icon = SUNSET_ICON
_attr_has_entity_name = True

@callback
Expand Down
8 changes: 2 additions & 6 deletions custom_components/somneo/select.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,9 @@
CUSTOM,
DOMAIN,
EVERYDAY,
SUNSET_ICON,
TOMORROW,
WEEKEND,
WORKDAYS,
WORKDAYS_ICON,
)
from .entity import SomneoEntity

Expand Down Expand Up @@ -54,17 +52,17 @@ class SomneoDays(SomneoEntity, SelectEntity):
"""Representation of a alarm days."""

_attr_should_poll = True
_attr_icon = WORKDAYS_ICON
_attr_assumed_state = False
_attr_available = True
_attr_options = [WORKDAYS, WEEKEND, TOMORROW, EVERYDAY, CUSTOM]
_attr_current_option = WORKDAYS
_attr_translation_key = "days"

def __init__(self, coordinator, unique_id, name, dev_info, alarm):
"""Initialize number entities."""
super().__init__(coordinator, unique_id, name, dev_info, "alarm" + str(alarm))

self._attr_translation_key = "alarm" + str(alarm) + "_days"
self._attr_translation_placeholders = {"number": str(alarm)}
self._alarm = alarm

@callback
Expand All @@ -84,7 +82,6 @@ class SomneoSunsetSound(SomneoEntity, SelectEntity):
"""Representation of a sunset sound source."""

_attr_should_poll = True
_attr_icon = SUNSET_ICON
_attr_translation_key = "sunset_sound"
_attr_assumed_state = False
_attr_available = True
Expand All @@ -108,7 +105,6 @@ class SomneoSunsetCurve(SomneoEntity, SelectEntity):
"""Representation of a sunset curve."""

_attr_should_poll = True
_attr_icon = SUNSET_ICON
_attr_translation_key = "sunset_curve"
_attr_assumed_state = False
_attr_available = True
Expand Down
14 changes: 0 additions & 14 deletions custom_components/somneo/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,17 +104,3 @@ class SomneoAlarmStatus(SomneoEntity, SensorEntity):
def _handle_coordinator_update(self) -> None:
self._attr_native_value = self.coordinator.data["somneo_status"]
self.async_write_ha_state()

@property
def icon(self):
"""Icon."""
if self._attr_native_value == "off":
return "mdi:alarm-off"
if self._attr_native_value == "on":
return "mdi:alarm"
if self._attr_native_value == "snooze":
return "mdi:alarm-snooze"
if self._attr_native_value == "wake-up":
return "mdi:weather-sunset-up"
if self._attr_native_value == "sunset":
return "mdi:weather-sunset-down"
12 changes: 4 additions & 8 deletions custom_components/somneo/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,12 @@
from homeassistant.helpers.entity_platform import AddEntitiesCallback

from .const import (
ALARMS_ICON,
ATTR_CHANNEL,
ATTR_CURVE,
ATTR_DURATION,
ATTR_LEVEL,
ATTR_SOURCE,
DOMAIN,
PW_ICON,
SUNSET_ICON,
)
from .entity import SomneoEntity

Expand Down Expand Up @@ -86,16 +83,16 @@ async def async_setup_entry(
class SomneoAlarmToggle(SomneoEntity, SwitchEntity):
"""Representation of a alarm switch."""

_attr_icon = ALARMS_ICON
_attr_should_poll = True
_attr_translation_key = "alarm"

def __init__(self, coordinator, unique_id, name, device_info, alarm):
"""Initialize the switches."""
super().__init__(
coordinator, unique_id, name, device_info, "alarm" + str(alarm)
)

self._attr_translation_key = "alarm" + str(alarm)
self._attr_translation_placeholders = {"number": str(alarm)}
self._alarm = alarm

@callback
Expand Down Expand Up @@ -149,16 +146,16 @@ async def add_alarm(self):
class SomneoPowerWakeToggle(SomneoEntity, SwitchEntity):
"""Representation of a Powerwake switch."""

_attr_icon = PW_ICON
_attr_should_poll = True
_attr_translation_key = "powerwake"

def __init__(self, coordinator, unique_id, name, device_info, alarm):
"""Initialize the switches."""
super().__init__(
coordinator, unique_id, name, device_info, "alarm" + str(alarm) + "_PW"
)

self._attr_translation_key = "alarm" + str(alarm) + "_powerwake"
self._attr_translation_placeholders = {"number": str(alarm)}
self._alarm = alarm

@callback
Expand All @@ -183,7 +180,6 @@ async def async_turn_off(self, **kwargs: Any):
class SomneoSunsetToggle(SomneoEntity, SwitchEntity):
"""Representation of a Sunset switch."""

_attr_icon = SUNSET_ICON
_attr_should_poll = True
_attr_translation_key = "sunset"

Expand Down
Loading

0 comments on commit 4c2158a

Please sign in to comment.