Rename mqtt mixins module to entity.py (#126279)

This commit is contained in:
Jan Bouwhuis 2024-09-19 20:50:33 +02:00 committed by GitHub
parent b18b532b40
commit 21affac571
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
36 changed files with 43 additions and 43 deletions

View File

@ -39,7 +39,7 @@ from .const import (
CONF_SUPPORTED_FEATURES,
PAYLOAD_NONE,
)
from .mixins import MqttEntity, async_setup_entity_entry_helper
from .entity import MqttEntity, async_setup_entity_entry_helper
from .models import MqttCommandTemplate, MqttValueTemplate, ReceiveMessage
from .schemas import MQTT_ENTITY_COMMON_SCHEMA
from .util import valid_publish_topic, valid_subscribe_topic

View File

@ -37,7 +37,7 @@ from homeassistant.util import dt as dt_util
from . import subscription
from .config import MQTT_RO_SCHEMA
from .const import CONF_STATE_TOPIC, PAYLOAD_NONE
from .mixins import MqttAvailabilityMixin, MqttEntity, async_setup_entity_entry_helper
from .entity import MqttAvailabilityMixin, MqttEntity, async_setup_entity_entry_helper
from .models import MqttValueTemplate, ReceiveMessage
from .schemas import MQTT_ENTITY_COMMON_SCHEMA

View File

@ -15,7 +15,7 @@ from homeassistant.helpers.typing import ConfigType
from .config import DEFAULT_RETAIN, MQTT_BASE_SCHEMA
from .const import CONF_COMMAND_TEMPLATE, CONF_COMMAND_TOPIC, CONF_RETAIN
from .mixins import MqttEntity, async_setup_entity_entry_helper
from .entity import MqttEntity, async_setup_entity_entry_helper
from .models import MqttCommandTemplate
from .schemas import MQTT_ENTITY_COMMON_SCHEMA
from .util import valid_publish_topic

View File

@ -20,7 +20,7 @@ from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
from . import subscription
from .config import MQTT_BASE_SCHEMA
from .const import CONF_TOPIC
from .mixins import MqttEntity, async_setup_entity_entry_helper
from .entity import MqttEntity, async_setup_entity_entry_helper
from .models import ReceiveMessage
from .schemas import MQTT_ENTITY_COMMON_SCHEMA
from .util import valid_subscribe_topic

View File

@ -79,7 +79,7 @@ from .const import (
DEFAULT_OPTIMISTIC,
PAYLOAD_NONE,
)
from .mixins import MqttEntity, async_setup_entity_entry_helper
from .entity import MqttEntity, async_setup_entity_entry_helper
from .models import (
MqttCommandTemplate,
MqttValueTemplate,

View File

@ -61,7 +61,7 @@ from .const import (
DEFAULT_RETAIN,
PAYLOAD_NONE,
)
from .mixins import MqttEntity, async_setup_entity_entry_helper
from .entity import MqttEntity, async_setup_entity_entry_helper
from .models import MqttCommandTemplate, MqttValueTemplate, ReceiveMessage
from .schemas import MQTT_ENTITY_COMMON_SCHEMA
from .util import valid_publish_topic, valid_subscribe_topic

View File

@ -12,7 +12,7 @@ from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
from . import device_trigger
from .config import MQTT_BASE_SCHEMA
from .mixins import async_setup_non_entity_entry_helper
from .entity import async_setup_non_entity_entry_helper
AUTOMATION_TYPE_TRIGGER = "trigger"
AUTOMATION_TYPES = [AUTOMATION_TYPE_TRIGGER]

View File

@ -33,7 +33,7 @@ from homeassistant.helpers.typing import ConfigType, VolSchemaType
from . import subscription
from .config import MQTT_BASE_SCHEMA
from .const import CONF_PAYLOAD_RESET, CONF_STATE_TOPIC
from .mixins import CONF_JSON_ATTRS_TOPIC, MqttEntity, async_setup_entity_entry_helper
from .entity import CONF_JSON_ATTRS_TOPIC, MqttEntity, async_setup_entity_entry_helper
from .models import MqttValueTemplate, ReceiveMessage
from .schemas import MQTT_ENTITY_COMMON_SCHEMA
from .util import valid_subscribe_topic

View File

@ -36,7 +36,7 @@ from .const import (
DOMAIN,
)
from .discovery import MQTTDiscoveryPayload, clear_discovery_hash
from .mixins import MqttDiscoveryDeviceUpdateMixin, send_discovery_done, update_device
from .entity import MqttDiscoveryDeviceUpdateMixin, send_discovery_done, update_device
from .models import DATA_MQTT
from .schemas import MQTT_ENTITY_DEVICE_INFO_SCHEMA

View File

@ -1,4 +1,4 @@
"""MQTT component mixins and helpers."""
"""MQTT (entity) component mixins and helpers."""
from __future__ import annotations
@ -369,7 +369,7 @@ def init_entity_id_from_config(
)
class MqttAttributesMixin(Entity): # pylint: disable=hass-enforce-class-module
class MqttAttributesMixin(Entity):
"""Mixin used for platforms that support JSON attributes."""
_attributes_extra_blocked: frozenset[str] = frozenset()
@ -454,7 +454,7 @@ class MqttAttributesMixin(Entity): # pylint: disable=hass-enforce-class-module
_LOGGER.warning("JSON result was not a dictionary")
class MqttAvailabilityMixin(Entity): # pylint: disable=hass-enforce-class-module
class MqttAvailabilityMixin(Entity):
"""Mixin used for platforms that report availability."""
def __init__(self, config: ConfigType) -> None:
@ -799,7 +799,7 @@ class MqttDiscoveryDeviceUpdateMixin(ABC):
"""Handle the cleanup of platform specific parts, extend to the platform."""
class MqttDiscoveryUpdateMixin(Entity): # pylint: disable=hass-enforce-class-module
class MqttDiscoveryUpdateMixin(Entity):
"""Mixin used to handle updated discovery message for entity based platforms."""
def __init__(
@ -1021,7 +1021,7 @@ def device_info_from_specifications(
return info
class MqttEntityDeviceInfo(Entity): # pylint: disable=hass-enforce-class-module
class MqttEntityDeviceInfo(Entity):
"""Mixin used for mqtt platforms that support the device registry."""
def __init__(

View File

@ -26,7 +26,7 @@ from homeassistant.util.json import JSON_DECODE_EXCEPTIONS, json_loads_object
from . import subscription
from .config import MQTT_RO_SCHEMA
from .const import CONF_STATE_TOPIC, PAYLOAD_EMPTY_JSON, PAYLOAD_NONE
from .mixins import MqttEntity, async_setup_entity_entry_helper
from .entity import MqttEntity, async_setup_entity_entry_helper
from .models import (
DATA_MQTT,
MqttValueTemplate,

View File

@ -47,7 +47,7 @@ from .const import (
CONF_STATE_VALUE_TEMPLATE,
PAYLOAD_NONE,
)
from .mixins import MqttEntity, async_setup_entity_entry_helper
from .entity import MqttEntity, async_setup_entity_entry_helper
from .models import (
MqttCommandTemplate,
MqttValueTemplate,

View File

@ -49,7 +49,7 @@ from .const import (
CONF_STATE_VALUE_TEMPLATE,
PAYLOAD_NONE,
)
from .mixins import MqttEntity, async_setup_entity_entry_helper
from .entity import MqttEntity, async_setup_entity_entry_helper
from .models import (
MqttCommandTemplate,
MqttValueTemplate,

View File

@ -25,7 +25,7 @@ from homeassistant.util import dt as dt_util
from . import subscription
from .config import MQTT_BASE_SCHEMA
from .mixins import MqttEntity, async_setup_entity_entry_helper
from .entity import MqttEntity, async_setup_entity_entry_helper
from .models import (
DATA_MQTT,
MqttValueTemplate,

View File

@ -26,7 +26,7 @@ from homeassistant.helpers.typing import ConfigType, VolSchemaType
from . import subscription
from .config import MQTT_BASE_SCHEMA
from .const import CONF_RETAIN, DEFAULT_OPTIMISTIC, DEFAULT_RETAIN
from .mixins import MqttEntity, async_setup_entity_entry_helper
from .entity import MqttEntity, async_setup_entity_entry_helper
from .models import (
MqttCommandTemplate,
MqttValueTemplate,

View File

@ -12,7 +12,7 @@ from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import ConfigType, VolSchemaType
from ..mixins import async_setup_entity_entry_helper
from ..entity import async_setup_entity_entry_helper
from .schema import CONF_SCHEMA, MQTT_LIGHT_SCHEMA_SCHEMA
from .schema_basic import (
DISCOVERY_SCHEMA_BASIC,

View File

@ -51,7 +51,7 @@ from ..const import (
CONF_STATE_VALUE_TEMPLATE,
PAYLOAD_NONE,
)
from ..mixins import MqttEntity
from ..entity import MqttEntity
from ..models import (
MqttCommandTemplate,
MqttValueTemplate,

View File

@ -65,7 +65,7 @@ from ..const import (
CONF_STATE_TOPIC,
DOMAIN as MQTT_DOMAIN,
)
from ..mixins import MqttEntity
from ..entity import MqttEntity
from ..models import ReceiveMessage
from ..schemas import MQTT_ENTITY_COMMON_SCHEMA
from ..util import valid_subscribe_topic

View File

@ -38,7 +38,7 @@ import homeassistant.util.color as color_util
from .. import subscription
from ..config import MQTT_RW_SCHEMA
from ..const import CONF_COMMAND_TOPIC, CONF_STATE_TOPIC, PAYLOAD_NONE
from ..mixins import MqttEntity
from ..entity import MqttEntity
from ..models import (
MqttCommandTemplate,
MqttValueTemplate,

View File

@ -34,7 +34,7 @@ from .const import (
CONF_STATE_OPENING,
CONF_STATE_TOPIC,
)
from .mixins import MqttEntity, async_setup_entity_entry_helper
from .entity import MqttEntity, async_setup_entity_entry_helper
from .models import (
MqttCommandTemplate,
MqttValueTemplate,

View File

@ -15,7 +15,7 @@ from homeassistant.helpers.typing import ConfigType
from .config import DEFAULT_RETAIN, MQTT_BASE_SCHEMA
from .const import CONF_COMMAND_TEMPLATE, CONF_COMMAND_TOPIC, CONF_RETAIN
from .mixins import MqttEntity, async_setup_entity_entry_helper
from .entity import MqttEntity, async_setup_entity_entry_helper
from .models import MqttCommandTemplate
from .schemas import MQTT_ENTITY_COMMON_SCHEMA
from .util import valid_publish_topic

View File

@ -39,7 +39,7 @@ from .const import (
CONF_PAYLOAD_RESET,
CONF_STATE_TOPIC,
)
from .mixins import MqttEntity, async_setup_entity_entry_helper
from .entity import MqttEntity, async_setup_entity_entry_helper
from .models import (
MqttCommandTemplate,
MqttValueTemplate,

View File

@ -17,7 +17,7 @@ from homeassistant.helpers.typing import ConfigType
from .config import MQTT_BASE_SCHEMA
from .const import CONF_COMMAND_TOPIC, CONF_RETAIN
from .mixins import MqttEntity, async_setup_entity_entry_helper
from .entity import MqttEntity, async_setup_entity_entry_helper
from .schemas import MQTT_ENTITY_COMMON_SCHEMA
from .util import valid_publish_topic

View File

@ -26,7 +26,7 @@ from .const import (
CONF_OPTIONS,
CONF_STATE_TOPIC,
)
from .mixins import MqttEntity, async_setup_entity_entry_helper
from .entity import MqttEntity, async_setup_entity_entry_helper
from .models import (
MqttCommandTemplate,
MqttValueTemplate,

View File

@ -40,7 +40,7 @@ from homeassistant.util import dt as dt_util
from . import subscription
from .config import MQTT_RO_SCHEMA
from .const import CONF_OPTIONS, CONF_STATE_TOPIC, PAYLOAD_NONE
from .mixins import MqttAvailabilityMixin, MqttEntity, async_setup_entity_entry_helper
from .entity import MqttAvailabilityMixin, MqttEntity, async_setup_entity_entry_helper
from .models import MqttValueTemplate, PayloadSentinel, ReceiveMessage
from .schemas import MQTT_ENTITY_COMMON_SCHEMA
from .util import check_state_too_long

View File

@ -46,7 +46,7 @@ from .const import (
PAYLOAD_EMPTY_JSON,
PAYLOAD_NONE,
)
from .mixins import MqttEntity, async_setup_entity_entry_helper
from .entity import MqttEntity, async_setup_entity_entry_helper
from .models import (
MqttCommandTemplate,
MqttValueTemplate,

View File

@ -34,7 +34,7 @@ from .const import (
CONF_STATE_TOPIC,
PAYLOAD_NONE,
)
from .mixins import MqttEntity, async_setup_entity_entry_helper
from .entity import MqttEntity, async_setup_entity_entry_helper
from .models import (
MqttCommandTemplate,
MqttValueTemplate,

View File

@ -20,7 +20,7 @@ from . import subscription
from .config import MQTT_BASE_SCHEMA
from .const import ATTR_DISCOVERY_HASH, CONF_QOS, CONF_TOPIC
from .discovery import MQTTDiscoveryPayload
from .mixins import (
from .entity import (
MqttDiscoveryDeviceUpdateMixin,
async_handle_schema_error,
async_setup_non_entity_entry_helper,

View File

@ -28,7 +28,7 @@ from homeassistant.helpers.typing import ConfigType, VolSchemaType
from . import subscription
from .config import MQTT_RW_SCHEMA
from .const import CONF_COMMAND_TEMPLATE, CONF_COMMAND_TOPIC, CONF_STATE_TOPIC
from .mixins import MqttEntity, async_setup_entity_entry_helper
from .entity import MqttEntity, async_setup_entity_entry_helper
from .models import (
MqttCommandTemplate,
MqttValueTemplate,

View File

@ -25,7 +25,7 @@ from homeassistant.util.json import JSON_DECODE_EXCEPTIONS, json_loads
from . import subscription
from .config import DEFAULT_RETAIN, MQTT_RO_SCHEMA
from .const import CONF_COMMAND_TOPIC, CONF_RETAIN, CONF_STATE_TOPIC, PAYLOAD_EMPTY_JSON
from .mixins import MqttEntity, async_setup_entity_entry_helper
from .entity import MqttEntity, async_setup_entity_entry_helper
from .models import MqttValueTemplate, ReceiveMessage
from .schemas import MQTT_ENTITY_COMMON_SCHEMA
from .util import valid_publish_topic, valid_subscribe_topic

View File

@ -34,7 +34,7 @@ from homeassistant.util.json import json_loads_object
from . import subscription
from .config import MQTT_BASE_SCHEMA
from .const import CONF_COMMAND_TOPIC, CONF_RETAIN, CONF_STATE_TOPIC
from .mixins import MqttEntity, async_setup_entity_entry_helper
from .entity import MqttEntity, async_setup_entity_entry_helper
from .models import ReceiveMessage
from .schemas import MQTT_ENTITY_COMMON_SCHEMA
from .util import valid_publish_topic

View File

@ -59,7 +59,7 @@ from .const import (
DEFAULT_RETAIN,
PAYLOAD_NONE,
)
from .mixins import MqttEntity, async_setup_entity_entry_helper
from .entity import MqttEntity, async_setup_entity_entry_helper
from .models import MqttCommandTemplate, MqttValueTemplate, ReceiveMessage
from .schemas import MQTT_ENTITY_COMMON_SCHEMA
from .util import valid_publish_topic, valid_subscribe_topic

View File

@ -65,7 +65,7 @@ from .const import (
DEFAULT_OPTIMISTIC,
PAYLOAD_NONE,
)
from .mixins import async_setup_entity_entry_helper
from .entity import async_setup_entity_entry_helper
from .models import MqttCommandTemplate, MqttValueTemplate, ReceiveMessage
from .schemas import MQTT_ENTITY_COMMON_SCHEMA
from .util import valid_publish_topic, valid_subscribe_topic

View File

@ -20,7 +20,7 @@ from homeassistant.components.mqtt.const import (
MQTT_CONNECTION_STATE,
SUPPORTED_COMPONENTS,
)
from homeassistant.components.mqtt.mixins import MQTT_ATTRIBUTES_BLOCKED
from homeassistant.components.mqtt.entity import MQTT_ATTRIBUTES_BLOCKED
from homeassistant.components.mqtt.models import PublishPayloadType
from homeassistant.config_entries import ConfigEntryState
from homeassistant.const import (
@ -1938,7 +1938,7 @@ async def help_test_skipped_async_ha_write_state(
) -> None:
"""Test entity.async_ha_write_state is only called on changes."""
with patch(
"homeassistant.components.mqtt.mixins.MqttEntity.async_write_ha_state"
"homeassistant.components.mqtt.entity.MqttEntity.async_write_ha_state"
) as mock_async_ha_write_state:
assert len(mock_async_ha_write_state.mock_calls) == 0
async_fire_mqtt_message(hass, topic, payload1)

View File

@ -90,7 +90,7 @@ async def test_multiple_events_are_all_updating_the_state(
"""Test all events are respected and trigger a state write."""
await mqtt_mock_entry()
with patch(
"homeassistant.components.mqtt.mixins.MqttEntity.async_write_ha_state"
"homeassistant.components.mqtt.entity.MqttEntity.async_write_ha_state"
) as mock_async_ha_write_state:
async_fire_mqtt_message(
hass, "test-topic", '{"event_type": "press", "duration": "short" }'
@ -109,7 +109,7 @@ async def test_handling_retained_event_payloads(
"""Test if event messages with a retained flag are ignored."""
await mqtt_mock_entry()
with patch(
"homeassistant.components.mqtt.mixins.MqttEntity.async_write_ha_state"
"homeassistant.components.mqtt.entity.MqttEntity.async_write_ha_state"
) as mock_async_ha_write_state:
async_fire_mqtt_message(
hass,
@ -752,7 +752,7 @@ async def test_skipped_async_ha_write_state2(
payload1 = '{"event_type": "press"}'
payload2 = '{"event_type": "unknown"}'
with patch(
"homeassistant.components.mqtt.mixins.MqttEntity.async_write_ha_state"
"homeassistant.components.mqtt.entity.MqttEntity.async_write_ha_state"
) as mock_async_ha_write_state:
assert len(mock_async_ha_write_state.mock_calls) == 0
async_fire_mqtt_message(hass, topic, payload1)

View File

@ -1894,7 +1894,7 @@ async def test_disabling_and_enabling_entry(
config_light = '{"name": "test_new", "command_topic": "test-topic_new"}'
with patch(
"homeassistant.components.mqtt.mixins.mqtt_config_entry_enabled",
"homeassistant.components.mqtt.entity.mqtt_config_entry_enabled",
return_value=False,
):
# Discovery of mqtt tag