diff --git a/custom_components/ups_over_network/config_flow.py b/custom_components/ups_over_network/config_flow.py index c701271..0763ccc 100644 --- a/custom_components/ups_over_network/config_flow.py +++ b/custom_components/ups_over_network/config_flow.py @@ -1,5 +1,16 @@ import voluptuous as vol +from datetime import timedelta +from homeassistant.const import ( + CONF_HOST, + CONF_ID, + CONF_NAME, + CONF_PORT, + CONF_PROTOCOL, + CONF_RESOURCES, + CONF_SCAN_INTERVAL +) from homeassistant.helpers import config_validation as cv +from .const import SENSOR_DEFINITIONS PLATFORM_SCHEMA = vol.Schema({ vol.Required(CONF_HOST): cv.string, diff --git a/custom_components/ups_over_network/const.py b/custom_components/ups_over_network/const.py new file mode 100644 index 0000000..69c28ff --- /dev/null +++ b/custom_components/ups_over_network/const.py @@ -0,0 +1,18 @@ +from homeassistant.const import ( + ELECTRIC_POTENTIAL_VOLT, + FREQUENCY_HERTZ, + TEMP_CELSIUS, + PERCENTAGE +) + +# Define sensor types and units +SENSOR_DEFINITIONS = { + "raw": ["Raw", "", "mdi:text-box-outline"], + "input_voltage": ["Input Voltage", ELECTRIC_POTENTIAL_VOLT, "mdi:flash"], + "fault_voltage": ["Fault Voltage", ELECTRIC_POTENTIAL_VOLT, "mdi:flash-off"], + "output_voltage": ["Output Voltage", ELECTRIC_POTENTIAL_VOLT, "mdi:flash"], + "load": ["Load", PERCENTAGE, "mdi:gauge"], + "frequency": ["Frequency", FREQUENCY_HERTZ, "mdi:current-ac"], + "battery_voltage": ["Battery Voltage", ELECTRIC_POTENTIAL_VOLT, "mdi:battery"], + "temperature": ["Temperature", TEMP_CELSIUS, "mdi:thermometer"], +} diff --git a/custom_components/ups_over_network/sensor.py b/custom_components/ups_over_network/sensor.py index 16e80a8..f92dd76 100644 --- a/custom_components/ups_over_network/sensor.py +++ b/custom_components/ups_over_network/sensor.py @@ -14,29 +14,18 @@ CONF_PORT, CONF_PROTOCOL, CONF_RESOURCES, - CONF_SCAN_INTERVAL, - ELECTRIC_POTENTIAL_VOLT, - FREQUENCY_HERTZ, - TEMP_CELSIUS, - PERCENTAGE + CONF_SCAN_INTERVAL ) +from .const import SENSOR_DEFINITIONS +from .config_flow import PLATFORM_SCHEMA _LOGGER = logging.getLogger(__name__) -# Define sensor types and units -SENSOR_DEFINITIONS = { - "raw": ["Raw", "", "mdi:text-box-outline"], - "input_voltage": ["Input Voltage", ELECTRIC_POTENTIAL_VOLT, "mdi:flash"], - "fault_voltage": ["Fault Voltage", ELECTRIC_POTENTIAL_VOLT, "mdi:flash-off"], - "output_voltage": ["Output Voltage", ELECTRIC_POTENTIAL_VOLT, "mdi:flash"], - "load": ["Load", PERCENTAGE, "mdi:gauge"], - "frequency": ["Frequency", FREQUENCY_HERTZ, "mdi:current-ac"], - "battery_voltage": ["Battery Voltage", ELECTRIC_POTENTIAL_VOLT, "mdi:battery"], - "temperature": ["Temperature", TEMP_CELSIUS, "mdi:thermometer"], -} - async def async_setup_platform(hass, config, async_add_entities, discovery_info=None): """Set up the UPS sensor.""" + # Explicitly validate the configuration against the PLATFORM_SCHEMA + config = PLATFORM_SCHEMA(config) + ups_id = config[CONF_ID] ups_name = config[CONF_NAME] ups_host = config[CONF_HOST]