From 383e45e517acf7c56f04eaeba5022021face48fd Mon Sep 17 00:00:00 2001 From: "Tyler F. Carr" Date: Sat, 6 Apr 2024 17:39:17 +0000 Subject: [PATCH] added polar absorption sensor --- .../noaa_space_weather/sensor.py | 26 +++++++++++++++---- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/custom_components/noaa_space_weather/sensor.py b/custom_components/noaa_space_weather/sensor.py index 968288e..056f326 100644 --- a/custom_components/noaa_space_weather/sensor.py +++ b/custom_components/noaa_space_weather/sensor.py @@ -42,6 +42,10 @@ def m1_return(coordinator): if not coordinator.data.get("probabilities_data") is None: return coordinator.data.get("probabilities_data", [{}])[0].get("m_class_1_day") +def polar_cap_absorption_return(coordinator): + if not coordinator.data.get("probabilities_data") is None: + return coordinator.data.get("probabilities_data", [{}])[0].get("polar_cap_absorption") + async def async_setup_entry(hass, entry, async_add_devices): """Setup sensor platform.""" @@ -59,12 +63,12 @@ async def async_setup_entry(hass, entry, async_add_devices): }, { "name": "AI2D", - "desc": "2 Day A Index", + "desc": "A Index 2 Day", "data": ai_2d_return, }, { "name": "AI3D", - "desc": "3 Day A Index", + "desc": "A Index 3 Day", "data": ai_3d_return, }, { @@ -77,6 +81,14 @@ async def async_setup_entry(hass, entry, async_add_devices): "desc": "Sunspot Number", "data": ssn_return, }, + { + "name": "PolarCapAbsorption", + "desc": "Polar Cap Absorption", + "data": polar_cap_absorption_return, + "state_class": None, + "icon": "mdi:sign-pole", + "unit": None, + }, { "name": "x1", "icon": "mdi:sun-wireless", @@ -106,12 +118,16 @@ def __init__(self, coordinator, entry, sensor): @property def state_class(self): - return "measurement" + return self.sensor.get("state_class","measurement") @property def unit_of_measurement(self): return self.sensor.get('unit', '') + @property + def options(self): + return self.sensor.get('options', None) + @property def state(self): """Return the state of the sensor.""" @@ -147,5 +163,5 @@ def icon(self): @property def device_class(self): - """Return de device class of the sensor.""" - return "noaa_space_weather__custom_device_class" + """Return the device class of the sensor.""" + return self.sensor.get("device_class","noaa_space_weather__custom_device_class")