Add unique ids for "buienradar" platforms weather and camera (#37761)

* Add unique ids for buienradar weather and camera

* Remove prefix from unique ids
This commit is contained in:
Rob Bierbooms 2020-08-01 09:13:17 +02:00 committed by GitHub
parent 416ee7f143
commit ff1709979f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 18 additions and 18 deletions

View file

@ -95,6 +95,8 @@ class BuienradarCam(Camera):
# deadline for image refresh - self.delta after last successful load
self._deadline: Optional[datetime] = None
self._unique_id = f"{self._dimension}_{self._country}"
@property
def name(self) -> str:
"""Return the component name."""
@ -186,3 +188,8 @@ class BuienradarCam(Camera):
async with self._condition:
self._loading = False
self._condition.notify_all()
@property
def unique_id(self):
"""Return the unique id."""
return self._unique_id

View file

@ -204,7 +204,6 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
"""Create the buienradar sensor."""
latitude = config.get(CONF_LATITUDE, hass.config.latitude)
longitude = config.get(CONF_LONGITUDE, hass.config.longitude)
timeframe = config[CONF_TIMEFRAME]
@ -236,7 +235,6 @@ class BrSensor(Entity):
def __init__(self, sensor_type, client_name, coordinates):
"""Initialize the sensor."""
self.client_name = client_name
self._name = SENSOR_TYPES[sensor_type][0]
self.type = sensor_type
@ -428,7 +426,6 @@ class BrSensor(Entity):
@property
def device_state_attributes(self):
"""Return the state attributes."""
if self.type.startswith(PRECIPITATION_FORECAST):
result = {ATTR_ATTRIBUTION: self._attribution}
if self._timeframe is not None:

View file

@ -107,7 +107,6 @@ class BrData:
async def async_update(self, *_):
"""Update the data from buienradar."""
content = await self.get_data(JSON_FEED_URL)
if content.get(SUCCESS) is not True:
@ -170,25 +169,21 @@ class BrData:
@property
def attribution(self):
"""Return the attribution."""
return self.data.get(ATTRIBUTION)
@property
def stationname(self):
"""Return the name of the selected weatherstation."""
return self.data.get(STATIONNAME)
@property
def condition(self):
"""Return the condition."""
return self.data.get(CONDITION)
@property
def temperature(self):
"""Return the temperature, or None."""
try:
return float(self.data.get(TEMPERATURE))
except (ValueError, TypeError):
@ -197,7 +192,6 @@ class BrData:
@property
def pressure(self):
"""Return the pressure, or None."""
try:
return float(self.data.get(PRESSURE))
except (ValueError, TypeError):
@ -206,7 +200,6 @@ class BrData:
@property
def humidity(self):
"""Return the humidity, or None."""
try:
return int(self.data.get(HUMIDITY))
except (ValueError, TypeError):
@ -215,7 +208,6 @@ class BrData:
@property
def visibility(self):
"""Return the visibility, or None."""
try:
return int(self.data.get(VISIBILITY))
except (ValueError, TypeError):
@ -224,7 +216,6 @@ class BrData:
@property
def wind_speed(self):
"""Return the windspeed, or None."""
try:
return float(self.data.get(WINDSPEED))
except (ValueError, TypeError):
@ -233,7 +224,6 @@ class BrData:
@property
def wind_bearing(self):
"""Return the wind bearing, or None."""
try:
return int(self.data.get(WINDAZIMUTH))
except (ValueError, TypeError):
@ -242,5 +232,4 @@ class BrData:
@property
def forecast(self):
"""Return the forecast data."""
return self.data.get(FORECAST)

View file

@ -90,7 +90,7 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
for condi in condlst:
hass.data[DATA_CONDITION][condi] = cond
async_add_entities([BrWeather(data, config)])
async_add_entities([BrWeather(data, config, coordinates)])
# schedule the first update in 1 minute from now:
await data.schedule_update(1)
@ -99,12 +99,16 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
class BrWeather(WeatherEntity):
"""Representation of a weather condition."""
def __init__(self, data, config):
def __init__(self, data, config, coordinates):
"""Initialise the platform with a data instance and station name."""
self._stationname = config.get(CONF_NAME)
self._forecast = config[CONF_FORECAST]
self._data = data
self._unique_id = "{:2.6f}{:2.6f}".format(
coordinates[CONF_LATITUDE], coordinates[CONF_LONGITUDE]
)
@property
def attribution(self):
"""Return the attribution."""
@ -120,7 +124,6 @@ class BrWeather(WeatherEntity):
@property
def condition(self):
"""Return the current condition."""
if self._data and self._data.condition:
ccode = self._data.condition.get(CONDCODE)
if ccode:
@ -170,7 +173,6 @@ class BrWeather(WeatherEntity):
@property
def forecast(self):
"""Return the forecast array."""
if not self._forecast:
return None
@ -197,3 +199,8 @@ class BrWeather(WeatherEntity):
fcdata_out.append(data_out)
return fcdata_out
@property
def unique_id(self):
"""Return the unique id."""
return self._unique_id