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

Add icon translations to Shelly #110183

Merged
merged 4 commits into from
Feb 11, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions homeassistant/components/shelly/button.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,23 +58,23 @@ class ShellyButtonDescription(
ShellyButtonDescription[ShellyBlockCoordinator](
key="self_test",
name="Self test",
icon="mdi:progress-wrench",
translation_key="self_test",
entity_category=EntityCategory.DIAGNOSTIC,
press_action=lambda coordinator: coordinator.device.trigger_shelly_gas_self_test(),
supported=lambda coordinator: coordinator.device.model in SHELLY_GAS_MODELS,
),
ShellyButtonDescription[ShellyBlockCoordinator](
key="mute",
name="Mute",
icon="mdi:volume-mute",
translation_key="mute",
entity_category=EntityCategory.CONFIG,
press_action=lambda coordinator: coordinator.device.trigger_shelly_gas_mute(),
supported=lambda coordinator: coordinator.device.model in SHELLY_GAS_MODELS,
),
ShellyButtonDescription[ShellyBlockCoordinator](
key="unmute",
name="Unmute",
icon="mdi:volume-high",
translation_key="unmute",
entity_category=EntityCategory.CONFIG,
press_action=lambda coordinator: coordinator.device.trigger_shelly_gas_unmute(),
supported=lambda coordinator: coordinator.device.model in SHELLY_GAS_MODELS,
Expand Down
2 changes: 0 additions & 2 deletions homeassistant/components/shelly/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,6 @@ class BlockSleepingClimate(
"""Representation of a Shelly climate device."""

_attr_hvac_modes = [HVACMode.OFF, HVACMode.HEAT]
_attr_icon = "mdi:thermostat"
_attr_max_temp = SHTRV_01_TEMPERATURE_SETTINGS["max"]
_attr_min_temp = SHTRV_01_TEMPERATURE_SETTINGS["min"]
_attr_supported_features = (
Expand Down Expand Up @@ -439,7 +438,6 @@ def _handle_coordinator_update(self) -> None:
class RpcClimate(ShellyRpcEntity, ClimateEntity):
"""Entity that controls a thermostat on RPC based Shelly devices."""

_attr_icon = "mdi:thermostat"
_attr_max_temp = RPC_THERMOSTAT_SETTINGS["max"]
_attr_min_temp = RPC_THERMOSTAT_SETTINGS["min"]
_attr_supported_features = (
Expand Down
1 change: 0 additions & 1 deletion homeassistant/components/shelly/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,6 @@ class BlockEntityDescription(EntityDescription):
# restrict the type to str.
name: str = ""

icon_fn: Callable[[dict], str] | None = None
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed icon_fn because now we can achieve the same with icon translations.

unit_fn: Callable[[dict], str] | None = None
value: Callable[[Any], Any] = lambda val: val
available: Callable[[Block], bool] | None = None
Expand Down
45 changes: 45 additions & 0 deletions homeassistant/components/shelly/icons.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
"entity": {
"button": {
"mute": {
"default": "mdi:volume-mute"
},
"self_test": {
"default": "mdi:progress-wrench"
},
"unmute": {
"default": "mdi:volume-high"
}
},
"number": {
"valve_position": {
"default": "mdi:pipe-valve"
}
},
"sensor": {
"gas_concentration": {
"default": "mdi:gauge"
},
"lamp_life": {
"default": "mdi:progress-wrench"
},
"operation": {
"default": "mdi:cog-transfer"
},
"tilt": {
"default": "mdi:angle-acute"
},
"valve_status": {
"default": "mdi:valve"
}
},
"switch": {
"valve_switch": {
"default": "mdi:valve-open",
"state": {
"off": "mdi:valve-closed"
bieniu marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
}
}
2 changes: 1 addition & 1 deletion homeassistant/components/shelly/number.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class BlockNumberDescription(BlockEntityDescription, NumberEntityDescription):
NUMBERS: dict[tuple[str, str], BlockNumberDescription] = {
("device", "valvePos"): BlockNumberDescription(
key="device|valvepos",
icon="mdi:pipe-valve",
translation_key="valve_position",
name="Valve position",
native_unit_of_measurement=PERCENTAGE,
available=lambda block: cast(int, block.valveError) != 1,
Expand Down
8 changes: 3 additions & 5 deletions homeassistant/components/shelly/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ class RestSensorDescription(RestEntityDescription, SensorEntityDescription):
key="sensor|concentration",
name="Gas concentration",
native_unit_of_measurement=CONCENTRATION_PARTS_PER_MILLION,
icon="mdi:gauge",
translation_key="gas_concentration",
state_class=SensorStateClass.MEASUREMENT,
),
("sensor", "temp"): BlockSensorDescription(
Expand Down Expand Up @@ -279,14 +279,14 @@ class RestSensorDescription(RestEntityDescription, SensorEntityDescription):
key="sensor|tilt",
name="Tilt",
native_unit_of_measurement=DEGREE,
icon="mdi:angle-acute",
translation_key="tilt",
state_class=SensorStateClass.MEASUREMENT,
),
("relay", "totalWorkTime"): BlockSensorDescription(
key="relay|totalWorkTime",
name="Lamp life",
native_unit_of_measurement=PERCENTAGE,
icon="mdi:progress-wrench",
translation_key="lamp_life",
value=lambda value: 100 - (value / 3600 / SHAIR_MAX_WORK_HOURS),
suggested_display_precision=1,
extra_state_attributes=lambda block: {
Expand All @@ -308,15 +308,13 @@ class RestSensorDescription(RestEntityDescription, SensorEntityDescription):
device_class=SensorDeviceClass.ENUM,
options=["unknown", "warmup", "normal", "fault"],
translation_key="operation",
icon="mdi:cog-transfer",
value=lambda value: value,
extra_state_attributes=lambda block: {"self_test": block.selfTest},
),
("valve", "valve"): BlockSensorDescription(
key="valve|valve",
name="Valve status",
translation_key="valve_status",
icon="mdi:valve",
device_class=SensorDeviceClass.ENUM,
options=[
"checking",
Expand Down
6 changes: 1 addition & 5 deletions homeassistant/components/shelly/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ class BlockValveSwitch(ShellyBlockAttributeEntity, SwitchEntity):
"""

entity_description: BlockSwitchDescription
_attr_translation_key = "valve_switch"

def __init__(
self,
Expand All @@ -173,11 +174,6 @@ def is_on(self) -> bool:

return self.attribute_value in GAS_VALVE_OPEN_STATES

@property
def icon(self) -> str:
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed icon property because now we can achieve the same with icon translations.

"""Return the icon."""
return "mdi:valve-open" if self.is_on else "mdi:valve-closed"

async def async_turn_on(self, **kwargs: Any) -> None:
"""Open valve."""
async_create_issue(
Expand Down
6 changes: 3 additions & 3 deletions tests/components/shelly/test_switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ async def test_block_device_gas_valve(
state = hass.states.get(entity_id)
assert state
assert state.state == STATE_ON # valve is open
assert state.attributes.get(ATTR_ICON) == "mdi:valve-open"
assert state.attributes.get(ATTR_ICON) is None

await hass.services.async_call(
SWITCH_DOMAIN,
Expand All @@ -302,7 +302,7 @@ async def test_block_device_gas_valve(
state = hass.states.get(entity_id)
assert state
assert state.state == STATE_OFF # valve is closed
assert state.attributes.get(ATTR_ICON) == "mdi:valve-closed"
assert state.attributes.get(ATTR_ICON) is None

monkeypatch.setattr(mock_block_device.blocks[GAS_VALVE_BLOCK_ID], "valve", "opened")
mock_block_device.mock_update()
Expand All @@ -311,7 +311,7 @@ async def test_block_device_gas_valve(
state = hass.states.get(entity_id)
assert state
assert state.state == STATE_ON # valve is open
assert state.attributes.get(ATTR_ICON) == "mdi:valve-open"
assert state.attributes.get(ATTR_ICON) is None
bieniu marked this conversation as resolved.
Show resolved Hide resolved


async def test_wall_display_thermostat_mode(
Expand Down