Skip to content

Commit

Permalink
Fixing spelling in code
Browse files Browse the repository at this point in the history
  • Loading branch information
dala318 committed Sep 25, 2024
1 parent 28ddcc6 commit 958c56a
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 32 deletions.
46 changes: 22 additions & 24 deletions custom_components/nordpool_planner/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
CONF_ACCEPT_RATE_ENTITY,
CONF_DURATION_ENTITY,
CONF_END_TIME_ENTITY,
CONF_HIGH_COST_ENTITY,
CONF_LOW_COST_ENTITY,
CONF_NP_ENTITY,
CONF_SEARCH_LENGTH_ENTITY,
CONF_TYPE,
Expand Down Expand Up @@ -76,11 +74,11 @@ def __init__(self, hass: HomeAssistant, config_entry: ConfigEntry) -> None:
"""Initialize my coordinator."""
self._hass = hass
self._config = config_entry
self._state_change_listners = []
self._state_change_listeners = []

# Input entities
self._np_entity = NordpoolEntity(self._config.data[CONF_NP_ENTITY])
self._state_change_listners.append(
self._state_change_listeners.append(
async_track_state_change_event(
self._hass,
[self._np_entity.unique_id],
Expand All @@ -97,7 +95,7 @@ def __init__(self, hass: HomeAssistant, config_entry: ConfigEntry) -> None:
# TODO: Make dictionary?

# Output entities
self._output_listners = {}
self._output_listeners = {}

# Output states
self.low_cost_state = NordpoolPlannerState()
Expand Down Expand Up @@ -146,8 +144,8 @@ def _accept_rate(self) -> float:
return self.get_number_entity_value(self._accept_rate_number_entity)

def cleanup(self):
"""Clenaup by removing event listners."""
for lister in self._state_change_listners:
"""Cleanup by removing event listeners."""
for lister in self._state_change_listeners:
lister()

def get_number_entity_value(
Expand Down Expand Up @@ -193,28 +191,28 @@ def register_input_entity_id(self, entity_id, conf_key) -> None:
self._end_time_number_entity = entity_id
else:
_LOGGER.warning(
'An entity "%s" was registred for callback but no match for key "%s"',
'An entity "%s" was registered for callback but no match for key "%s"',
entity_id,
conf_key,
)
self._state_change_listners.append(
self._state_change_listeners.append(
async_track_state_change_event(
self._hass,
[entity_id],
self._async_input_changed,
)
)

def register_output_listner_entity(self, entity, conf_key="") -> None:
def register_output_listener_entity(self, entity, conf_key="") -> None:
"""Register output entity."""
if self._output_listners.get(conf_key):
if self._output_listeners.get(conf_key):
_LOGGER.warning(
'An output listner with key "%s" and unique id "%s" is overriding previous entity "%s"',
'An output listener with key "%s" and unique id "%s" is overriding previous entity "%s"',
conf_key,
self._output_listners.get(conf_key).entity_id,
self._output_listeners.get(conf_key).entity_id,
entity.entity_id,
)
self._output_listners[conf_key] = entity
self._output_listeners[conf_key] = entity

def get_device_info(self) -> DeviceInfo:
"""Get device info to group entities."""
Expand All @@ -226,7 +224,7 @@ def get_device_info(self) -> DeviceInfo:
)

def input_changed(self, value):
"""Input entitiy callback to initiate a planner update."""
"""Input entity callback to initiate a planner update."""
_LOGGER.debug("Sensor change event from callback: %s", value)
self.update()

Expand Down Expand Up @@ -348,8 +346,8 @@ def set_lowest_cost_state(self, prices_group: NordpoolPricesGroup) -> None:
else:
self.low_cost_state.now_cost_rate = STATE_UNAVAILABLE
_LOGGER.debug("Wrote lowest cost state: %s", self.low_cost_state)
for listner in self._output_listners.values():
listner.update_callback()
for listener in self._output_listeners.values():
listener.update_callback()

def set_highest_cost_state(self, prices_group: NordpoolPricesGroup) -> None:
"""Set the state to output variable."""
Expand All @@ -362,8 +360,8 @@ def set_highest_cost_state(self, prices_group: NordpoolPricesGroup) -> None:
else:
self.low_cost_state.now_cost_rate = STATE_UNAVAILABLE
_LOGGER.debug("Wrote highest cost state: %s", self.high_cost_state)
for listner in self._output_listners.values():
listner.update_callback()
for listener in self._output_listeners.values():
listener.update_callback()

def set_unavailable(self) -> None:
"""Set output state to unavailable."""
Expand All @@ -374,12 +372,12 @@ def set_unavailable(self) -> None:
self.high_cost_state.cost_at = STATE_UNAVAILABLE
self.high_cost_state.now_cost_rate = STATE_UNAVAILABLE
_LOGGER.debug("Setting output states to unavailable")
for listner in self._output_listners.values():
listner.update_callback()
for listener in self._output_listeners.values():
listener.update_callback()


class NordpoolEntity:
"""Represenatation for Nordpool state."""
"""Representation for Nordpool state."""

def __init__(self, unique_id: str) -> None:
"""Initialize state tracker."""
Expand Down Expand Up @@ -433,7 +431,7 @@ def update(self, hass: HomeAssistant) -> bool:
)
else:
_LOGGER.debug(
"Nordpool sensor %s was updated sucsessfully", self._unique_id
"Nordpool sensor %s was updated successfully", self._unique_id
)
if self._np is None:
pass
Expand All @@ -446,7 +444,7 @@ def update(self, hass: HomeAssistant) -> bool:
def get_prices_group(
self, start: dt.datetime, end: dt.datetime
) -> NordpoolPricesGroup:
"""Get a range of prices from NP given the start and end datatimes.
"""Get a range of prices from NP given the start and end datetimes.
Ex. If start is 7:05 and end 10:05, a list of 4 prices will be returned,
7, 8, 9 & 10.
Expand Down
2 changes: 1 addition & 1 deletion custom_components/nordpool_planner/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def extra_state_attributes(self):
async def async_added_to_hass(self) -> None:
"""Load the last known state when added to hass."""
await super().async_added_to_hass()
self._planner.register_output_listner_entity(self, self.entity_description.key)
self._planner.register_output_listener_entity(self, self.entity_description.key)

def update_callback(self) -> None:
"""Call from planner that new data avaialble."""
Expand Down
6 changes: 3 additions & 3 deletions custom_components/nordpool_planner/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from .const import (
CONF_ACCEPT_COST_ENTITY,
CONF_ACCEPT_RATE_ENTITY,
CONF_CURENCY,
CONF_CURRENCY,
CONF_DURATION_ENTITY,
CONF_END_TIME_ENTITY,
CONF_HIGH_COST_ENTITY,
Expand Down Expand Up @@ -60,7 +60,7 @@ async def async_step_user(
self.options = {}
np_entity = self.hass.states.get(self.data[CONF_NP_ENTITY])
try:
self.options[CONF_CURENCY] = np_entity.attributes.get(CONF_CURENCY)
self.options[CONF_CURRENCY] = np_entity.attributes.get(CONF_CURRENCY)
except (IndexError, KeyError):
_LOGGER.warning("Could not extract currency from Nordpool entity")

Expand All @@ -84,7 +84,7 @@ async def async_step_user(

sensor_entities = self.hass.states.async_entity_ids(domain_filter="sensor")
selected_entities = [s for s in sensor_entities if "nordpool" in s]
# TODO: Enable usage for e-ENTSO prices integration
# TODO: Enable usage for ENTSO-E prices integration
# selected_entities += [
# s for s in sensor_entities if "current_electricity_market_price" in s
# ]
Expand Down
2 changes: 1 addition & 1 deletion custom_components/nordpool_planner/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@
# CONF_END_TIME = "end_time"
CONF_END_TIME_ENTITY = "end_time_entity"

CONF_CURENCY = "currency"
CONF_CURRENCY = "currency"
4 changes: 2 additions & 2 deletions custom_components/nordpool_planner/number.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
NordpoolPlanner,
NordpoolPlannerEntity,
)
from .const import CONF_CURENCY, DOMAIN
from .const import CONF_CURRENCY, DOMAIN

_LOGGER = logging.getLogger(__name__)

Expand Down Expand Up @@ -87,7 +87,7 @@ async def async_setup_entry(
if config_entry.data.get(CONF_ACCEPT_COST_ENTITY):
entity_description = ACCEPT_COST_ENTITY_DESCRIPTION
# Override if currency option is set
if currency := config_entry.options.get(CONF_CURENCY):
if currency := config_entry.options.get(CONF_CURRENCY):
entity_description = NumberEntityDescription(
key=ACCEPT_COST_ENTITY_DESCRIPTION.key,
device_class=ACCEPT_COST_ENTITY_DESCRIPTION.device_class,
Expand Down
2 changes: 1 addition & 1 deletion custom_components/nordpool_planner/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def native_value(self):
async def async_added_to_hass(self) -> None:
"""Load the last known state when added to hass."""
await super().async_added_to_hass()
self._planner.register_output_listner_entity(self, self.entity_description.key)
self._planner.register_output_listener_entity(self, self.entity_description.key)

def update_callback(self) -> None:
"""Call from planner that new data avaialble."""
Expand Down

0 comments on commit 958c56a

Please sign in to comment.