Add country code to co2signal state attributes (#53512)

This commit is contained in:
Paulus Schoutsen 2021-07-26 11:10:39 -07:00 committed by GitHub
parent f28d8fae2f
commit 962ddf664c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 1 deletions

View File

@ -100,7 +100,10 @@ class CO2Sensor(update_coordinator.CoordinatorEntity[CO2SignalResponse], SensorE
name = f"{extra_name} - {name}" name = f"{extra_name} - {name}"
self._attr_name = name self._attr_name = name
self._attr_extra_state_attributes = {ATTR_ATTRIBUTION: ATTRIBUTION} self._attr_extra_state_attributes = {
"country_code": coordinator.data["countryCode"],
ATTR_ATTRIBUTION: ATTRIBUTION,
}
self._attr_device_info = { self._attr_device_info = {
ATTR_IDENTIFIERS: {(DOMAIN, coordinator.entry_id)}, ATTR_IDENTIFIERS: {(DOMAIN, coordinator.entry_id)},
ATTR_NAME: "CO2 signal", ATTR_NAME: "CO2 signal",

View File

@ -218,12 +218,14 @@ async def test_import(hass: HomeAssistant) -> None:
assert state.state == "45.99" assert state.state == "45.99"
assert state.name == "CO2 intensity" assert state.name == "CO2 intensity"
assert state.attributes["unit_of_measurement"] == "gCO2eq/kWh" assert state.attributes["unit_of_measurement"] == "gCO2eq/kWh"
assert state.attributes["country_code"] == "FR"
state = hass.states.get("sensor.grid_fossil_fuel_percentage") state = hass.states.get("sensor.grid_fossil_fuel_percentage")
assert state is not None assert state is not None
assert state.state == "5.46" assert state.state == "5.46"
assert state.name == "Grid fossil fuel percentage" assert state.name == "Grid fossil fuel percentage"
assert state.attributes["unit_of_measurement"] == "%" assert state.attributes["unit_of_measurement"] == "%"
assert state.attributes["country_code"] == "FR"
async def test_import_abort_existing_home(hass: HomeAssistant) -> None: async def test_import_abort_existing_home(hass: HomeAssistant) -> None: