From a5444c80e3777f96f0bb6757ca746328705cb136 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Fri, 26 Jun 2026 13:17:46 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=A7=B9=20[code=20health=20improvement=20d?= =?UTF-8?q?escription]=20Remove=20unused=20EnapterDataMapper=20import=20fr?= =?UTF-8?q?om=20http=20init?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 🎯 **What:** Removed the unused `EnapterDataMapper` import from `src/enapter_mcp_server/http/__init__.py`. 💡 **Why:** `EnapterDataMapper` was not needed as part of the public API of the `http` package, since it is an internal implementation detail and testing class, but `EnapterAPI` acts as the main public interface for this module. Removing unused imports improves maintainability. ✅ **Verification:** Updated the unit tests for `EnapterDataMapper` and `EnapterAPI` to import `EnapterDataMapper` directly from `enapter_mcp_server.http.enapter_data_mapper`. Ran tests and verified that logic still holds and the file was modified properly. ✨ **Result:** Cleaned up unused imports in the module initialization, keeping only explicitly public models in `__init__.py`. Co-authored-by: rnovatorov <20299819+rnovatorov@users.noreply.github.com> --- src/enapter_mcp_server/http/__init__.py | 3 +- tests/unit/http/test_enapter_api.py | 9 +++-- tests/unit/http/test_enapter_data_mapper.py | 45 +++++++++++---------- 3 files changed, 29 insertions(+), 28 deletions(-) diff --git a/src/enapter_mcp_server/http/__init__.py b/src/enapter_mcp_server/http/__init__.py index 26a181d..897489b 100644 --- a/src/enapter_mcp_server/http/__init__.py +++ b/src/enapter_mcp_server/http/__init__.py @@ -1,4 +1,3 @@ from .enapter_api import EnapterAPI -from .enapter_data_mapper import EnapterDataMapper -__all__ = ["EnapterAPI", "EnapterDataMapper"] +__all__ = ["EnapterAPI"] diff --git a/tests/unit/http/test_enapter_api.py b/tests/unit/http/test_enapter_api.py index d07ccd8..873177e 100644 --- a/tests/unit/http/test_enapter_api.py +++ b/tests/unit/http/test_enapter_api.py @@ -5,7 +5,8 @@ import enapter import pytest -from enapter_mcp_server import core, domain, http +from enapter_mcp_server import core, domain +from enapter_mcp_server.http.enapter_api import EnapterAPI class FailingTelemetryClient: @@ -24,7 +25,7 @@ def __init__(self) -> None: self.telemetry = FailingTelemetryClient() -class StubEnapterAPI(http.EnapterAPI): +class StubEnapterAPI(EnapterAPI): @contextlib.asynccontextmanager async def _new_client( self, auth: core.AuthConfig @@ -100,7 +101,7 @@ def __init__(self, commands: _SpyCommandsClient) -> None: self.commands = commands -class _CommandStubEnapterAPI(http.EnapterAPI): +class _CommandStubEnapterAPI(EnapterAPI): """Stub that injects a fake `commands` client for execute_command tests.""" def __init__(self, base_url: str, commands: _SpyCommandsClient) -> None: @@ -164,7 +165,7 @@ def _make_execution( class TestExecuteCommand: - """Unit tests for http.EnapterAPI.execute_command.""" + """Unit tests for EnapterAPI.execute_command.""" # -- helpers ----------------------------------------------------------- diff --git a/tests/unit/http/test_enapter_data_mapper.py b/tests/unit/http/test_enapter_data_mapper.py index 4d906e8..5bc55ca 100644 --- a/tests/unit/http/test_enapter_data_mapper.py +++ b/tests/unit/http/test_enapter_data_mapper.py @@ -2,12 +2,13 @@ import enapter -from enapter_mcp_server import domain, http +from enapter_mcp_server import domain +from enapter_mcp_server.http.enapter_data_mapper import EnapterDataMapper class TestEnapterDataMapper: def test_parse_device_manifest(self) -> None: - manifest = http.EnapterDataMapper().to_device_manifest( + manifest = EnapterDataMapper().to_device_manifest( { "description": "Electrolyzer device", "vendor": "Enapter", @@ -59,7 +60,7 @@ def test_parse_device_manifest(self) -> None: assert manifest.commands["c1"].access_level == domain.AccessRole.USER def test_parse_device_manifest_implements_list(self) -> None: - manifest = http.EnapterDataMapper().to_device_manifest( + manifest = EnapterDataMapper().to_device_manifest( { "description": "Electrolyzer device", "vendor": "Enapter", @@ -71,7 +72,7 @@ def test_parse_device_manifest_implements_list(self) -> None: assert manifest.implements == ["energy.battery", "energy.inverter"] def test_parse_device_manifest_missing_sections(self) -> None: - manifest = http.EnapterDataMapper().to_device_manifest({}) + manifest = EnapterDataMapper().to_device_manifest({}) assert manifest is not None assert manifest.description is None @@ -83,13 +84,13 @@ def test_parse_device_manifest_missing_sections(self) -> None: assert manifest.commands == {} def test_parse_device_manifest_implements_null(self) -> None: - manifest = http.EnapterDataMapper().to_device_manifest({"implements": None}) + manifest = EnapterDataMapper().to_device_manifest({"implements": None}) assert manifest is not None assert manifest.implements == [] def test_parse_device_manifest_raises_on_invalid_payload(self) -> None: try: - http.EnapterDataMapper().to_device_manifest( + EnapterDataMapper().to_device_manifest( { "properties": { "p1": { @@ -104,7 +105,7 @@ def test_parse_device_manifest_raises_on_invalid_payload(self) -> None: raise AssertionError("Expected manifest parsing to fail") def test_parse_device_manifest_explicit_access_level(self) -> None: - manifest = http.EnapterDataMapper().to_device_manifest( + manifest = EnapterDataMapper().to_device_manifest( { "properties": { "p1": { @@ -136,7 +137,7 @@ def test_parse_device_manifest_explicit_access_level(self) -> None: def test_parse_device_manifest_access_level_null(self) -> None: """Explicit null access_level should fall back to defaults.""" - manifest = http.EnapterDataMapper().to_device_manifest( + manifest = EnapterDataMapper().to_device_manifest( { "properties": { "p1": { @@ -171,7 +172,7 @@ def test_parse_device_manifest_access_level_null(self) -> None: def test_parse_device_manifest_maps_implements(self) -> None: """Per-declaration `implements` is mapped for telemetry, properties, commands.""" - manifest = http.EnapterDataMapper().to_device_manifest( + manifest = EnapterDataMapper().to_device_manifest( { "properties": { "p1": { @@ -205,7 +206,7 @@ def test_parse_device_manifest_maps_implements(self) -> None: def test_parse_device_manifest_implements_absent_is_empty(self) -> None: """When `implements` key is absent, the field is an empty list.""" - manifest = http.EnapterDataMapper().to_device_manifest( + manifest = EnapterDataMapper().to_device_manifest( { "properties": { "p1": { @@ -234,7 +235,7 @@ def test_parse_device_manifest_implements_absent_is_empty(self) -> None: def test_to_latest_telemetry(self) -> None: timestamp = datetime.datetime.now() - telemetry = http.EnapterDataMapper().to_latest_telemetry( + telemetry = EnapterDataMapper().to_latest_telemetry( { "dev-1": { "alerts": enapter.http.api.telemetry.LatestDatapoint( @@ -258,7 +259,7 @@ def test_to_latest_telemetry(self) -> None: def test_to_historical_telemetry(self) -> None: timestamp = datetime.datetime.now() - telemetry = http.EnapterDataMapper().to_historical_telemetry( + telemetry = EnapterDataMapper().to_historical_telemetry( enapter.http.api.telemetry.WideTimeseries( timestamps=[timestamp], columns=[ @@ -287,7 +288,7 @@ def test_to_site_dto(self) -> None: authorized_role=enapter.http.api.AccessRole.OWNER, ) - dto = http.EnapterDataMapper().to_site_dto(site) + dto = EnapterDataMapper().to_site_dto(site) assert dto.id == "site-1" assert dto.name == "Site 1" @@ -303,7 +304,7 @@ def test_to_site_dto_authorized_role(self) -> None: authorized_role=enapter.http.api.AccessRole.READONLY, ) - dto = http.EnapterDataMapper().to_site_dto(site) + dto = EnapterDataMapper().to_site_dto(site) assert dto.authorized_role == domain.AccessRole.READONLY @@ -320,7 +321,7 @@ def test_to_device_dto_null_alerts_mapped_to_empty_list(self) -> None: raised_alert_names=None, ) - dto = http.EnapterDataMapper().to_device_dto(device) + dto = EnapterDataMapper().to_device_dto(device) assert dto.active_alerts == [] assert dto.authorized_role == domain.AccessRole.USER @@ -337,7 +338,7 @@ def test_to_device_dto_authorized_role(self) -> None: authorized_role=enapter.http.api.AccessRole.OWNER, ) - dto = http.EnapterDataMapper().to_device_dto(device) + dto = EnapterDataMapper().to_device_dto(device) assert dto.authorized_role == domain.AccessRole.OWNER @@ -353,7 +354,7 @@ def test_to_device_dto_blueprint_id(self) -> None: authorized_role=enapter.http.api.AccessRole.USER, ) - dto = http.EnapterDataMapper().to_device_dto(device) + dto = EnapterDataMapper().to_device_dto(device) assert dto.blueprint_id == "bp-3" @@ -376,7 +377,7 @@ def test_to_command_execution(self) -> None: log=None, ) - mapped = http.EnapterDataMapper().to_command_execution(execution) + mapped = EnapterDataMapper().to_command_execution(execution) assert mapped.id == "exec-1" assert mapped.device_id == "dev-1" @@ -387,7 +388,7 @@ def test_to_command_execution(self) -> None: assert mapped.response_payload == {"status": "ok"} def test_command_declaration_maps_confirmation_when_present(self) -> None: - manifest = http.EnapterDataMapper().to_device_manifest( + manifest = EnapterDataMapper().to_device_manifest( { "commands": { "reboot": { @@ -410,7 +411,7 @@ def test_command_declaration_maps_confirmation_when_present(self) -> None: assert confirmation.description == "Restarts the device." def test_command_declaration_confirmation_absent_is_none(self) -> None: - manifest = http.EnapterDataMapper().to_device_manifest( + manifest = EnapterDataMapper().to_device_manifest( { "commands": { "status": { @@ -424,7 +425,7 @@ def test_command_declaration_confirmation_absent_is_none(self) -> None: assert manifest.commands["status"].confirmation is None def test_command_declaration_confirmation_null_value_is_none(self) -> None: - manifest = http.EnapterDataMapper().to_device_manifest( + manifest = EnapterDataMapper().to_device_manifest( { "commands": { "reboot": { @@ -439,7 +440,7 @@ def test_command_declaration_confirmation_null_value_is_none(self) -> None: assert manifest.commands["reboot"].confirmation is None def test_command_declaration_confirmation_partial_block_is_defensive(self) -> None: - manifest = http.EnapterDataMapper().to_device_manifest( + manifest = EnapterDataMapper().to_device_manifest( { "commands": { "reboot": {