1 """The Nibe Heat Pump integration."""
3 from __future__
import annotations
5 from nibe.connection
import Connection
6 from nibe.connection.modbus
import Modbus
7 from nibe.connection.nibegw
import NibeGW, ProductInfo
8 from nibe.heatpump
import HeatPump, Model
14 EVENT_HOMEASSISTANT_STOP,
23 CONF_CONNECTION_TYPE_MODBUS,
24 CONF_CONNECTION_TYPE_NIBEGW,
28 CONF_REMOTE_READ_PORT,
29 CONF_REMOTE_WRITE_PORT,
33 from .coordinator
import CoilCoordinator
35 PLATFORMS: list[Platform] = [
36 Platform.BINARY_SENSOR,
43 Platform.WATER_HEATER,
49 """Set up Nibe Heat Pump from a config entry."""
51 heatpump = HeatPump(Model[entry.data[CONF_MODEL]])
52 heatpump.word_swap = entry.data.get(CONF_WORD_SWAP,
True)
53 await heatpump.initialize()
55 connection: Connection
56 connection_type = entry.data[CONF_CONNECTION_TYPE]
58 if connection_type == CONF_CONNECTION_TYPE_NIBEGW:
61 entry.data[CONF_IP_ADDRESS],
62 entry.data[CONF_REMOTE_READ_PORT],
63 entry.data[CONF_REMOTE_WRITE_PORT],
64 listening_port=entry.data[CONF_LISTENING_PORT],
66 elif connection_type == CONF_CONNECTION_TYPE_MODBUS:
68 heatpump, entry.data[CONF_MODBUS_URL], entry.data[CONF_MODBUS_UNIT]
73 await connection.start()
78 await connection.stop()
80 entry.async_on_unload(
81 hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, _async_stop)
86 data = hass.data.setdefault(DOMAIN, {})
87 data[entry.entry_id] = coordinator
89 reg = dr.async_get(hass)
90 device_entry = reg.async_get_or_create(
91 config_entry_id=entry.entry_id,
92 identifiers={(DOMAIN, entry.unique_id
or entry.entry_id)},
93 manufacturer=
"NIBE Energy Systems",
94 name=heatpump.model.name,
97 def _on_product_info(product_info: ProductInfo):
98 reg.async_update_device(
99 device_id=device_entry.id,
100 model=product_info.model,
101 sw_version=
str(product_info.firmware_version),
104 if hasattr(connection,
"PRODUCT_INFO_EVENT")
and hasattr(connection,
"subscribe"):
105 connection.subscribe(connection.PRODUCT_INFO_EVENT, _on_product_info)
107 reg.async_update_device(device_id=device_entry.id, model=heatpump.model.name)
109 await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
112 hass.async_create_task(coordinator.async_refresh())
117 """Unload a config entry."""
118 if unload_ok := await hass.config_entries.async_unload_platforms(entry, PLATFORMS):
119 hass.data[DOMAIN].pop(entry.entry_id)
None _async_stop(HomeAssistant hass, bool restart)
bool async_setup_entry(HomeAssistant hass, ConfigEntry entry)
bool async_unload_entry(HomeAssistant hass, ConfigEntry entry)