Remove b64 encoding work-a-round for MQTT camera (#82244)

This commit is contained in:
Jan Bouwhuis 2022-11-17 10:11:25 +01:00 committed by GitHub
parent 4c8850ec7b
commit f60850586e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 2 additions and 56 deletions

View file

@ -18,7 +18,7 @@ from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
from . import subscription
from .config import MQTT_BASE_SCHEMA
from .const import CONF_ENCODING, CONF_QOS, CONF_TOPIC, DEFAULT_ENCODING
from .const import CONF_QOS, CONF_TOPIC
from .debug_info import log_messages
from .mixins import (
MQTT_ENTITY_COMMON_SCHEMA,
@ -45,20 +45,6 @@ MQTT_CAMERA_ATTRIBUTES_BLOCKED = frozenset(
}
)
# Using CONF_ENCODING to set b64 encoding for images is deprecated as of Home Assistant 2022.9
# use CONF_IMAGE_ENCODING instead, support for the work-a-round will be removed with Home Assistant 2022.11
def repair_legacy_encoding(config: ConfigType) -> ConfigType:
"""Check incorrect deprecated config of image encoding."""
if config[CONF_ENCODING] == "b64":
config[CONF_IMAGE_ENCODING] = "b64"
config[CONF_ENCODING] = DEFAULT_ENCODING
_LOGGER.warning(
"Using the `encoding` parameter to set image encoding has been deprecated, use `image_encoding` instead"
)
return config
PLATFORM_SCHEMA_BASE = MQTT_BASE_SCHEMA.extend(
{
vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
@ -69,14 +55,12 @@ PLATFORM_SCHEMA_BASE = MQTT_BASE_SCHEMA.extend(
PLATFORM_SCHEMA_MODERN = vol.All(
PLATFORM_SCHEMA_BASE.schema,
repair_legacy_encoding,
)
# Configuring MQTT Camera under the camera platform key is deprecated in HA Core 2022.6
PLATFORM_SCHEMA = vol.All(
cv.PLATFORM_SCHEMA.extend(PLATFORM_SCHEMA_BASE.schema),
warn_for_legacy_schema(camera.DOMAIN),
repair_legacy_encoding,
)
DISCOVERY_SCHEMA = PLATFORM_SCHEMA_BASE.extend({}, extra=vol.REMOVE_EXTRA)

View file

@ -95,7 +95,7 @@ async def test_run_camera_b64_encoded(
camera.DOMAIN: {
"topic": topic,
"name": "Test Camera",
"encoding": "b64",
"image_encoding": "b64",
}
}
},
@ -114,44 +114,6 @@ async def test_run_camera_b64_encoded(
assert body == "grass"
# Using CONF_ENCODING to set b64 encoding for images is deprecated in Home Assistant 2022.9, use CONF_IMAGE_ENCODING instead
async def test_legacy_camera_b64_encoded_with_availability(
hass, hass_client_no_auth, mqtt_mock_entry_with_yaml_config
):
"""Test availability works if b64 encoding (legacy mode) is turned on."""
topic = "test/camera"
topic_availability = "test/camera_availability"
await async_setup_component(
hass,
mqtt.DOMAIN,
{
mqtt.DOMAIN: {
camera.DOMAIN: {
"topic": topic,
"name": "Test Camera",
"encoding": "b64",
"availability": {"topic": topic_availability},
}
}
},
)
await hass.async_block_till_done()
await mqtt_mock_entry_with_yaml_config()
# Make sure we are available
async_fire_mqtt_message(hass, topic_availability, "online")
url = hass.states.get("camera.test_camera").attributes["entity_picture"]
async_fire_mqtt_message(hass, topic, b64encode(b"grass"))
client = await hass_client_no_auth()
resp = await client.get(url)
assert resp.status == HTTPStatus.OK
body = await resp.text()
assert body == "grass"
async def test_camera_b64_encoded_with_availability(
hass, hass_client_no_auth, mqtt_mock_entry_with_yaml_config
):