mirror of
https://github.com/home-assistant/core.git
synced 2025-05-19 05:19:14 +00:00

* Initial commit * Correct settings for config flow * Use scan interval * Store proper data * Remove circular dependency * Remove circular dependency * Integration can be initialized * Fix defaults * Add setup entry * Add setup entry * Dont block forever * Poll during async_setup_entry * Remove not needed async methods * Add debug info * Parse binary data * Parse binary data * Use data to update device * Use data to update device * Add CCM15DeviceState * Use DataCoordinator * Use DataCoordinator * Use DataCoordinator * Use CoordinatorEntity * Use CoordinatorEntity * Call update API * Call update API * Call update API * Call update API * Use dataclass * Use dataclass * Use dataclass * Use dataclass * Use dataclass * Use dataclass * Use dataclass * Use dataclass * Fix bugs * Implement swing * Support swing mode, read only * Add unit test * Swing should work * Set swing mode * Add DeviceInfo * Add error code * Add error code * Add error code * Add error code * Initial commit * Refactor * Remove comment code * Try remove circular ref * Try remove circular ref * Remove circular ref * Fix bug * Fix tests * Fix tests * Increase test coverage * Increase test coverage * Increase test coverrage * Add more unit tests * Increase coverage * Update coordinator.py * Fix ruff * Set unit of temperature * Add bounds check * Fix unit tests * Add test coverage * Use Py-ccm15 * Update tests * Upgrade dependency * Apply PR feedback * Upgrade dependency * Upgrade dependency * Upgrade dependency * Force ruff * Delete not needed consts * Fix mypy * Update homeassistant/components/ccm15/coordinator.py Co-authored-by: Robert Resch <robert@resch.dev> * Apply PR Feedback * Apply PR Feedback * Apply PR Feedback * Apply PR Feedback * Apply PR Feedback * Apply PR Feedback * Fix unit tests * Move climate instance * Revert "Move climate instance" This reverts commit cc5b9916b79e805b77cc0062da67aea61e22e7c5. * Apply PR feedback * Apply PR Feedback * Remove scan internal parameter * Update homeassistant/components/ccm15/coordinator.py Co-authored-by: Robert Resch <robert@resch.dev> * Remove empty keys * Fix tests * Use attr fields * Try refactor * Check for multiple hosts * Check for duplicates * Fix tests * Use PRECISION_WHOLE * Use str(ac_index) * Move {self._ac_host}.{self._ac_index} to construtor * Make it fancy * Update homeassistant/components/ccm15/coordinator.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Move const to class variables * Use actual config host * Move device info to construtor * Update homeassistant/components/ccm15/climate.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Set name to none, dont ask for poll * Undo name change * Dont use coordinator in config flow * Dont use coordinator in config flow * Check already configured * Apply PR comments * Move above * Use device info name * Update tests/components/ccm15/test_coordinator.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update tests/components/ccm15/test_config_flow.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Apply feedback * Remove logger debug calls * Add new test to check for dupplicates * Test error * Use better name for test * Update homeassistant/components/ccm15/config_flow.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update homeassistant/components/ccm15/climate.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update homeassistant/components/ccm15/config_flow.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Use prop data for all getters * Fix tests * Improve tests * Improve tests, v2 * Replace log message by comment * No need to do bounds check * Update config_flow.py * Update test_config_flow.py * Update test_coordinator.py * Update test_coordinator.py * Create test_climate.py * Delete tests/components/ccm15/test_coordinator.py * Update coordinator.py * Update __init__.py * Create test_climate.ambr * Update conftest.py * Update test_climate.py * Create test_init.py * Update .coveragerc * Update __init__.py * We need to check bounds after all * Add more test coverage * Test is not None * Use better naming * fix tests * Add available property * Update homeassistant/components/ccm15/climate.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Use snapshots to simulate netwrok failure or power failure * Remove not needed test * Use walrus --------- Co-authored-by: Robert Resch <robert@resch.dev> Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>
161 lines
5.0 KiB
Python
161 lines
5.0 KiB
Python
"""Climate device for CCM15 coordinator."""
|
|
import logging
|
|
from typing import Any
|
|
|
|
from ccm15 import CCM15DeviceState
|
|
|
|
from homeassistant.components.climate import (
|
|
FAN_AUTO,
|
|
FAN_HIGH,
|
|
FAN_LOW,
|
|
FAN_MEDIUM,
|
|
PRECISION_WHOLE,
|
|
SWING_OFF,
|
|
SWING_ON,
|
|
ClimateEntity,
|
|
ClimateEntityFeature,
|
|
HVACMode,
|
|
)
|
|
from homeassistant.config_entries import ConfigEntry
|
|
from homeassistant.const import ATTR_TEMPERATURE, UnitOfTemperature
|
|
from homeassistant.core import HomeAssistant
|
|
from homeassistant.helpers.device_registry import DeviceInfo
|
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
|
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
|
|
|
from .const import CONST_CMD_FAN_MAP, CONST_CMD_STATE_MAP, DOMAIN
|
|
from .coordinator import CCM15Coordinator
|
|
|
|
_LOGGER = logging.getLogger(__name__)
|
|
|
|
|
|
async def async_setup_entry(
|
|
hass: HomeAssistant,
|
|
config_entry: ConfigEntry,
|
|
async_add_entities: AddEntitiesCallback,
|
|
) -> None:
|
|
"""Set up all climate."""
|
|
coordinator: CCM15Coordinator = hass.data[DOMAIN][config_entry.entry_id]
|
|
|
|
ac_data: CCM15DeviceState = coordinator.data
|
|
entities = [
|
|
CCM15Climate(coordinator.get_host(), ac_index, coordinator)
|
|
for ac_index in ac_data.devices
|
|
]
|
|
async_add_entities(entities)
|
|
|
|
|
|
class CCM15Climate(CoordinatorEntity[CCM15Coordinator], ClimateEntity):
|
|
"""Climate device for CCM15 coordinator."""
|
|
|
|
_attr_temperature_unit = UnitOfTemperature.CELSIUS
|
|
_attr_has_entity_name = True
|
|
_attr_target_temperature_step = PRECISION_WHOLE
|
|
_attr_hvac_modes = [
|
|
HVACMode.OFF,
|
|
HVACMode.HEAT,
|
|
HVACMode.COOL,
|
|
HVACMode.DRY,
|
|
HVACMode.AUTO,
|
|
]
|
|
_attr_fan_modes = [FAN_AUTO, FAN_LOW, FAN_MEDIUM, FAN_HIGH]
|
|
_attr_swing_modes = [SWING_OFF, SWING_ON]
|
|
_attr_supported_features = (
|
|
ClimateEntityFeature.TARGET_TEMPERATURE
|
|
| ClimateEntityFeature.FAN_MODE
|
|
| ClimateEntityFeature.SWING_MODE
|
|
)
|
|
_attr_name = None
|
|
|
|
def __init__(
|
|
self, ac_host: str, ac_index: int, coordinator: CCM15Coordinator
|
|
) -> None:
|
|
"""Create a climate device managed from a coordinator."""
|
|
super().__init__(coordinator)
|
|
self._ac_index: int = ac_index
|
|
self._attr_unique_id = f"{ac_host}.{ac_index}"
|
|
self._attr_device_info = DeviceInfo(
|
|
identifiers={
|
|
# Serial numbers are unique identifiers within a specific domain
|
|
(DOMAIN, f"{ac_host}.{ac_index}"),
|
|
},
|
|
name=f"Midea {ac_index}",
|
|
manufacturer="Midea",
|
|
model="CCM15",
|
|
)
|
|
|
|
@property
|
|
def data(self) -> CCM15DeviceState | None:
|
|
"""Return device data."""
|
|
return self.coordinator.get_ac_data(self._ac_index)
|
|
|
|
@property
|
|
def current_temperature(self) -> int | None:
|
|
"""Return current temperature."""
|
|
if (data := self.data) is not None:
|
|
return data.temperature
|
|
return None
|
|
|
|
@property
|
|
def target_temperature(self) -> int | None:
|
|
"""Return target temperature."""
|
|
if (data := self.data) is not None:
|
|
return data.temperature_setpoint
|
|
return None
|
|
|
|
@property
|
|
def hvac_mode(self) -> HVACMode | None:
|
|
"""Return hvac mode."""
|
|
if (data := self.data) is not None:
|
|
mode = data.ac_mode
|
|
return CONST_CMD_STATE_MAP[mode]
|
|
return None
|
|
|
|
@property
|
|
def fan_mode(self) -> str | None:
|
|
"""Return fan mode."""
|
|
if (data := self.data) is not None:
|
|
mode = data.fan_mode
|
|
return CONST_CMD_FAN_MAP[mode]
|
|
return None
|
|
|
|
@property
|
|
def swing_mode(self) -> str | None:
|
|
"""Return swing mode."""
|
|
if (data := self.data) is not None:
|
|
return SWING_ON if data.is_swing_on else SWING_OFF
|
|
return None
|
|
|
|
@property
|
|
def available(self) -> bool:
|
|
"""Return the avalability of the entity."""
|
|
return self.data is not None
|
|
|
|
@property
|
|
def extra_state_attributes(self) -> dict[str, Any]:
|
|
"""Return the optional state attributes."""
|
|
if (data := self.data) is not None:
|
|
return {"error_code": data.error_code}
|
|
return {}
|
|
|
|
async def async_set_temperature(self, **kwargs: Any) -> None:
|
|
"""Set the target temperature."""
|
|
if (temperature := kwargs.get(ATTR_TEMPERATURE)) is not None:
|
|
await self.coordinator.async_set_temperature(self._ac_index, temperature)
|
|
|
|
async def async_set_hvac_mode(self, hvac_mode: HVACMode) -> None:
|
|
"""Set the hvac mode."""
|
|
await self.coordinator.async_set_hvac_mode(self._ac_index, hvac_mode)
|
|
|
|
async def async_set_fan_mode(self, fan_mode: str) -> None:
|
|
"""Set the fan mode."""
|
|
await self.coordinator.async_set_fan_mode(self._ac_index, fan_mode)
|
|
|
|
async def async_turn_off(self) -> None:
|
|
"""Turn off."""
|
|
await self.async_set_hvac_mode(HVACMode.OFF)
|
|
|
|
async def async_turn_on(self) -> None:
|
|
"""Turn on."""
|
|
await self.async_set_hvac_mode(HVACMode.AUTO)
|