Delete obsolete lines and add some missing type hints in OpenTherm Gateway integration (#90530)

pull/90067/head^2
PatrickGlesner 2023-04-14 15:28:26 +02:00 committed by GitHub
parent f52fd13d6d
commit f65e06dc26
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 14 additions and 40 deletions

View File

@ -142,7 +142,7 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
return True
def register_services(hass):
def register_services(hass: HomeAssistant) -> None:
"""Register services for the component."""
service_reset_schema = vol.Schema(
{
@ -260,9 +260,7 @@ def register_services(hass):
"""Reset the OpenTherm Gateway."""
gw_dev = hass.data[DATA_OPENTHERM_GW][DATA_GATEWAYS][call.data[ATTR_GW_ID]]
mode_rst = gw_vars.OTGW_MODE_RESET
status = await gw_dev.gateway.set_mode(mode_rst)
gw_dev.status = status
async_dispatcher_send(hass, gw_dev.update_signal, gw_dev.status)
await gw_dev.gateway.set_mode(mode_rst)
hass.services.async_register(
DOMAIN, SERVICE_RESET_GATEWAY, reset_gateway, service_reset_schema
@ -283,10 +281,7 @@ def register_services(hass):
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]]
gw_var = gw_vars.DATA_CONTROL_SETPOINT
value = await gw_dev.gateway.set_control_setpoint(call.data[ATTR_TEMPERATURE])
gw_dev.status.update({gw_var: value})
async_dispatcher_send(hass, gw_dev.update_signal, gw_dev.status)
await gw_dev.gateway.set_control_setpoint(call.data[ATTR_TEMPERATURE])
hass.services.async_register(
DOMAIN,
@ -298,10 +293,7 @@ def register_services(hass):
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]]
gw_var = gw_vars.OTGW_DHW_OVRD
value = await gw_dev.gateway.set_hot_water_ovrd(call.data[ATTR_DHW_OVRD])
gw_dev.status.update({gw_var: value})
async_dispatcher_send(hass, gw_dev.update_signal, gw_dev.status)
await gw_dev.gateway.set_hot_water_ovrd(call.data[ATTR_DHW_OVRD])
hass.services.async_register(
DOMAIN,
@ -313,10 +305,7 @@ def register_services(hass):
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]]
gw_var = gw_vars.DATA_DHW_SETPOINT
value = await gw_dev.gateway.set_dhw_setpoint(call.data[ATTR_TEMPERATURE])
gw_dev.status.update({gw_var: value})
async_dispatcher_send(hass, gw_dev.update_signal, gw_dev.status)
await gw_dev.gateway.set_dhw_setpoint(call.data[ATTR_TEMPERATURE])
hass.services.async_register(
DOMAIN,
@ -341,10 +330,7 @@ def register_services(hass):
gw_dev = hass.data[DATA_OPENTHERM_GW][DATA_GATEWAYS][call.data[ATTR_GW_ID]]
gpio_id = call.data[ATTR_ID]
gpio_mode = call.data[ATTR_MODE]
mode = await gw_dev.gateway.set_gpio_mode(gpio_id, gpio_mode)
gpio_var = getattr(gw_vars, f"OTGW_GPIO_{gpio_id}")
gw_dev.status.update({gpio_var: mode})
async_dispatcher_send(hass, gw_dev.update_signal, gw_dev.status)
await gw_dev.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
@ -355,10 +341,7 @@ def register_services(hass):
gw_dev = hass.data[DATA_OPENTHERM_GW][DATA_GATEWAYS][call.data[ATTR_GW_ID]]
led_id = call.data[ATTR_ID]
led_mode = call.data[ATTR_MODE]
mode = await gw_dev.gateway.set_led_mode(led_id, led_mode)
led_var = getattr(gw_vars, f"OTGW_LED_{led_id}")
gw_dev.status.update({led_var: mode})
async_dispatcher_send(hass, gw_dev.update_signal, gw_dev.status)
await gw_dev.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
@ -367,14 +350,11 @@ def register_services(hass):
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_var = gw_vars.DATA_SLAVE_MAX_RELATIVE_MOD
level = call.data[ATTR_LEVEL]
if level == -1:
# Backend only clears setting on non-numeric values.
level = "-"
value = await gw_dev.gateway.set_max_relative_mod(level)
gw_dev.status.update({gw_var: value})
async_dispatcher_send(hass, gw_dev.update_signal, gw_dev.status)
await gw_dev.gateway.set_max_relative_mod(level)
hass.services.async_register(
DOMAIN, SERVICE_SET_MAX_MOD, set_max_mod, service_set_max_mod_schema
@ -383,10 +363,7 @@ def register_services(hass):
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]]
gw_var = gw_vars.DATA_OUTSIDE_TEMP
value = await gw_dev.gateway.set_outside_temp(call.data[ATTR_TEMPERATURE])
gw_dev.status.update({gw_var: value})
async_dispatcher_send(hass, gw_dev.update_signal, gw_dev.status)
await gw_dev.gateway.set_outside_temp(call.data[ATTR_TEMPERATURE])
hass.services.async_register(
DOMAIN, SERVICE_SET_OAT, set_outside_temp, service_set_oat_schema
@ -395,10 +372,7 @@ def register_services(hass):
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]]
gw_var = gw_vars.OTGW_SB_TEMP
value = await gw_dev.gateway.set_setback_temp(call.data[ATTR_TEMPERATURE])
gw_dev.status.update({gw_var: value})
async_dispatcher_send(hass, gw_dev.update_signal, gw_dev.status)
await gw_dev.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
@ -416,7 +390,7 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
class OpenThermGatewayDevice:
"""OpenTherm Gateway device class."""
def __init__(self, hass, config_entry):
def __init__(self, hass: HomeAssistant, config_entry: ConfigEntry) -> None:
"""Initialize the OpenTherm Gateway."""
self.hass = hass
self.device_path = config_entry.data[CONF_DEVICE]
@ -424,19 +398,19 @@ class OpenThermGatewayDevice:
self.name = config_entry.data[CONF_NAME]
self.climate_config = config_entry.options
self.config_entry_id = config_entry.entry_id
self.status = {}
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.gateway = pyotgw.OpenThermGateway()
self.gw_version = None
async def cleanup(self, event=None):
async def cleanup(self, event=None) -> None:
"""Reset overrides on the gateway."""
await self.gateway.set_control_setpoint(0)
await self.gateway.set_max_relative_mod("-")
await self.gateway.disconnect()
async def connect_and_subscribe(self):
async def connect_and_subscribe(self) -> None:
"""Connect to serial device and subscribe report handler."""
self.status = await self.gateway.connect(self.device_path)
if not self.status: