Skip to content

Commit 8ebef4d

Browse files
committed
Deprecate fireplace mode switch instead of removing it
- Keep fireplace mode switch but disable it by default - Add deprecation warning when switch is used - Direct users to use climate preset mode instead - Provides smoother migration path for existing users
1 parent 193d780 commit 8ebef4d

File tree

5 files changed

+115
-0
lines changed

5 files changed

+115
-0
lines changed

homeassistant/components/flexit_bacnet/icons.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,12 @@
6161
"state": {
6262
"off": "mdi:radiator-off"
6363
}
64+
},
65+
"fireplace_mode": {
66+
"default": "mdi:fireplace",
67+
"state": {
68+
"off": "mdi:fireplace-off"
69+
}
6470
}
6571
}
6672
}

homeassistant/components/flexit_bacnet/strings.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,9 @@
128128
},
129129
"electric_heater": {
130130
"name": "Electric heater"
131+
},
132+
"fireplace_mode": {
133+
"name": "Fireplace mode"
131134
}
132135
}
133136
},
@@ -150,5 +153,11 @@
150153
"switch_turn": {
151154
"message": "Failed to turn the switch {state}."
152155
}
156+
},
157+
"issues": {
158+
"deprecated_fireplace_switch": {
159+
"description": "The fireplace mode switch entity `{entity_id}` is deprecated and will be removed in a future version.\n\nFireplace mode has been moved to a climate preset to better match the device interface. Please update your automations to use the climate entity preset instead.\n\n**To migrate:**\n\n1. Open your automation that uses `{entity_id}`\n2. Replace the switch service call with:\n```yaml\nservice: climate.set_preset_mode\ntarget:\n entity_id: {climate_entity_id}\ndata:\n preset_mode: fireplace\n```\n\n3. After migrating your automations, you can safely disable this switch entity.",
160+
"title": "Fireplace mode switch is deprecated"
161+
}
153162
}
154163
}

homeassistant/components/flexit_bacnet/switch.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
from homeassistant.core import HomeAssistant
1717
from homeassistant.exceptions import HomeAssistantError
1818
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
19+
from homeassistant.helpers.issue_registry import IssueSeverity, async_create_issue
20+
from homeassistant.util import slugify
1921

2022
from .const import DOMAIN
2123
from .coordinator import FlexitConfigEntry, FlexitCoordinator
@@ -46,6 +48,14 @@ class FlexitSwitchEntityDescription(SwitchEntityDescription):
4648
turn_on_fn=lambda data: data.activate_cooker_hood(),
4749
turn_off_fn=lambda data: data.deactivate_cooker_hood(),
4850
),
51+
FlexitSwitchEntityDescription(
52+
key="fireplace_mode",
53+
translation_key="fireplace_mode",
54+
entity_registry_enabled_default=False,
55+
is_on_fn=lambda data: data.fireplace_ventilation_status,
56+
turn_on_fn=lambda data: data.trigger_fireplace_mode(),
57+
turn_off_fn=lambda data: data.trigger_fireplace_mode(),
58+
),
4959
)
5060

5161

@@ -92,6 +102,26 @@ def is_on(self) -> bool:
92102

93103
async def async_turn_on(self, **kwargs: Any) -> None:
94104
"""Turn switch on."""
105+
# Create deprecation warning for fireplace mode switch
106+
if self.entity_description.key == "fireplace_mode":
107+
# Derive climate entity ID from switch entity ID
108+
climate_entity_id = self.entity_id.replace("switch.", "climate.").replace(
109+
"_fireplace_mode", ""
110+
)
111+
async_create_issue(
112+
self.hass,
113+
DOMAIN,
114+
f"deprecated_switch_{slugify(self.entity_id)}",
115+
is_fixable=False,
116+
issue_domain=DOMAIN,
117+
severity=IssueSeverity.WARNING,
118+
translation_key="deprecated_fireplace_switch",
119+
translation_placeholders={
120+
"entity_id": self.entity_id,
121+
"climate_entity_id": climate_entity_id,
122+
},
123+
)
124+
95125
try:
96126
await self.entity_description.turn_on_fn(self.coordinator.data)
97127
except (asyncio.exceptions.TimeoutError, ConnectionError, DecodingError) as exc:
@@ -107,6 +137,26 @@ async def async_turn_on(self, **kwargs: Any) -> None:
107137

108138
async def async_turn_off(self, **kwargs: Any) -> None:
109139
"""Turn switch off."""
140+
# Create deprecation warning for fireplace mode switch
141+
if self.entity_description.key == "fireplace_mode":
142+
# Derive climate entity ID from switch entity ID
143+
climate_entity_id = self.entity_id.replace("switch.", "climate.").replace(
144+
"_fireplace_mode", ""
145+
)
146+
async_create_issue(
147+
self.hass,
148+
DOMAIN,
149+
f"deprecated_switch_{slugify(self.entity_id)}",
150+
is_fixable=False,
151+
issue_domain=DOMAIN,
152+
severity=IssueSeverity.WARNING,
153+
translation_key="deprecated_fireplace_switch",
154+
translation_placeholders={
155+
"entity_id": self.entity_id,
156+
"climate_entity_id": climate_entity_id,
157+
},
158+
)
159+
110160
try:
111161
await self.entity_description.turn_off_fn(self.coordinator.data)
112162
except (asyncio.exceptions.TimeoutError, ConnectionError, DecodingError) as exc:

tests/components/flexit_bacnet/snapshots/test_switch.ambr

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,55 @@
9797
'state': 'on',
9898
})
9999
# ---
100+
# name: test_switches[switch.device_name_fireplace_mode-entry]
101+
EntityRegistryEntrySnapshot({
102+
'aliases': set({
103+
}),
104+
'area_id': None,
105+
'capabilities': None,
106+
'config_entry_id': <ANY>,
107+
'config_subentry_id': <ANY>,
108+
'device_class': None,
109+
'device_id': <ANY>,
110+
'disabled_by': None,
111+
'domain': 'switch',
112+
'entity_category': None,
113+
'entity_id': 'switch.device_name_fireplace_mode',
114+
'has_entity_name': True,
115+
'hidden_by': None,
116+
'icon': None,
117+
'id': <ANY>,
118+
'labels': set({
119+
}),
120+
'name': None,
121+
'options': dict({
122+
}),
123+
'original_device_class': <SwitchDeviceClass.SWITCH: 'switch'>,
124+
'original_icon': None,
125+
'original_name': 'Fireplace mode',
126+
'platform': 'flexit_bacnet',
127+
'previous_unique_id': None,
128+
'suggested_object_id': None,
129+
'supported_features': 0,
130+
'translation_key': 'fireplace_mode',
131+
'unique_id': '0000-0001-fireplace_mode',
132+
'unit_of_measurement': None,
133+
})
134+
# ---
135+
# name: test_switches[switch.device_name_fireplace_mode-state]
136+
StateSnapshot({
137+
'attributes': ReadOnlyDict({
138+
'device_class': 'switch',
139+
'friendly_name': 'Device Name Fireplace mode',
140+
}),
141+
'context': <ANY>,
142+
'entity_id': 'switch.device_name_fireplace_mode',
143+
'last_changed': <ANY>,
144+
'last_reported': <ANY>,
145+
'last_updated': <ANY>,
146+
'state': 'on',
147+
})
148+
# ---
100149
# name: test_switches_implementation[switch.device_name_electric_heater-state]
101150
StateSnapshot({
102151
'attributes': ReadOnlyDict({

tests/components/flexit_bacnet/test_switch.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
ENTITY_ID = "switch.device_name_electric_heater"
2424

2525

26+
@pytest.mark.usefixtures("entity_registry_enabled_by_default")
2627
async def test_switches(
2728
hass: HomeAssistant,
2829
snapshot: SnapshotAssertion,

0 commit comments

Comments
 (0)