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 # deadline for image refresh - self.delta after last successful load
self._deadline: Optional[datetime] = None self._deadline: Optional[datetime] = None
self._unique_id = f"{self._dimension}_{self._country}"
@property @property
def name(self) -> str: def name(self) -> str:
"""Return the component name.""" """Return the component name."""
@ -186,3 +188,8 @@ class BuienradarCam(Camera):
async with self._condition: async with self._condition:
self._loading = False self._loading = False
self._condition.notify_all() 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): async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
"""Create the buienradar sensor.""" """Create the buienradar sensor."""
latitude = config.get(CONF_LATITUDE, hass.config.latitude) latitude = config.get(CONF_LATITUDE, hass.config.latitude)
longitude = config.get(CONF_LONGITUDE, hass.config.longitude) longitude = config.get(CONF_LONGITUDE, hass.config.longitude)
timeframe = config[CONF_TIMEFRAME] timeframe = config[CONF_TIMEFRAME]
@ -236,7 +235,6 @@ class BrSensor(Entity):
def __init__(self, sensor_type, client_name, coordinates): def __init__(self, sensor_type, client_name, coordinates):
"""Initialize the sensor.""" """Initialize the sensor."""
self.client_name = client_name self.client_name = client_name
self._name = SENSOR_TYPES[sensor_type][0] self._name = SENSOR_TYPES[sensor_type][0]
self.type = sensor_type self.type = sensor_type
@ -428,7 +426,6 @@ class BrSensor(Entity):
@property @property
def device_state_attributes(self): def device_state_attributes(self):
"""Return the state attributes.""" """Return the state attributes."""
if self.type.startswith(PRECIPITATION_FORECAST): if self.type.startswith(PRECIPITATION_FORECAST):
result = {ATTR_ATTRIBUTION: self._attribution} result = {ATTR_ATTRIBUTION: self._attribution}
if self._timeframe is not None: if self._timeframe is not None:

View file

@ -107,7 +107,6 @@ class BrData:
async def async_update(self, *_): async def async_update(self, *_):
"""Update the data from buienradar.""" """Update the data from buienradar."""
content = await self.get_data(JSON_FEED_URL) content = await self.get_data(JSON_FEED_URL)
if content.get(SUCCESS) is not True: if content.get(SUCCESS) is not True:
@ -170,25 +169,21 @@ class BrData:
@property @property
def attribution(self): def attribution(self):
"""Return the attribution.""" """Return the attribution."""
return self.data.get(ATTRIBUTION) return self.data.get(ATTRIBUTION)
@property @property
def stationname(self): def stationname(self):
"""Return the name of the selected weatherstation.""" """Return the name of the selected weatherstation."""
return self.data.get(STATIONNAME) return self.data.get(STATIONNAME)
@property @property
def condition(self): def condition(self):
"""Return the condition.""" """Return the condition."""
return self.data.get(CONDITION) return self.data.get(CONDITION)
@property @property
def temperature(self): def temperature(self):
"""Return the temperature, or None.""" """Return the temperature, or None."""
try: try:
return float(self.data.get(TEMPERATURE)) return float(self.data.get(TEMPERATURE))
except (ValueError, TypeError): except (ValueError, TypeError):
@ -197,7 +192,6 @@ class BrData:
@property @property
def pressure(self): def pressure(self):
"""Return the pressure, or None.""" """Return the pressure, or None."""
try: try:
return float(self.data.get(PRESSURE)) return float(self.data.get(PRESSURE))
except (ValueError, TypeError): except (ValueError, TypeError):
@ -206,7 +200,6 @@ class BrData:
@property @property
def humidity(self): def humidity(self):
"""Return the humidity, or None.""" """Return the humidity, or None."""
try: try:
return int(self.data.get(HUMIDITY)) return int(self.data.get(HUMIDITY))
except (ValueError, TypeError): except (ValueError, TypeError):
@ -215,7 +208,6 @@ class BrData:
@property @property
def visibility(self): def visibility(self):
"""Return the visibility, or None.""" """Return the visibility, or None."""
try: try:
return int(self.data.get(VISIBILITY)) return int(self.data.get(VISIBILITY))
except (ValueError, TypeError): except (ValueError, TypeError):
@ -224,7 +216,6 @@ class BrData:
@property @property
def wind_speed(self): def wind_speed(self):
"""Return the windspeed, or None.""" """Return the windspeed, or None."""
try: try:
return float(self.data.get(WINDSPEED)) return float(self.data.get(WINDSPEED))
except (ValueError, TypeError): except (ValueError, TypeError):
@ -233,7 +224,6 @@ class BrData:
@property @property
def wind_bearing(self): def wind_bearing(self):
"""Return the wind bearing, or None.""" """Return the wind bearing, or None."""
try: try:
return int(self.data.get(WINDAZIMUTH)) return int(self.data.get(WINDAZIMUTH))
except (ValueError, TypeError): except (ValueError, TypeError):
@ -242,5 +232,4 @@ class BrData:
@property @property
def forecast(self): def forecast(self):
"""Return the forecast data.""" """Return the forecast data."""
return self.data.get(FORECAST) 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: for condi in condlst:
hass.data[DATA_CONDITION][condi] = cond 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: # schedule the first update in 1 minute from now:
await data.schedule_update(1) await data.schedule_update(1)
@ -99,12 +99,16 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
class BrWeather(WeatherEntity): class BrWeather(WeatherEntity):
"""Representation of a weather condition.""" """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.""" """Initialise the platform with a data instance and station name."""
self._stationname = config.get(CONF_NAME) self._stationname = config.get(CONF_NAME)
self._forecast = config[CONF_FORECAST] self._forecast = config[CONF_FORECAST]
self._data = data self._data = data
self._unique_id = "{:2.6f}{:2.6f}".format(
coordinates[CONF_LATITUDE], coordinates[CONF_LONGITUDE]
)
@property @property
def attribution(self): def attribution(self):
"""Return the attribution.""" """Return the attribution."""
@ -120,7 +124,6 @@ class BrWeather(WeatherEntity):
@property @property
def condition(self): def condition(self):
"""Return the current condition.""" """Return the current condition."""
if self._data and self._data.condition: if self._data and self._data.condition:
ccode = self._data.condition.get(CONDCODE) ccode = self._data.condition.get(CONDCODE)
if ccode: if ccode:
@ -170,7 +173,6 @@ class BrWeather(WeatherEntity):
@property @property
def forecast(self): def forecast(self):
"""Return the forecast array.""" """Return the forecast array."""
if not self._forecast: if not self._forecast:
return None return None
@ -197,3 +199,8 @@ class BrWeather(WeatherEntity):
fcdata_out.append(data_out) fcdata_out.append(data_out)
return fcdata_out return fcdata_out
@property
def unique_id(self):
"""Return the unique id."""
return self._unique_id