Skip to content

Commit

Permalink
Address tests interacting with issue creation
Browse files Browse the repository at this point in the history
  • Loading branch information
bjpetit committed Apr 28, 2024
1 parent e99f04a commit 08b8802
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 37 deletions.
36 changes: 5 additions & 31 deletions homeassistant/components/ecobee/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
UnitOfTemperature,
)
from homeassistant.core import HomeAssistant, ServiceCall
from homeassistant.helpers import entity_platform, issue_registry as ir
from homeassistant.helpers import entity_platform
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.device_registry import DeviceInfo
from homeassistant.helpers.entity_platform import AddEntitiesCallback
Expand All @@ -46,6 +46,7 @@
ECOBEE_MODEL_TO_NAME,
MANUFACTURER,
)
from .repairs import aux_heat_deprecation_issue
from .util import ecobee_date, ecobee_time, is_indefinite_hold

ATTR_COOL_TEMP = "cool_temp"
Expand Down Expand Up @@ -571,47 +572,20 @@ def extra_state_attributes(self) -> dict[str, Any] | None:
@property
def is_aux_heat(self) -> bool:
"""Return true if aux heater."""
ir.async_create_issue(
self.hass,
DOMAIN,
"service_deprecation",
breaks_in_ha_version="2024.10.0",
is_fixable=True,
is_persistent=True,
severity=ir.IssueSeverity.WARNING,
translation_key="service_deprecation",
)
aux_heat_deprecation_issue(self.hass)
return self.settings["hvacMode"] == ECOBEE_AUX_HEAT_ONLY

def turn_aux_heat_on(self) -> None:
"""Turn auxiliary heater on."""
ir.async_create_issue(
self.hass,
DOMAIN,
"service_deprecation",
breaks_in_ha_version="2024.10.0",
is_fixable=True,
is_persistent=True,
severity=ir.IssueSeverity.WARNING,
translation_key="service_deprecation",
)
aux_heat_deprecation_issue(self.hass)
_LOGGER.debug("Setting HVAC mode to auxHeatOnly to turn on aux heat")
self._last_hvac_mode_before_aux_heat = self.hvac_mode
self.data.ecobee.set_hvac_mode(self.thermostat_index, ECOBEE_AUX_HEAT_ONLY)
self.update_without_throttle = True

def turn_aux_heat_off(self) -> None:
"""Turn auxiliary heater off."""
ir.async_create_issue(
self.hass,
DOMAIN,
"service_deprecation",
breaks_in_ha_version="2024.10.0",
is_fixable=True,
is_persistent=True,
severity=ir.IssueSeverity.WARNING,
translation_key="service_deprecation",
)
aux_heat_deprecation_issue(self.hass)
_LOGGER.debug("Setting HVAC mode to last mode to disable aux heat")
self.set_hvac_mode(self._last_hvac_mode_before_aux_heat)
self.update_without_throttle = True
Expand Down
17 changes: 16 additions & 1 deletion homeassistant/components/ecobee/repairs.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,26 @@ def migrate_notify_issue(hass: HomeAssistant) -> None:
)


@callback
def aux_heat_deprecation_issue(hass: HomeAssistant) -> None:
"""Ensure an issue is registered."""
ir.async_create_issue(
hass,
DOMAIN,
"migrate_aux_heat",
breaks_in_ha_version="2024.10.0",
is_fixable=True,
is_persistent=True,
severity=ir.IssueSeverity.WARNING,
translation_key="migrate_aux_heat",
)


async def async_create_fix_flow(
hass: HomeAssistant,
issue_id: str,
data: dict[str, str | int | float | None] | None,
) -> RepairsFlow:
"""Create flow."""
assert issue_id == "migrate_notify"
assert issue_id in ["migrate_notify", "service_deprecation"]
return ConfirmRepairFlow()
11 changes: 11 additions & 0 deletions homeassistant/components/ecobee/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,17 @@
}
}
}
},
"migrate_aux_heat": {
"title": "Migration of Ecobee aux_heat service",
"fix_flow": {
"step": {
"confirm": {
"description": "The Ecobee `aux_heat` service has been migrated. A new aux_heat_only switch entity per Thermostat is available for thermostats that support auxHeat.\n\nUpdate any automations and dashboards to use the new aux_heat_only switch. When this is done, fix this issue and restart Home Assistant.",
"title": "Disable legacy Ecobee aux_heat service"
}
}
}
}
}
}
2 changes: 1 addition & 1 deletion tests/components/ecobee/test_notify.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,4 @@ async def test_legacy_notify_service(
await hass.async_block_till_done()
mock_ecobee.send_message.assert_called_with(THERMOSTAT_ID, "It is too cold!")
mock_ecobee.send_message.reset_mock()
assert len(issue_registry.issues) == 1
assert len(issue_registry.issues) >= 1
5 changes: 3 additions & 2 deletions tests/components/ecobee/test_repairs.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ async def test_ecobee_repair_flow(
domain=DOMAIN,
issue_id="migrate_notify",
)
assert len(issue_registry.issues) == 1
issue_count = len(issue_registry.issues)
assert issue_count >= 1

url = RepairsFlowIndexView.url
resp = await http_client.post(
Expand All @@ -76,4 +77,4 @@ async def test_ecobee_repair_flow(
domain=DOMAIN,
issue_id="migrate_notify",
)
assert len(issue_registry.issues) == 0
assert len(issue_registry.issues) == (issue_count - 1)
19 changes: 17 additions & 2 deletions tests/components/ecobee/test_switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,30 @@

from unittest.mock import patch

from homeassistant.components.switch import DOMAIN as SWITCH_DOMAIN
from homeassistant.const import ATTR_ENTITY_ID, SERVICE_TURN_OFF, SERVICE_TURN_ON
from homeassistant.components.switch import DOMAIN as SWITCH_DOMAIN, SwitchDeviceClass
from homeassistant.const import (
ATTR_DEVICE_CLASS,
ATTR_ENTITY_ID,
SERVICE_TURN_OFF,
SERVICE_TURN_ON,
STATE_OFF,
)
from homeassistant.core import HomeAssistant

from .common import setup_platform

DEVICE_ID = "switch.ecobee2_aux_heat_only"


async def test_attributes(hass: HomeAssistant) -> None:
"""Test the switch attributes are correct."""
await setup_platform(hass, SWITCH_DOMAIN)

state = hass.states.get(DEVICE_ID)
assert state.state == STATE_OFF
assert state.attributes[ATTR_DEVICE_CLASS] == SwitchDeviceClass.SWITCH


async def test_turn_on(hass: HomeAssistant) -> None:
"""Test the switch can be turned on."""
with patch("pyecobee.Ecobee.set_hvac_mode") as mock_turn_on:
Expand Down

0 comments on commit 08b8802

Please sign in to comment.