From f60850586e05e486bd32c44bbfeaa9d23ed0816b Mon Sep 17 00:00:00 2001 From: Jan Bouwhuis Date: Thu, 17 Nov 2022 10:11:25 +0100 Subject: [PATCH] Remove `b64` encoding work-a-round for MQTT camera (#82244) --- homeassistant/components/mqtt/camera.py | 18 +---------- tests/components/mqtt/test_camera.py | 40 +------------------------ 2 files changed, 2 insertions(+), 56 deletions(-) diff --git a/homeassistant/components/mqtt/camera.py b/homeassistant/components/mqtt/camera.py index 5044f5abfaf..8f52212172d 100644 --- a/homeassistant/components/mqtt/camera.py +++ b/homeassistant/components/mqtt/camera.py @@ -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) diff --git a/tests/components/mqtt/test_camera.py b/tests/components/mqtt/test_camera.py index 4cb6afb6495..5b8ad747244 100644 --- a/tests/components/mqtt/test_camera.py +++ b/tests/components/mqtt/test_camera.py @@ -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 ):