Rename OpenThermGatewayDevice to OpenThermGatewayHub (#124361)

* Rename OpenThermGatewayDevice to OpenThermGatewayHub
Update references accordingly

* Update tests
This commit is contained in:
mvn23 2024-08-21 16:56:57 +02:00 committed by GitHub
parent 9de90ca7d5
commit ec256166cc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 64 additions and 64 deletions

View File

@ -99,7 +99,7 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> b
if DATA_OPENTHERM_GW not in hass.data:
hass.data[DATA_OPENTHERM_GW] = {DATA_GATEWAYS: {}}
gateway = OpenThermGatewayDevice(hass, config_entry)
gateway = OpenThermGatewayHub(hass, config_entry)
hass.data[DATA_OPENTHERM_GW][DATA_GATEWAYS][config_entry.data[CONF_ID]] = gateway
if config_entry.options.get(CONF_PRECISION):
@ -273,9 +273,9 @@ def register_services(hass: HomeAssistant) -> None:
async def reset_gateway(call: ServiceCall) -> None:
"""Reset the OpenTherm Gateway."""
gw_dev = hass.data[DATA_OPENTHERM_GW][DATA_GATEWAYS][call.data[ATTR_GW_ID]]
gw_hub = hass.data[DATA_OPENTHERM_GW][DATA_GATEWAYS][call.data[ATTR_GW_ID]]
mode_rst = gw_vars.OTGW_MODE_RESET
await gw_dev.gateway.set_mode(mode_rst)
await gw_hub.gateway.set_mode(mode_rst)
hass.services.async_register(
DOMAIN, SERVICE_RESET_GATEWAY, reset_gateway, service_reset_schema
@ -283,8 +283,8 @@ def register_services(hass: HomeAssistant) -> None:
async def set_ch_ovrd(call: ServiceCall) -> None:
"""Set the central heating override on the OpenTherm Gateway."""
gw_dev = hass.data[DATA_OPENTHERM_GW][DATA_GATEWAYS][call.data[ATTR_GW_ID]]
await gw_dev.gateway.set_ch_enable_bit(1 if call.data[ATTR_CH_OVRD] else 0)
gw_hub = hass.data[DATA_OPENTHERM_GW][DATA_GATEWAYS][call.data[ATTR_GW_ID]]
await gw_hub.gateway.set_ch_enable_bit(1 if call.data[ATTR_CH_OVRD] else 0)
hass.services.async_register(
DOMAIN,
@ -295,8 +295,8 @@ def register_services(hass: HomeAssistant) -> None:
async def set_control_setpoint(call: ServiceCall) -> None:
"""Set the control setpoint on the OpenTherm Gateway."""
gw_dev = hass.data[DATA_OPENTHERM_GW][DATA_GATEWAYS][call.data[ATTR_GW_ID]]
await gw_dev.gateway.set_control_setpoint(call.data[ATTR_TEMPERATURE])
gw_hub = hass.data[DATA_OPENTHERM_GW][DATA_GATEWAYS][call.data[ATTR_GW_ID]]
await gw_hub.gateway.set_control_setpoint(call.data[ATTR_TEMPERATURE])
hass.services.async_register(
DOMAIN,
@ -307,8 +307,8 @@ def register_services(hass: HomeAssistant) -> None:
async def set_dhw_ovrd(call: ServiceCall) -> None:
"""Set the domestic hot water override on the OpenTherm Gateway."""
gw_dev = hass.data[DATA_OPENTHERM_GW][DATA_GATEWAYS][call.data[ATTR_GW_ID]]
await gw_dev.gateway.set_hot_water_ovrd(call.data[ATTR_DHW_OVRD])
gw_hub = hass.data[DATA_OPENTHERM_GW][DATA_GATEWAYS][call.data[ATTR_GW_ID]]
await gw_hub.gateway.set_hot_water_ovrd(call.data[ATTR_DHW_OVRD])
hass.services.async_register(
DOMAIN,
@ -319,8 +319,8 @@ def register_services(hass: HomeAssistant) -> None:
async def set_dhw_setpoint(call: ServiceCall) -> None:
"""Set the domestic hot water setpoint on the OpenTherm Gateway."""
gw_dev = hass.data[DATA_OPENTHERM_GW][DATA_GATEWAYS][call.data[ATTR_GW_ID]]
await gw_dev.gateway.set_dhw_setpoint(call.data[ATTR_TEMPERATURE])
gw_hub = hass.data[DATA_OPENTHERM_GW][DATA_GATEWAYS][call.data[ATTR_GW_ID]]
await gw_hub.gateway.set_dhw_setpoint(call.data[ATTR_TEMPERATURE])
hass.services.async_register(
DOMAIN,
@ -331,10 +331,10 @@ def register_services(hass: HomeAssistant) -> None:
async def set_device_clock(call: ServiceCall) -> None:
"""Set the clock on the OpenTherm Gateway."""
gw_dev = hass.data[DATA_OPENTHERM_GW][DATA_GATEWAYS][call.data[ATTR_GW_ID]]
gw_hub = hass.data[DATA_OPENTHERM_GW][DATA_GATEWAYS][call.data[ATTR_GW_ID]]
attr_date = call.data[ATTR_DATE]
attr_time = call.data[ATTR_TIME]
await gw_dev.gateway.set_clock(datetime.combine(attr_date, attr_time))
await gw_hub.gateway.set_clock(datetime.combine(attr_date, attr_time))
hass.services.async_register(
DOMAIN, SERVICE_SET_CLOCK, set_device_clock, service_set_clock_schema
@ -342,10 +342,10 @@ def register_services(hass: HomeAssistant) -> None:
async def set_gpio_mode(call: ServiceCall) -> None:
"""Set the OpenTherm Gateway GPIO modes."""
gw_dev = hass.data[DATA_OPENTHERM_GW][DATA_GATEWAYS][call.data[ATTR_GW_ID]]
gw_hub = hass.data[DATA_OPENTHERM_GW][DATA_GATEWAYS][call.data[ATTR_GW_ID]]
gpio_id = call.data[ATTR_ID]
gpio_mode = call.data[ATTR_MODE]
await gw_dev.gateway.set_gpio_mode(gpio_id, gpio_mode)
await gw_hub.gateway.set_gpio_mode(gpio_id, gpio_mode)
hass.services.async_register(
DOMAIN, SERVICE_SET_GPIO_MODE, set_gpio_mode, service_set_gpio_mode_schema
@ -353,10 +353,10 @@ def register_services(hass: HomeAssistant) -> None:
async def set_led_mode(call: ServiceCall) -> None:
"""Set the OpenTherm Gateway LED modes."""
gw_dev = hass.data[DATA_OPENTHERM_GW][DATA_GATEWAYS][call.data[ATTR_GW_ID]]
gw_hub = hass.data[DATA_OPENTHERM_GW][DATA_GATEWAYS][call.data[ATTR_GW_ID]]
led_id = call.data[ATTR_ID]
led_mode = call.data[ATTR_MODE]
await gw_dev.gateway.set_led_mode(led_id, led_mode)
await gw_hub.gateway.set_led_mode(led_id, led_mode)
hass.services.async_register(
DOMAIN, SERVICE_SET_LED_MODE, set_led_mode, service_set_led_mode_schema
@ -364,12 +364,12 @@ def register_services(hass: HomeAssistant) -> None:
async def set_max_mod(call: ServiceCall) -> None:
"""Set the max modulation level."""
gw_dev = hass.data[DATA_OPENTHERM_GW][DATA_GATEWAYS][call.data[ATTR_GW_ID]]
gw_hub = hass.data[DATA_OPENTHERM_GW][DATA_GATEWAYS][call.data[ATTR_GW_ID]]
level = call.data[ATTR_LEVEL]
if level == -1:
# Backend only clears setting on non-numeric values.
level = "-"
await gw_dev.gateway.set_max_relative_mod(level)
await gw_hub.gateway.set_max_relative_mod(level)
hass.services.async_register(
DOMAIN, SERVICE_SET_MAX_MOD, set_max_mod, service_set_max_mod_schema
@ -377,8 +377,8 @@ def register_services(hass: HomeAssistant) -> None:
async def set_outside_temp(call: ServiceCall) -> None:
"""Provide the outside temperature to the OpenTherm Gateway."""
gw_dev = hass.data[DATA_OPENTHERM_GW][DATA_GATEWAYS][call.data[ATTR_GW_ID]]
await gw_dev.gateway.set_outside_temp(call.data[ATTR_TEMPERATURE])
gw_hub = hass.data[DATA_OPENTHERM_GW][DATA_GATEWAYS][call.data[ATTR_GW_ID]]
await gw_hub.gateway.set_outside_temp(call.data[ATTR_TEMPERATURE])
hass.services.async_register(
DOMAIN, SERVICE_SET_OAT, set_outside_temp, service_set_oat_schema
@ -386,8 +386,8 @@ def register_services(hass: HomeAssistant) -> None:
async def set_setback_temp(call: ServiceCall) -> None:
"""Set the OpenTherm Gateway SetBack temperature."""
gw_dev = hass.data[DATA_OPENTHERM_GW][DATA_GATEWAYS][call.data[ATTR_GW_ID]]
await gw_dev.gateway.set_setback_temp(call.data[ATTR_TEMPERATURE])
gw_hub = hass.data[DATA_OPENTHERM_GW][DATA_GATEWAYS][call.data[ATTR_GW_ID]]
await gw_hub.gateway.set_setback_temp(call.data[ATTR_TEMPERATURE])
hass.services.async_register(
DOMAIN, SERVICE_SET_SB_TEMP, set_setback_temp, service_set_sb_temp_schema
@ -395,10 +395,10 @@ def register_services(hass: HomeAssistant) -> None:
async def send_transparent_cmd(call: ServiceCall) -> None:
"""Send a transparent OpenTherm Gateway command."""
gw_dev = hass.data[DATA_OPENTHERM_GW][DATA_GATEWAYS][call.data[ATTR_GW_ID]]
gw_hub = hass.data[DATA_OPENTHERM_GW][DATA_GATEWAYS][call.data[ATTR_GW_ID]]
transp_cmd = call.data[ATTR_TRANSP_CMD]
transp_arg = call.data[ATTR_TRANSP_ARG]
await gw_dev.gateway.send_transparent_command(transp_cmd, transp_arg)
await gw_hub.gateway.send_transparent_command(transp_cmd, transp_arg)
hass.services.async_register(
DOMAIN,
@ -416,20 +416,20 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
return unload_ok
class OpenThermGatewayDevice:
"""OpenTherm Gateway device class."""
class OpenThermGatewayHub:
"""OpenTherm Gateway hub class."""
def __init__(self, hass: HomeAssistant, config_entry: ConfigEntry) -> None:
"""Initialize the OpenTherm Gateway."""
self.hass = hass
self.device_path = config_entry.data[CONF_DEVICE]
self.gw_id = config_entry.data[CONF_ID]
self.hub_id = config_entry.data[CONF_ID]
self.name = config_entry.data[CONF_NAME]
self.climate_config = config_entry.options
self.config_entry_id = config_entry.entry_id
self.status = gw_vars.DEFAULT_STATUS
self.update_signal = f"{DATA_OPENTHERM_GW}_{self.gw_id}_update"
self.options_update_signal = f"{DATA_OPENTHERM_GW}_{self.gw_id}_options_update"
self.update_signal = f"{DATA_OPENTHERM_GW}_{self.hub_id}_update"
self.options_update_signal = f"{DATA_OPENTHERM_GW}_{self.hub_id}_options_update"
self.gateway = pyotgw.OpenThermGateway()
self.gw_version = None
@ -453,7 +453,7 @@ class OpenThermGatewayDevice:
dev_reg = dr.async_get(self.hass)
gw_dev = dev_reg.async_get_or_create(
config_entry_id=self.config_entry_id,
identifiers={(DOMAIN, self.gw_id)},
identifiers={(DOMAIN, self.hub_id)},
name=self.name,
manufacturer="Schelte Bron",
model="OpenTherm Gateway",

View File

@ -16,7 +16,7 @@ from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers.entity import async_generate_entity_id
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from . import OpenThermGatewayDevice
from . import OpenThermGatewayHub
from .const import DATA_GATEWAYS, DATA_OPENTHERM_GW
from .entity import OpenThermEntity, OpenThermEntityDescription
@ -290,10 +290,10 @@ async def async_setup_entry(
async_add_entities: AddEntitiesCallback,
) -> None:
"""Set up the OpenTherm Gateway binary sensors."""
gw_dev = hass.data[DATA_OPENTHERM_GW][DATA_GATEWAYS][config_entry.data[CONF_ID]]
gw_hub = hass.data[DATA_OPENTHERM_GW][DATA_GATEWAYS][config_entry.data[CONF_ID]]
async_add_entities(
OpenThermBinarySensor(gw_dev, source, description)
OpenThermBinarySensor(gw_hub, source, description)
for sources, description in BINARY_SENSOR_INFO
for source in sources
)
@ -306,17 +306,17 @@ class OpenThermBinarySensor(OpenThermEntity, BinarySensorEntity):
def __init__(
self,
gw_dev: OpenThermGatewayDevice,
gw_hub: OpenThermGatewayHub,
source: str,
description: OpenThermBinarySensorEntityDescription,
) -> None:
"""Initialize the binary sensor."""
self.entity_id = async_generate_entity_id(
ENTITY_ID_FORMAT,
f"{description.key}_{source}_{gw_dev.gw_id}",
hass=gw_dev.hass,
f"{description.key}_{source}_{gw_hub.hub_id}",
hass=gw_hub.hass,
)
super().__init__(gw_dev, source, description)
super().__init__(gw_hub, source, description)
@callback
def receive_report(self, status: dict[str, dict]) -> None:

View File

@ -87,13 +87,13 @@ class OpenThermClimate(ClimateEntity):
_current_operation: HVACAction | None = None
_enable_turn_on_off_backwards_compatibility = False
def __init__(self, gw_dev, options):
def __init__(self, gw_hub, options):
"""Initialize the device."""
self._gateway = gw_dev
self._gateway = gw_hub
self.entity_id = async_generate_entity_id(
ENTITY_ID_FORMAT, gw_dev.gw_id, hass=gw_dev.hass
ENTITY_ID_FORMAT, gw_hub.hub_id, hass=gw_hub.hass
)
self.friendly_name = gw_dev.name
self.friendly_name = gw_hub.name
self._attr_name = self.friendly_name
self.floor_temp = options.get(CONF_FLOOR_TEMP, DEFAULT_FLOOR_TEMP)
self.temp_read_precision = options.get(CONF_READ_PRECISION)
@ -102,13 +102,13 @@ class OpenThermClimate(ClimateEntity):
self._unsub_options = None
self._unsub_updates = None
self._attr_device_info = DeviceInfo(
identifiers={(DOMAIN, gw_dev.gw_id)},
identifiers={(DOMAIN, gw_hub.hub_id)},
manufacturer="Schelte Bron",
model="OpenTherm Gateway",
name=gw_dev.name,
sw_version=gw_dev.gw_version,
name=gw_hub.name,
sw_version=gw_hub.gw_version,
)
self._attr_unique_id = gw_dev.gw_id
self._attr_unique_id = gw_hub.hub_id
@callback
def update_options(self, entry):

View File

@ -9,7 +9,7 @@ from homeassistant.helpers.device_registry import DeviceInfo
from homeassistant.helpers.dispatcher import async_dispatcher_connect
from homeassistant.helpers.entity import Entity, EntityDescription
from . import OpenThermGatewayDevice
from . import OpenThermGatewayHub
from .const import DOMAIN
_LOGGER = logging.getLogger(__name__)
@ -37,27 +37,27 @@ class OpenThermEntity(Entity):
def __init__(
self,
gw_dev: OpenThermGatewayDevice,
gw_hub: OpenThermGatewayHub,
source: str,
description: OpenThermEntityDescription,
) -> None:
"""Initialize the entity."""
self.entity_description = description
self._gateway = gw_dev
self._gateway = gw_hub
self._source = source
friendly_name_format = (
f"{description.friendly_name_format} ({TRANSLATE_SOURCE[source]})"
if TRANSLATE_SOURCE[source] is not None
else description.friendly_name_format
)
self._attr_name = friendly_name_format.format(gw_dev.name)
self._attr_unique_id = f"{gw_dev.gw_id}-{source}-{description.key}"
self._attr_name = friendly_name_format.format(gw_hub.name)
self._attr_unique_id = f"{gw_hub.hub_id}-{source}-{description.key}"
self._attr_device_info = DeviceInfo(
identifiers={(DOMAIN, gw_dev.gw_id)},
identifiers={(DOMAIN, gw_hub.hub_id)},
manufacturer="Schelte Bron",
model="OpenTherm Gateway",
name=gw_dev.name,
sw_version=gw_dev.gw_version,
name=gw_hub.name,
sw_version=gw_hub.gw_version,
)
async def async_added_to_hass(self) -> None:

View File

@ -25,7 +25,7 @@ from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers.entity import async_generate_entity_id
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from . import OpenThermGatewayDevice
from . import OpenThermGatewayHub
from .const import DATA_GATEWAYS, DATA_OPENTHERM_GW
from .entity import OpenThermEntity, OpenThermEntityDescription
@ -624,11 +624,11 @@ async def async_setup_entry(
async_add_entities: AddEntitiesCallback,
) -> None:
"""Set up the OpenTherm Gateway sensors."""
gw_dev = hass.data[DATA_OPENTHERM_GW][DATA_GATEWAYS][config_entry.data[CONF_ID]]
gw_hub = hass.data[DATA_OPENTHERM_GW][DATA_GATEWAYS][config_entry.data[CONF_ID]]
async_add_entities(
OpenThermSensor(
gw_dev,
gw_hub,
source,
description,
)
@ -644,17 +644,17 @@ class OpenThermSensor(OpenThermEntity, SensorEntity):
def __init__(
self,
gw_dev: OpenThermGatewayDevice,
gw_hub: OpenThermGatewayHub,
source: str,
description: OpenThermSensorEntityDescription,
) -> None:
"""Initialize the OpenTherm Gateway sensor."""
self.entity_id = async_generate_entity_id(
ENTITY_ID_FORMAT,
f"{description.key}_{source}_{gw_dev.gw_id}",
hass=gw_dev.hass,
f"{description.key}_{source}_{gw_hub.hub_id}",
hass=gw_hub.hass,
)
super().__init__(gw_dev, source, description)
super().__init__(gw_hub, source, description)
@callback
def receive_report(self, status: dict[str, dict]) -> None:

View File

@ -223,7 +223,7 @@ async def test_options_migration(hass: HomeAssistant) -> None:
with (
patch(
"homeassistant.components.opentherm_gw.OpenThermGatewayDevice.connect_and_subscribe",
"homeassistant.components.opentherm_gw.OpenThermGatewayHub.connect_and_subscribe",
return_value=True,
),
patch(

View File

@ -40,7 +40,7 @@ async def test_device_registry_insert(
with (
patch(
"homeassistant.components.opentherm_gw.OpenThermGatewayDevice.cleanup",
"homeassistant.components.opentherm_gw.OpenThermGatewayHub.cleanup",
return_value=None,
),
patch("pyotgw.OpenThermGateway.connect", return_value=MINIMAL_STATUS),
@ -72,7 +72,7 @@ async def test_device_registry_update(
with (
patch(
"homeassistant.components.opentherm_gw.OpenThermGatewayDevice.cleanup",
"homeassistant.components.opentherm_gw.OpenThermGatewayHub.cleanup",
return_value=None,
),
patch("pyotgw.OpenThermGateway.connect", return_value=MINIMAL_STATUS_UPD),