From 962ddf664c3dcb2f439898aa550143687a10ef5b Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Mon, 26 Jul 2021 11:10:39 -0700 Subject: [PATCH] Add country code to co2signal state attributes (#53512) --- homeassistant/components/co2signal/sensor.py | 5 ++++- tests/components/co2signal/test_config_flow.py | 2 ++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/homeassistant/components/co2signal/sensor.py b/homeassistant/components/co2signal/sensor.py index 0b79378c36b..e7ac138335b 100644 --- a/homeassistant/components/co2signal/sensor.py +++ b/homeassistant/components/co2signal/sensor.py @@ -100,7 +100,10 @@ class CO2Sensor(update_coordinator.CoordinatorEntity[CO2SignalResponse], SensorE name = f"{extra_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 = { ATTR_IDENTIFIERS: {(DOMAIN, coordinator.entry_id)}, ATTR_NAME: "CO2 signal", diff --git a/tests/components/co2signal/test_config_flow.py b/tests/components/co2signal/test_config_flow.py index 129ab7124fe..668c72e9b04 100644 --- a/tests/components/co2signal/test_config_flow.py +++ b/tests/components/co2signal/test_config_flow.py @@ -218,12 +218,14 @@ async def test_import(hass: HomeAssistant) -> None: assert state.state == "45.99" assert state.name == "CO2 intensity" assert state.attributes["unit_of_measurement"] == "gCO2eq/kWh" + assert state.attributes["country_code"] == "FR" state = hass.states.get("sensor.grid_fossil_fuel_percentage") assert state is not None assert state.state == "5.46" assert state.name == "Grid fossil fuel percentage" assert state.attributes["unit_of_measurement"] == "%" + assert state.attributes["country_code"] == "FR" async def test_import_abort_existing_home(hass: HomeAssistant) -> None: