Skip to content

Commit

Permalink
feat: add const definition
Browse files Browse the repository at this point in the history
  • Loading branch information
tinymins committed Mar 19, 2024
1 parent 12ef3ba commit 8d6c9f8
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 17 deletions.
11 changes: 11 additions & 0 deletions custom_components/ups_over_network/config_flow.py
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
18 changes: 18 additions & 0 deletions custom_components/ups_over_network/const.py
Original file line number Diff line number Diff line change
@@ -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"],
}
23 changes: 6 additions & 17 deletions custom_components/ups_over_network/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

0 comments on commit 8d6c9f8

Please sign in to comment.