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 a48e553
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 59 deletions.
39 changes: 6 additions & 33 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,19 @@ 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",
)
return self.settings["hvacMode"] == ECOBEE_AUX_HEAT_ONLY

def turn_aux_heat_on(self) -> None:
async def async_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:
async def async_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", "migrate_aux_heat"]
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"
}
}
}
}
}
}
25 changes: 5 additions & 20 deletions homeassistant/components/ecobee/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,7 @@
from homeassistant.helpers.device_registry import DeviceInfo
from homeassistant.helpers.entity_platform import AddEntitiesCallback

from .const import (
_LOGGER,
DOMAIN,
ECOBEE_AUX_HEAT_ONLY,
ECOBEE_MODEL_TO_NAME,
MANUFACTURER,
)
from .const import _LOGGER, DOMAIN, ECOBEE_AUX_HEAT_ONLY

AUX_HEAT_ONLY_KEY = "aux_heat_only"

Expand All @@ -46,7 +40,7 @@ async def async_setup_entry(
async_add_entities(
EcobeeSwitch(data, index, description)
for index in range(len(data.ecobee.thermostats))
if data.ecobee.get_thermostat(index)["settings"]["hasHeatPump"]
# if data.ecobee.get_thermostat(index)["settings"]["hasHeatPump"]
for description in SWITCH_TYPES
)

Expand All @@ -67,34 +61,25 @@ def __init__(
self.entity_description = description
self._attr_unique_id = f"{self.thermostat['name']}_{description.key}"

model: str | None
try:
model = f"{ECOBEE_MODEL_TO_NAME[self.thermostat['modelNumber']]} Thermostat"
except KeyError:
# Ecobee model is not in our list
model = None

self._attr_device_info = DeviceInfo(
identifiers={(DOMAIN, self.thermostat["identifier"])},
manufacturer=MANUFACTURER,
model=model,
name=self.thermostat["name"],
)

def turn_on(self, **kwargs: Any) -> None:
"""Turn the switch on if heat mode is enabled."""
"""Set the hvacMode to auxHeatOnly."""
_LOGGER.debug("Setting HVAC mode to auxHeatOnly to turn on aux heat")
self._last_hvac_mode_before_aux_heat = self.thermostat["settings"]["hvacMode"]
self.data.ecobee.set_hvac_mode(self.thermostat_index, ECOBEE_AUX_HEAT_ONLY)

def turn_off(self, **kwargs: Any) -> None:
"""Turn the switch off if on."""
"""Set the hvacMode back to the prior setting."""
_LOGGER.debug("Setting HVAC mode to last mode to disable aux heat")
self.data.ecobee.set_hvac_mode(
self.thermostat_index, self._last_hvac_mode_before_aux_heat
)

@property
def is_on(self) -> bool:
"""Return true if Emergency heat is enabled."""
"""Return true if auxHeatOnly mode is active."""
return self.thermostat["settings"]["hvacMode"] == ECOBEE_AUX_HEAT_ONLY
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 a48e553

Please sign in to comment.