Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add broadlink climate #91183

Merged
merged 14 commits into from
Nov 14, 2023
1 change: 1 addition & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ omit =
homeassistant/components/braviatv/coordinator.py
homeassistant/components/braviatv/media_player.py
homeassistant/components/braviatv/remote.py
homeassistant/components/broadlink/climate.py
homeassistant/components/broadlink/light.py
homeassistant/components/broadlink/remote.py
homeassistant/components/broadlink/switch.py
Expand Down
4 changes: 2 additions & 2 deletions CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,8 @@ build.json @home-assistant/supervisor
/tests/components/bosch_shc/ @tschamm
/homeassistant/components/braviatv/ @bieniu @Drafteed
/tests/components/braviatv/ @bieniu @Drafteed
/homeassistant/components/broadlink/ @danielhiversen @felipediel @L-I-Am
/tests/components/broadlink/ @danielhiversen @felipediel @L-I-Am
/homeassistant/components/broadlink/ @danielhiversen @felipediel @L-I-Am @eifinger
/tests/components/broadlink/ @danielhiversen @felipediel @L-I-Am @eifinger
/homeassistant/components/brother/ @bieniu
/tests/components/brother/ @bieniu
/homeassistant/components/brottsplatskartan/ @gjohansson-ST
Expand Down
89 changes: 89 additions & 0 deletions homeassistant/components/broadlink/climate.py
eifinger marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
"""Support for Broadlink climate devices."""
from typing import Any

from homeassistant.components.climate import (
ATTR_TEMPERATURE,
ClimateEntity,
ClimateEntityFeature,
HVACAction,
HVACMode,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import PRECISION_HALVES, Platform, UnitOfTemperature
from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers.entity_platform import AddEntitiesCallback

from .const import DOMAIN, DOMAINS_AND_TYPES
from .device import BroadlinkDevice
from .entity import BroadlinkEntity


async def async_setup_entry(
hass: HomeAssistant,
config_entry: ConfigEntry,
async_add_entities: AddEntitiesCallback,
) -> None:
"""Set up the Broadlink climate entities."""
device = hass.data[DOMAIN].devices[config_entry.entry_id]

if device.api.type in DOMAINS_AND_TYPES[Platform.CLIMATE]:
async_add_entities([BroadlinkThermostat(device)])
edenhaus marked this conversation as resolved.
Show resolved Hide resolved


class BroadlinkThermostat(ClimateEntity, BroadlinkEntity):
MartinHjelmare marked this conversation as resolved.
Show resolved Hide resolved
"""Representation of a Broadlink Hysen climate entity."""

_attr_has_entity_name = True
_attr_hvac_modes = [HVACMode.HEAT, HVACMode.OFF, HVACMode.AUTO]
_attr_supported_features = ClimateEntityFeature.TARGET_TEMPERATURE
_attr_target_temperature_step = PRECISION_HALVES
_attr_temperature_unit = UnitOfTemperature.CELSIUS

def __init__(self, device: BroadlinkDevice) -> None:
"""Initialize the climate entity."""
super().__init__(device)
self._attr_unique_id = device.unique_id
self._attr_hvac_action = None

async def async_set_temperature(self, **kwargs: Any) -> None:
"""Set new target temperature."""
temperature = kwargs[ATTR_TEMPERATURE]
await self._device.async_request(self._device.api.set_temp, temperature)
self._attr_target_temperature = temperature
self.async_write_ha_state()

@callback
def _update_state(self, data: dict[str, Any]) -> None:
"""Update data."""
if data.get("power"):
if data.get("auto_mode"):
self._attr_hvac_mode = HVACMode.AUTO
else:
self._attr_hvac_mode = HVACMode.HEAT

if data.get("active"):
self._attr_hvac_action = HVACAction.HEATING
else:
self._attr_hvac_action = HVACAction.IDLE
else:
self._attr_hvac_mode = HVACMode.OFF
self._attr_hvac_action = HVACAction.OFF

self._attr_current_temperature = data.get("room_temp")
self._attr_target_temperature = data.get("thermostat_temp")

async def async_set_hvac_mode(self, hvac_mode: HVACMode) -> None:
"""Set new target hvac mode."""
if hvac_mode == HVACMode.OFF:
await self._device.async_request(self._device.api.set_power, 0)

elif hvac_mode == HVACMode.AUTO:
await self._device.async_request(self._device.api.set_power, 1)
await self._device.async_request(self._device.api.set_mode, 1, 0)

elif hvac_mode == HVACMode.HEAT:
await self._device.async_request(self._device.api.set_power, 1)
await self._device.async_request(self._device.api.set_mode, 0, 0)
edenhaus marked this conversation as resolved.
Show resolved Hide resolved

self._attr_hvac_mode = hvac_mode
self.async_write_ha_state()
1 change: 1 addition & 0 deletions homeassistant/components/broadlink/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
DOMAIN = "broadlink"

DOMAINS_AND_TYPES = {
Platform.CLIMATE: {"HYS"},
Platform.REMOTE: {"RM4MINI", "RM4PRO", "RMMINI", "RMMINIB", "RMPRO"},
Platform.SENSOR: {
"A1",
Expand Down
5 changes: 4 additions & 1 deletion homeassistant/components/broadlink/manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"domain": "broadlink",
"name": "Broadlink",
"codeowners": ["@danielhiversen", "@felipediel", "@L-I-Am"],
"codeowners": ["@danielhiversen", "@felipediel", "@L-I-Am", "@eifinger"],
"config_flow": true,
"dhcp": [
{
Expand Down Expand Up @@ -30,6 +30,9 @@
},
{
"macaddress": "EC0BAE*"
},
{
"macaddress": "780F77*"
}
],
"documentation": "https://www.home-assistant.io/integrations/broadlink",
Expand Down
9 changes: 9 additions & 0 deletions homeassistant/components/broadlink/updater.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ def get_update_manager(device):
update_managers = {
"A1": BroadlinkA1UpdateManager,
"BG1": BroadlinkBG1UpdateManager,
"HYS": BroadlinkThermostatUpdateManager,
"LB1": BroadlinkLB1UpdateManager,
"LB2": BroadlinkLB1UpdateManager,
"MP1": BroadlinkMP1UpdateManager,
Expand Down Expand Up @@ -184,3 +185,11 @@ class BroadlinkLB1UpdateManager(BroadlinkUpdateManager):
async def async_fetch_data(self):
"""Fetch data from the device."""
return await self.device.async_request(self.device.api.get_state)


class BroadlinkThermostatUpdateManager(BroadlinkUpdateManager):
"""Manages updates for thermostats with Broadlink DNA."""

async def async_fetch_data(self):
"""Fetch data from the device."""
return await self.device.async_request(self.device.api.get_full_status)
4 changes: 4 additions & 0 deletions homeassistant/generated/dhcp.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@
"domain": "broadlink",
"macaddress": "EC0BAE*",
},
{
"domain": "broadlink",
"macaddress": "780F77*",
},
{
"domain": "dlink",
"hostname": "dsp-w215",
Expand Down