mirror of
https://github.com/home-assistant/core.git
synced 2025-07-22 20:57:21 +00:00
Lyric Code Improvements (#45819)
Co-authored-by: J. Nick Koston <nick@koston.org>
This commit is contained in:
parent
f2286d4811
commit
253ae3f423
@ -85,7 +85,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||||||
client = ConfigEntryLyricClient(session, oauth_session)
|
client = ConfigEntryLyricClient(session, oauth_session)
|
||||||
|
|
||||||
client_id = hass.data[DOMAIN][CONF_CLIENT_ID]
|
client_id = hass.data[DOMAIN][CONF_CLIENT_ID]
|
||||||
lyric: Lyric = Lyric(client, client_id)
|
lyric = Lyric(client, client_id)
|
||||||
|
|
||||||
async def async_update_data() -> Lyric:
|
async def async_update_data() -> Lyric:
|
||||||
"""Fetch data from Lyric."""
|
"""Fetch data from Lyric."""
|
||||||
@ -93,7 +93,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||||||
async with async_timeout.timeout(60):
|
async with async_timeout.timeout(60):
|
||||||
await lyric.get_locations()
|
await lyric.get_locations()
|
||||||
return lyric
|
return lyric
|
||||||
except (*LYRIC_EXCEPTIONS, TimeoutError) as exception:
|
except LYRIC_EXCEPTIONS as exception:
|
||||||
raise UpdateFailed(exception) from exception
|
raise UpdateFailed(exception) from exception
|
||||||
|
|
||||||
coordinator = DataUpdateCoordinator(
|
coordinator = DataUpdateCoordinator(
|
||||||
|
@ -82,7 +82,11 @@ async def async_setup_entry(
|
|||||||
|
|
||||||
for location in coordinator.data.locations:
|
for location in coordinator.data.locations:
|
||||||
for device in location.devices:
|
for device in location.devices:
|
||||||
entities.append(LyricClimate(hass, coordinator, location, device))
|
entities.append(
|
||||||
|
LyricClimate(
|
||||||
|
coordinator, location, device, hass.config.units.temperature_unit
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
async_add_entities(entities, True)
|
async_add_entities(entities, True)
|
||||||
|
|
||||||
@ -100,13 +104,13 @@ class LyricClimate(LyricDeviceEntity, ClimateEntity):
|
|||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
hass: HomeAssistantType,
|
|
||||||
coordinator: DataUpdateCoordinator,
|
coordinator: DataUpdateCoordinator,
|
||||||
location: LyricLocation,
|
location: LyricLocation,
|
||||||
device: LyricDevice,
|
device: LyricDevice,
|
||||||
|
temperature_unit: str,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Initialize Honeywell Lyric climate entity."""
|
"""Initialize Honeywell Lyric climate entity."""
|
||||||
self._temperature_unit = hass.config.units.temperature_unit
|
self._temperature_unit = temperature_unit
|
||||||
|
|
||||||
# Setup supported hvac modes
|
# Setup supported hvac modes
|
||||||
self._hvac_modes = [HVAC_MODE_OFF]
|
self._hvac_modes = [HVAC_MODE_OFF]
|
||||||
@ -161,23 +165,26 @@ class LyricClimate(LyricDeviceEntity, ClimateEntity):
|
|||||||
@property
|
@property
|
||||||
def target_temperature(self) -> Optional[float]:
|
def target_temperature(self) -> Optional[float]:
|
||||||
"""Return the temperature we try to reach."""
|
"""Return the temperature we try to reach."""
|
||||||
device: LyricDevice = self.device
|
device = self.device
|
||||||
if not device.hasDualSetpointStatus:
|
if not device.hasDualSetpointStatus:
|
||||||
return device.changeableValues.heatSetpoint
|
return device.changeableValues.heatSetpoint
|
||||||
|
return None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def target_temperature_low(self) -> Optional[float]:
|
def target_temperature_low(self) -> Optional[float]:
|
||||||
"""Return the upper bound temperature we try to reach."""
|
"""Return the upper bound temperature we try to reach."""
|
||||||
device: LyricDevice = self.device
|
device = self.device
|
||||||
if device.hasDualSetpointStatus:
|
if device.hasDualSetpointStatus:
|
||||||
return device.changeableValues.coolSetpoint
|
return device.changeableValues.coolSetpoint
|
||||||
|
return None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def target_temperature_high(self) -> Optional[float]:
|
def target_temperature_high(self) -> Optional[float]:
|
||||||
"""Return the upper bound temperature we try to reach."""
|
"""Return the upper bound temperature we try to reach."""
|
||||||
device: LyricDevice = self.device
|
device = self.device
|
||||||
if device.hasDualSetpointStatus:
|
if device.hasDualSetpointStatus:
|
||||||
return device.changeableValues.heatSetpoint
|
return device.changeableValues.heatSetpoint
|
||||||
|
return None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def preset_mode(self) -> Optional[str]:
|
def preset_mode(self) -> Optional[str]:
|
||||||
@ -198,7 +205,7 @@ class LyricClimate(LyricDeviceEntity, ClimateEntity):
|
|||||||
@property
|
@property
|
||||||
def min_temp(self) -> float:
|
def min_temp(self) -> float:
|
||||||
"""Identify min_temp in Lyric API or defaults if not available."""
|
"""Identify min_temp in Lyric API or defaults if not available."""
|
||||||
device: LyricDevice = self.device
|
device = self.device
|
||||||
if LYRIC_HVAC_MODE_COOL in device.allowedModes:
|
if LYRIC_HVAC_MODE_COOL in device.allowedModes:
|
||||||
return device.minCoolSetpoint
|
return device.minCoolSetpoint
|
||||||
return device.minHeatSetpoint
|
return device.minHeatSetpoint
|
||||||
@ -206,7 +213,7 @@ class LyricClimate(LyricDeviceEntity, ClimateEntity):
|
|||||||
@property
|
@property
|
||||||
def max_temp(self) -> float:
|
def max_temp(self) -> float:
|
||||||
"""Identify max_temp in Lyric API or defaults if not available."""
|
"""Identify max_temp in Lyric API or defaults if not available."""
|
||||||
device: LyricDevice = self.device
|
device = self.device
|
||||||
if LYRIC_HVAC_MODE_HEAT in device.allowedModes:
|
if LYRIC_HVAC_MODE_HEAT in device.allowedModes:
|
||||||
return device.maxHeatSetpoint
|
return device.maxHeatSetpoint
|
||||||
return device.maxCoolSetpoint
|
return device.maxCoolSetpoint
|
||||||
@ -216,7 +223,7 @@ class LyricClimate(LyricDeviceEntity, ClimateEntity):
|
|||||||
target_temp_low = kwargs.get(ATTR_TARGET_TEMP_LOW)
|
target_temp_low = kwargs.get(ATTR_TARGET_TEMP_LOW)
|
||||||
target_temp_high = kwargs.get(ATTR_TARGET_TEMP_HIGH)
|
target_temp_high = kwargs.get(ATTR_TARGET_TEMP_HIGH)
|
||||||
|
|
||||||
device: LyricDevice = self.device
|
device = self.device
|
||||||
if device.hasDualSetpointStatus:
|
if device.hasDualSetpointStatus:
|
||||||
if target_temp_low is not None and target_temp_high is not None:
|
if target_temp_low is not None and target_temp_high is not None:
|
||||||
temp = (target_temp_low, target_temp_high)
|
temp = (target_temp_low, target_temp_high)
|
||||||
@ -255,16 +262,6 @@ class LyricClimate(LyricDeviceEntity, ClimateEntity):
|
|||||||
_LOGGER.error(exception)
|
_LOGGER.error(exception)
|
||||||
await self.coordinator.async_refresh()
|
await self.coordinator.async_refresh()
|
||||||
|
|
||||||
async def async_set_preset_period(self, period: str) -> None:
|
|
||||||
"""Set preset period (time)."""
|
|
||||||
try:
|
|
||||||
await self._update_thermostat(
|
|
||||||
self.location, self.device, nextPeriodTime=period
|
|
||||||
)
|
|
||||||
except LYRIC_EXCEPTIONS as exception:
|
|
||||||
_LOGGER.error(exception)
|
|
||||||
await self.coordinator.async_refresh()
|
|
||||||
|
|
||||||
async def async_set_hold_time(self, time_period: str) -> None:
|
async def async_set_hold_time(self, time_period: str) -> None:
|
||||||
"""Set the time to hold until."""
|
"""Set the time to hold until."""
|
||||||
_LOGGER.debug("set_hold_time: %s", time_period)
|
_LOGGER.debug("set_hold_time: %s", time_period)
|
||||||
|
@ -34,9 +34,9 @@ async def mock_impl(hass):
|
|||||||
|
|
||||||
async def test_abort_if_no_configuration(hass):
|
async def test_abort_if_no_configuration(hass):
|
||||||
"""Check flow abort when no configuration."""
|
"""Check flow abort when no configuration."""
|
||||||
flow = config_flow.OAuth2FlowHandler()
|
result = await hass.config_entries.flow.async_init(
|
||||||
flow.hass = hass
|
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
||||||
result = await flow.async_step_user()
|
)
|
||||||
assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT
|
assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT
|
||||||
assert result["reason"] == "missing_configuration"
|
assert result["reason"] == "missing_configuration"
|
||||||
|
|
||||||
@ -114,8 +114,14 @@ async def test_full_flow(
|
|||||||
assert len(mock_setup.mock_calls) == 1
|
assert len(mock_setup.mock_calls) == 1
|
||||||
|
|
||||||
|
|
||||||
async def test_abort_if_authorization_timeout(hass, mock_impl):
|
async def test_abort_if_authorization_timeout(
|
||||||
|
hass, mock_impl, current_request_with_host
|
||||||
|
):
|
||||||
"""Check Somfy authorization timeout."""
|
"""Check Somfy authorization timeout."""
|
||||||
|
result = await hass.config_entries.flow.async_init(
|
||||||
|
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
||||||
|
)
|
||||||
|
|
||||||
flow = config_flow.OAuth2FlowHandler()
|
flow = config_flow.OAuth2FlowHandler()
|
||||||
flow.hass = hass
|
flow.hass = hass
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user