Skip to content

Commit

Permalink
Merge pull request #2 from jaroschek/feature/coding-style
Browse files Browse the repository at this point in the history
Fix coding style warnings by re-organizing imports and more
  • Loading branch information
jaroschek authored Jan 19, 2024
2 parents 17bc7c4 + 4e33582 commit fe13848
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 29 deletions.
22 changes: 11 additions & 11 deletions custom_components/eaton_epdu/api.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
"""API for Eaton ePDU."""
from __future__ import annotations

from homeassistant.config_entries import ConfigEntry

from pysnmp import hlapi

from homeassistant.config_entries import ConfigEntry

from .const import (
ATTR_HOST,
ATTR_PORT,
ATTR_VERSION,
ATTR_COMMUNITY,
ATTR_USERNAME,
ATTR_AUTH_KEY,
ATTR_AUTH_PROTOCOL,
ATTR_COMMUNITY,
ATTR_HOST,
ATTR_PORT,
ATTR_PRIV_KEY,
ATTR_PRIV_PROTOCOL,
ATTR_USERNAME,
ATTR_VERSION,
SNMP_PORT_DEFAULT,
AuthProtocol,
PrivProtocol,
Expand Down Expand Up @@ -47,7 +47,7 @@ class SnmpApi:
"""Provide an api for Eaton ePDU."""

def __init__(self, entry: ConfigEntry) -> None:
"""Init the SnmpApi"""
"""Init the SnmpApi."""
self._target = hlapi.UdpTransportTarget(
(
entry.data.get(ATTR_HOST),
Expand Down Expand Up @@ -118,7 +118,7 @@ def get_bulk_auto(

@staticmethod
def cast(value):
"""Cast returned value into correct type"""
"""Cast returned value into correct type."""
try:
return int(value)
except (ValueError, TypeError):
Expand All @@ -135,7 +135,7 @@ def cast(value):
def fetch(iterator, count) -> list:
"""Fetch data from iterator."""
result = []
for i in range(count):
for _i in range(count):
try:
error_indication, error_status, error_index, var_binds = next(iterator)
if not error_indication and not error_status:
Expand All @@ -145,7 +145,7 @@ def fetch(iterator, count) -> list:
result.append(items)
else:
raise RuntimeError(
"Got SNMP error: {0} {1} {2}".format(
"Got SNMP error: {} {} {}".format(
error_indication, error_status, error_index
)
)
Expand Down
24 changes: 12 additions & 12 deletions custom_components/eaton_epdu/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,20 @@
SelectSelectorConfig,
SelectSelectorMode,
)

from homeassistant.helpers.typing import ConfigType

from .const import (
DOMAIN,
ATTR_NAME,
ATTR_HOST,
ATTR_PORT,
ATTR_VERSION,
ATTR_COMMUNITY,
ATTR_USERNAME,
ATTR_AUTH_KEY,
ATTR_AUTH_PROTOCOL,
ATTR_COMMUNITY,
ATTR_HOST,
ATTR_NAME,
ATTR_PORT,
ATTR_PRIV_KEY,
ATTR_PRIV_PROTOCOL,
ATTR_USERNAME,
ATTR_VERSION,
DOMAIN,
SNMP_PORT_DEFAULT,
AuthProtocol,
PrivProtocol,
Expand All @@ -37,7 +37,7 @@


def get_host_schema_config(data: ConfigType) -> Schema:
"""Return the host schema for config flow"""
"""Return the host schema for config flow."""
return vol.Schema(
{
vol.Required(ATTR_NAME, default=data.get(ATTR_NAME)): cv.string,
Expand All @@ -58,7 +58,7 @@ def get_host_schema_config(data: ConfigType) -> Schema:


def get_host_schema_options(data: ConfigType) -> Schema:
"""Return the host schema for options flow"""
"""Return the host schema for options flow."""
return vol.Schema(
{
vol.Required(ATTR_HOST, default=data.get(ATTR_HOST)): cv.string,
Expand All @@ -78,7 +78,7 @@ def get_host_schema_options(data: ConfigType) -> Schema:


def get_v1_schema(data: ConfigType) -> Schema:
"""Return the v1 schema"""
"""Return the v1 schema."""
return vol.Schema(
{
vol.Required(ATTR_COMMUNITY, default=data.get(ATTR_COMMUNITY)): cv.string,
Expand All @@ -87,7 +87,7 @@ def get_v1_schema(data: ConfigType) -> Schema:


def get_v3_schema(data: ConfigType) -> Schema:
"""Return the v3 schema"""
"""Return the v3 schema."""
return vol.Schema(
{
vol.Required(ATTR_USERNAME, default=data.get(ATTR_USERNAME)): cv.string,
Expand Down
4 changes: 2 additions & 2 deletions custom_components/eaton_epdu/entity.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Definition of base Eaton ePDU Entity"""
"""Definition of base Eaton ePDU Entity."""
from __future__ import annotations

from homeassistant.helpers.entity import DeviceInfo
Expand All @@ -25,7 +25,7 @@ def __init__(self, coordinator: SnmpCoordinator, unit: str) -> None:
self._unit = unit

def get_unit_data(self, oid: str, default=None):
"""Wrapper to fetch data from coordinator for current unit"""
"""Fetch data from coordinator for current unit."""
return self.coordinator.data.get(oid.replace("unit", self._unit), default)

@property
Expand Down
4 changes: 1 addition & 3 deletions custom_components/eaton_epdu/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
from homeassistant.const import (
UnitOfElectricCurrent,
UnitOfElectricPotential,
UnitOfPower,
UnitOfEnergy,
UnitOfPower,
)
from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers.entity_platform import AddEntitiesCallback
Expand All @@ -33,7 +33,6 @@
SNMP_OID_UNITS_OUTLET_COUNT,
SNMP_OID_UNITS_SERIAL_NUMBER,
)

from .coordinator import SnmpCoordinator
from .entity import SnmpEntity

Expand All @@ -50,7 +49,6 @@ async def async_setup_entry(
entities: list[SensorEntity] = []

for unit in coordinator.get_units():

for index in range(
1,
coordinator.data.get(SNMP_OID_UNITS_INPUT_COUNT.replace("unit", unit), 0)
Expand Down
2 changes: 1 addition & 1 deletion custom_components/eaton_epdu/strings.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"config": {
"step": {
"user": {
"host": {
"data": {
"host": "[%key:common::config_flow::data::host%]",
"username": "[%key:common::config_flow::data::username%]",
Expand Down

0 comments on commit fe13848

Please sign in to comment.