Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump datapoint to 0.9.9 + re-enable Met Office Integration #110206

Merged
merged 16 commits into from Feb 13, 2024
Merged
12 changes: 3 additions & 9 deletions homeassistant/components/metoffice/__init__.py
Expand Up @@ -4,9 +4,10 @@
import asyncio
import logging
import re
import sys
from typing import Any

import datapoint

from homeassistant.config_entries import ConfigEntry
from homeassistant.const import (
CONF_API_KEY,
Expand All @@ -16,7 +17,7 @@
Platform,
)
from homeassistant.core import HomeAssistant, callback
from homeassistant.exceptions import ConfigEntryNotReady, HomeAssistantError
from homeassistant.exceptions import ConfigEntryNotReady
from homeassistant.helpers import device_registry as dr, entity_registry as er
from homeassistant.helpers.device_registry import DeviceInfo
from homeassistant.helpers.update_coordinator import TimestampDataUpdateCoordinator
Expand All @@ -34,20 +35,13 @@
from .data import MetOfficeData
from .helpers import fetch_data, fetch_site

if sys.version_info < (3, 12):
import datapoint

_LOGGER = logging.getLogger(__name__)

PLATFORMS = [Platform.SENSOR, Platform.WEATHER]


async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Set up a Met Office entry."""
if sys.version_info >= (3, 12):
raise HomeAssistantError(
"Met Office is not supported on Python 3.12. Please use Python 3.11."
)

latitude = entry.data[CONF_LATITUDE]
longitude = entry.data[CONF_LONGITUDE]
Expand Down
8 changes: 3 additions & 5 deletions homeassistant/components/metoffice/data.py
Expand Up @@ -2,12 +2,10 @@
from __future__ import annotations

from dataclasses import dataclass
import sys

if sys.version_info < (3, 12):
from datapoint.Forecast import Forecast
from datapoint.Site import Site
from datapoint.Timestep import Timestep
from datapoint.Forecast import Forecast
from datapoint.Site import Site
from datapoint.Timestep import Timestep


@dataclass
Expand Down
11 changes: 4 additions & 7 deletions homeassistant/components/metoffice/helpers.py
Expand Up @@ -2,19 +2,16 @@
from __future__ import annotations

import logging
import sys

import datapoint
from datapoint.Site import Site

from homeassistant.helpers.update_coordinator import UpdateFailed
from homeassistant.util.dt import utcnow

from .const import MODE_3HOURLY
from .data import MetOfficeData

if sys.version_info < (3, 12):
import datapoint
from datapoint.Site import Site


_LOGGER = logging.getLogger(__name__)


Expand All @@ -34,7 +31,7 @@ def fetch_site(
def fetch_data(connection: datapoint.Manager, site: Site, mode: str) -> MetOfficeData:
"""Fetch weather and forecast from Datapoint API."""
try:
forecast = connection.get_forecast_for_site(site.id, mode)
forecast = connection.get_forecast_for_site(site.location_id, mode)
except (ValueError, datapoint.exceptions.APIException) as err:
_LOGGER.error("Check Met Office connection: %s", err.args)
raise UpdateFailed from err
Expand Down
3 changes: 1 addition & 2 deletions homeassistant/components/metoffice/manifest.json
DustyArmstrong marked this conversation as resolved.
Show resolved Hide resolved
Expand Up @@ -3,9 +3,8 @@
"name": "Met Office",
"codeowners": ["@MrHarcombe", "@avee87"],
"config_flow": true,
"disabled": "Integration library not compatible with Python 3.12",
"documentation": "https://www.home-assistant.io/integrations/metoffice",
"iot_class": "cloud_polling",
"loggers": ["datapoint"],
"requirements": ["datapoint==0.9.8;python_version<'3.12'"]
"requirements": ["datapoint==0.9.9"]
DustyArmstrong marked this conversation as resolved.
Show resolved Hide resolved
}
2 changes: 1 addition & 1 deletion homeassistant/components/metoffice/sensor.py
Expand Up @@ -251,6 +251,6 @@ def extra_state_attributes(self) -> dict[str, Any]:
return {
ATTR_LAST_UPDATE: self.coordinator.data.now.date,
ATTR_SENSOR_ID: self.entity_description.key,
ATTR_SITE_ID: self.coordinator.data.site.id,
ATTR_SITE_ID: self.coordinator.data.site.location_id,
ATTR_SITE_NAME: self.coordinator.data.site.name,
}
3 changes: 3 additions & 0 deletions requirements_all.txt
Expand Up @@ -680,6 +680,9 @@ crownstone-uart==2.1.0
# homeassistant.components.datadog
datadog==0.15.0

# homeassistant.components.metoffice
datapoint==0.9.9

# homeassistant.components.bluetooth
dbus-fast==2.21.1

Expand Down
3 changes: 3 additions & 0 deletions requirements_test_all.txt
Expand Up @@ -561,6 +561,9 @@ crownstone-uart==2.1.0
# homeassistant.components.datadog
datadog==0.15.0

# homeassistant.components.metoffice
datapoint==0.9.9

# homeassistant.components.bluetooth
dbus-fast==2.21.1

Expand Down
8 changes: 1 addition & 7 deletions tests/components/metoffice/conftest.py
@@ -1,15 +1,9 @@
"""Fixtures for Met Office weather integration tests."""
from unittest.mock import patch

from datapoint.exceptions import APIException
import pytest

# All tests are marked as disabled, as the integration is disabled in the
# integration manifest. `datapoint` isn't compatible with Python 3.12
#
# from datapoint.exceptions import APIException
APIException = Exception
collect_ignore_glob = ["test_*.py"]


@pytest.fixture
def mock_simple_manager_fail():
Expand Down