Strict type hints for MQTT integration (#82317)

* Strict type hints for MQTT integration

* Fix errors

* Additional corrections

* Use cv.template to avoid untyped calls

* Enable strict typing policy for MQTT integration

* Use ignore[no-untyped-call]

* Use # type: ignore[unreachable]

* Correct cast

* Refactor getting discovery_payload

* Remove unused type ignore comments
This commit is contained in:
Jan Bouwhuis 2022-11-24 08:25:44 +01:00 committed by GitHub
parent 697b5db3f2
commit 8a8732f0bc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 87 additions and 53 deletions

View file

@ -97,7 +97,7 @@ def valid_subscribe_topic(topic: Any) -> str:
def valid_subscribe_topic_template(value: Any) -> template.Template:
"""Validate either a jinja2 template or a valid MQTT subscription topic."""
tpl = template.Template(value)
tpl = cv.template(value)
if tpl.is_static:
valid_subscribe_topic(value)
@ -115,7 +115,8 @@ def valid_publish_topic(topic: Any) -> str:
def valid_qos_schema(qos: Any) -> int:
"""Validate that QOS value is valid."""
return _VALID_QOS_SCHEMA(qos)
validated_qos: int = _VALID_QOS_SCHEMA(qos)
return validated_qos
_MQTT_WILL_BIRTH_SCHEMA = vol.Schema(
@ -138,9 +139,12 @@ def valid_birth_will(config: ConfigType) -> ConfigType:
def get_mqtt_data(hass: HomeAssistant, ensure_exists: bool = False) -> MqttData:
"""Return typed MqttData from hass.data[DATA_MQTT]."""
mqtt_data: MqttData
if ensure_exists:
return hass.data.setdefault(DATA_MQTT, MqttData())
return hass.data[DATA_MQTT]
mqtt_data = hass.data.setdefault(DATA_MQTT, MqttData())
return mqtt_data
mqtt_data = hass.data[DATA_MQTT]
return mqtt_data
async def async_create_certificate_temp_files(