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

Rename OpenThermGatewayDevice to OpenThermGatewayHub #124361

Merged
merged 2 commits into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 31 additions & 31 deletions homeassistant/components/opentherm_gw/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
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):
Expand Down Expand Up @@ -273,18 +273,18 @@

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]]

Check warning on line 276 in homeassistant/components/opentherm_gw/__init__.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/opentherm_gw/__init__.py#L276

Added line #L276 was not covered by tests
mode_rst = gw_vars.OTGW_MODE_RESET
await gw_dev.gateway.set_mode(mode_rst)
await gw_hub.gateway.set_mode(mode_rst)

Check warning on line 278 in homeassistant/components/opentherm_gw/__init__.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/opentherm_gw/__init__.py#L278

Added line #L278 was not covered by tests

hass.services.async_register(
DOMAIN, SERVICE_RESET_GATEWAY, reset_gateway, service_reset_schema
)

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)

Check warning on line 287 in homeassistant/components/opentherm_gw/__init__.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/opentherm_gw/__init__.py#L286-L287

Added lines #L286 - L287 were not covered by tests

hass.services.async_register(
DOMAIN,
Expand All @@ -295,8 +295,8 @@

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])

Check warning on line 299 in homeassistant/components/opentherm_gw/__init__.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/opentherm_gw/__init__.py#L298-L299

Added lines #L298 - L299 were not covered by tests

hass.services.async_register(
DOMAIN,
Expand All @@ -307,8 +307,8 @@

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])

Check warning on line 311 in homeassistant/components/opentherm_gw/__init__.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/opentherm_gw/__init__.py#L310-L311

Added lines #L310 - L311 were not covered by tests

hass.services.async_register(
DOMAIN,
Expand All @@ -319,8 +319,8 @@

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])

Check warning on line 323 in homeassistant/components/opentherm_gw/__init__.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/opentherm_gw/__init__.py#L322-L323

Added lines #L322 - L323 were not covered by tests

hass.services.async_register(
DOMAIN,
Expand All @@ -331,74 +331,74 @@

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]]

Check warning on line 334 in homeassistant/components/opentherm_gw/__init__.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/opentherm_gw/__init__.py#L334

Added line #L334 was not covered by tests
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))

Check warning on line 337 in homeassistant/components/opentherm_gw/__init__.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/opentherm_gw/__init__.py#L337

Added line #L337 was not covered by tests

hass.services.async_register(
DOMAIN, SERVICE_SET_CLOCK, set_device_clock, service_set_clock_schema
)

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]]

Check warning on line 345 in homeassistant/components/opentherm_gw/__init__.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/opentherm_gw/__init__.py#L345

Added line #L345 was not covered by tests
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)

Check warning on line 348 in homeassistant/components/opentherm_gw/__init__.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/opentherm_gw/__init__.py#L348

Added line #L348 was not covered by tests

hass.services.async_register(
DOMAIN, SERVICE_SET_GPIO_MODE, set_gpio_mode, service_set_gpio_mode_schema
)

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]]

Check warning on line 356 in homeassistant/components/opentherm_gw/__init__.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/opentherm_gw/__init__.py#L356

Added line #L356 was not covered by tests
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)

Check warning on line 359 in homeassistant/components/opentherm_gw/__init__.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/opentherm_gw/__init__.py#L359

Added line #L359 was not covered by tests

hass.services.async_register(
DOMAIN, SERVICE_SET_LED_MODE, set_led_mode, service_set_led_mode_schema
)

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]]

Check warning on line 367 in homeassistant/components/opentherm_gw/__init__.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/opentherm_gw/__init__.py#L367

Added line #L367 was not covered by tests
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)

Check warning on line 372 in homeassistant/components/opentherm_gw/__init__.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/opentherm_gw/__init__.py#L372

Added line #L372 was not covered by tests

hass.services.async_register(
DOMAIN, SERVICE_SET_MAX_MOD, set_max_mod, service_set_max_mod_schema
)

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])

Check warning on line 381 in homeassistant/components/opentherm_gw/__init__.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/opentherm_gw/__init__.py#L380-L381

Added lines #L380 - L381 were not covered by tests

hass.services.async_register(
DOMAIN, SERVICE_SET_OAT, set_outside_temp, service_set_oat_schema
)

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])

Check warning on line 390 in homeassistant/components/opentherm_gw/__init__.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/opentherm_gw/__init__.py#L389-L390

Added lines #L389 - L390 were not covered by tests

hass.services.async_register(
DOMAIN, SERVICE_SET_SB_TEMP, set_setback_temp, service_set_sb_temp_schema
)

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]]

Check warning on line 398 in homeassistant/components/opentherm_gw/__init__.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/opentherm_gw/__init__.py#L398

Added line #L398 was not covered by tests
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)

Check warning on line 401 in homeassistant/components/opentherm_gw/__init__.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/opentherm_gw/__init__.py#L401

Added line #L401 was not covered by tests

hass.services.async_register(
DOMAIN,
Expand All @@ -416,20 +416,20 @@
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

Expand All @@ -453,7 +453,7 @@
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",
Expand Down
14 changes: 7 additions & 7 deletions homeassistant/components/opentherm_gw/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
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

Expand Down Expand Up @@ -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
)
Expand All @@ -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:
Expand Down
16 changes: 8 additions & 8 deletions homeassistant/components/opentherm_gw/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -102,13 +102,13 @@ def __init__(self, gw_dev, options):
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):
Expand Down
16 changes: 8 additions & 8 deletions homeassistant/components/opentherm_gw/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
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__)
Expand Down Expand Up @@ -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:
Expand Down
14 changes: 7 additions & 7 deletions homeassistant/components/opentherm_gw/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
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

Expand Down Expand Up @@ -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,
)
Expand All @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion tests/components/opentherm_gw/test_config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions tests/components/opentherm_gw/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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),
Expand Down