diff --git a/homeassistant/components/co2signal/sensor.py b/homeassistant/components/co2signal/sensor.py index e9cfdb87983..cb2ff40c062 100644 --- a/homeassistant/components/co2signal/sensor.py +++ b/homeassistant/components/co2signal/sensor.py @@ -47,10 +47,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None): _LOGGER.debug("Setting up the sensor using the %s", country_code) - devs = [] - - devs.append(CO2Sensor(token, country_code, lat, lon)) - add_entities(devs, True) + add_entities([CO2Sensor(token, country_code, lat, lon)], True) class CO2Sensor(SensorEntity): @@ -65,42 +62,27 @@ class CO2Sensor(SensorEntity): self._country_code = country_code self._latitude = lat self._longitude = lon - self._data = None if country_code is not None: device_name = country_code else: device_name = f"{round(self._latitude, 2)}/{round(self._longitude, 2)}" - self._friendly_name = f"CO2 intensity - {device_name}" - - @property - def name(self): - """Return the name of the sensor.""" - return self._friendly_name - - @property - def state(self): - """Return the state of the device.""" - return self._data - - @property - def extra_state_attributes(self): - """Return the state attributes of the last update.""" - return {ATTR_ATTRIBUTION: ATTRIBUTION} + self._attr_name = f"CO2 intensity - {device_name}" + self._attr_extra_state_attributes = {ATTR_ATTRIBUTION: ATTRIBUTION} def update(self): """Get the latest data and updates the states.""" - _LOGGER.debug("Update data for %s", self._friendly_name) + _LOGGER.debug("Update data for %s", self.name) if self._country_code is not None: - self._data = CO2Signal.get_latest_carbon_intensity( + data = CO2Signal.get_latest_carbon_intensity( self._token, country_code=self._country_code ) else: - self._data = CO2Signal.get_latest_carbon_intensity( + data = CO2Signal.get_latest_carbon_intensity( self._token, latitude=self._latitude, longitude=self._longitude ) - self._data = round(self._data, 2) + self._attr_state = round(data, 2)