mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 03:07:37 +00:00
Disable Met.no hourly weather by default (#39867)
Co-authored-by: Daniel Hjelseth Høyer <mail@dahoiv.net>
This commit is contained in:
parent
6e79d49c80
commit
b70df4ab18
@ -104,7 +104,6 @@ class MetWeather(CoordinatorEntity, WeatherEntity):
|
|||||||
self._config = config
|
self._config = config
|
||||||
self._is_metric = is_metric
|
self._is_metric = is_metric
|
||||||
self._hourly = hourly
|
self._hourly = hourly
|
||||||
self._name_appendix = "-hourly" if hourly else ""
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def track_home(self):
|
def track_home(self):
|
||||||
@ -114,23 +113,34 @@ class MetWeather(CoordinatorEntity, WeatherEntity):
|
|||||||
@property
|
@property
|
||||||
def unique_id(self):
|
def unique_id(self):
|
||||||
"""Return unique ID."""
|
"""Return unique ID."""
|
||||||
|
name_appendix = ""
|
||||||
|
if self._hourly:
|
||||||
|
name_appendix = "-hourly"
|
||||||
if self.track_home:
|
if self.track_home:
|
||||||
return f"home{self._name_appendix}"
|
return f"home{name_appendix}"
|
||||||
|
|
||||||
return f"{self._config[CONF_LATITUDE]}-{self._config[CONF_LONGITUDE]}{self._name_appendix}"
|
return f"{self._config[CONF_LATITUDE]}-{self._config[CONF_LONGITUDE]}{name_appendix}"
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
"""Return the name of the sensor."""
|
"""Return the name of the sensor."""
|
||||||
name = self._config.get(CONF_NAME)
|
name = self._config.get(CONF_NAME)
|
||||||
|
name_appendix = ""
|
||||||
|
if self._hourly:
|
||||||
|
name_appendix = " Hourly"
|
||||||
|
|
||||||
if name is not None:
|
if name is not None:
|
||||||
return f"{name}{self._name_appendix}"
|
return f"{name}{name_appendix}"
|
||||||
|
|
||||||
if self.track_home:
|
if self.track_home:
|
||||||
return f"{self.hass.config.location_name}{self._name_appendix}"
|
return f"{self.hass.config.location_name}{name_appendix}"
|
||||||
|
|
||||||
return f"{DEFAULT_NAME}{self._name_appendix}"
|
return f"{DEFAULT_NAME}{name_appendix}"
|
||||||
|
|
||||||
|
@property
|
||||||
|
def entity_registry_enabled_default(self) -> bool:
|
||||||
|
"""Return if the entity should be enabled when first added to the entity registry."""
|
||||||
|
return not self._hourly
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def condition(self):
|
def condition(self):
|
||||||
|
@ -1,13 +1,27 @@
|
|||||||
"""Test Met weather entity."""
|
"""Test Met weather entity."""
|
||||||
|
|
||||||
|
from homeassistant.components.met import DOMAIN
|
||||||
|
from homeassistant.components.weather import DOMAIN as WEATHER_DOMAIN
|
||||||
|
|
||||||
|
|
||||||
async def test_tracking_home(hass, mock_weather):
|
async def test_tracking_home(hass, mock_weather):
|
||||||
"""Test we track home."""
|
"""Test we track home."""
|
||||||
await hass.config_entries.flow.async_init("met", context={"source": "onboarding"})
|
await hass.config_entries.flow.async_init("met", context={"source": "onboarding"})
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
assert len(hass.states.async_entity_ids("weather")) == 2
|
assert len(hass.states.async_entity_ids("weather")) == 1
|
||||||
assert len(mock_weather.mock_calls) == 4
|
assert len(mock_weather.mock_calls) == 4
|
||||||
|
|
||||||
|
# Test the hourly sensor is disabled by default
|
||||||
|
registry = await hass.helpers.entity_registry.async_get_registry()
|
||||||
|
|
||||||
|
state = hass.states.get("weather.test_home_hourly")
|
||||||
|
assert state is None
|
||||||
|
|
||||||
|
entry = registry.async_get("weather.test_home_hourly")
|
||||||
|
assert entry
|
||||||
|
assert entry.disabled
|
||||||
|
assert entry.disabled_by == "integration"
|
||||||
|
|
||||||
# Test we track config
|
# Test we track config
|
||||||
await hass.config.async_update(latitude=10, longitude=20)
|
await hass.config.async_update(latitude=10, longitude=20)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
@ -21,6 +35,17 @@ async def test_tracking_home(hass, mock_weather):
|
|||||||
|
|
||||||
async def test_not_tracking_home(hass, mock_weather):
|
async def test_not_tracking_home(hass, mock_weather):
|
||||||
"""Test when we not track home."""
|
"""Test when we not track home."""
|
||||||
|
|
||||||
|
# Pre-create registry entry for disabled by default hourly weather
|
||||||
|
registry = await hass.helpers.entity_registry.async_get_registry()
|
||||||
|
registry.async_get_or_create(
|
||||||
|
WEATHER_DOMAIN,
|
||||||
|
DOMAIN,
|
||||||
|
"10-20-hourly",
|
||||||
|
suggested_object_id="somewhere_hourly",
|
||||||
|
disabled_by=None,
|
||||||
|
)
|
||||||
|
|
||||||
await hass.config_entries.flow.async_init(
|
await hass.config_entries.flow.async_init(
|
||||||
"met",
|
"met",
|
||||||
context={"source": "user"},
|
context={"source": "user"},
|
||||||
|
@ -276,4 +276,4 @@ async def test_onboarding_core_sets_up_met(hass, hass_storage, hass_client):
|
|||||||
assert resp.status == 200
|
assert resp.status == 200
|
||||||
|
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
assert len(hass.states.async_entity_ids("weather")) == 2
|
assert len(hass.states.async_entity_ids("weather")) == 1
|
||||||
|
Loading…
x
Reference in New Issue
Block a user