Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: do not change name entry from config flow #71

Merged
merged 4 commits into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
name: Validate
steps:
- name: 📥 Checkout the repository
uses: actions/checkout@v3.5.3
uses: actions/checkout@v4

- name: HACS validation
uses: "hacs/action@main"
Expand All @@ -27,9 +27,9 @@ jobs:
name: Check style formatting
steps:
- name: 📥 Checkout the repository
uses: actions/checkout@v3.5.3
uses: actions/checkout@v4
- name: 🛠️ Set up Python
uses: actions/setup-python@v4.6.1
uses: actions/setup-python@v5
with:
python-version: "3.x"
- run: python3 -m pip install black
Expand All @@ -45,13 +45,13 @@ jobs:

steps:
- name: 📥 Checkout the repository
uses: actions/checkout@v3.5.3
uses: actions/checkout@v4
- name: 🛠️ Set up Python
uses: actions/setup-python@v4.6.1
uses: actions/setup-python@v5
with:
fetch-depth: 2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4.6.1
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: 📦 Install requirements
Expand All @@ -60,7 +60,7 @@ jobs:
- name: 🏃 Test with tox
run: tox
- name: 📤 Upload coverage to Codecov
uses: "actions/upload-artifact@v2.2.4"
uses: "actions/upload-artifact@v4"
with:
name: coverage-data
path: "coverage.xml"
Expand All @@ -70,14 +70,14 @@ jobs:
needs: tests
steps:
- name: 📥 Checkout the repository
uses: actions/checkout@v3.5.3
uses: actions/checkout@v4
with:
fetch-depth: 2
- name: 📥 Download coverage data
uses: actions/download-artifact@v3.0.2
uses: actions/download-artifact@v4
with:
name: coverage-data
- name: 📤 Upload coverage report
uses: codecov/codecov-action@v3.1.1
uses: codecov/codecov-action@v4
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
4 changes: 0 additions & 4 deletions custom_components/gasbuddy/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
from homeassistant import config_entries
from homeassistant.core import callback
from homeassistant.data_entry_flow import FlowResult
from homeassistant.util import slugify

from .const import (
CONF_INTERVAL,
Expand Down Expand Up @@ -189,7 +188,6 @@ async def async_step_manual(self, user_input=None):
self._errors = {}

if user_input is not None:
user_input[CONF_NAME] = slugify(user_input[CONF_NAME].lower())
user_input[CONF_INTERVAL] = 3600
user_input[CONF_UOM] = True
validate = await validate_station(user_input[CONF_STATION_ID])
Expand Down Expand Up @@ -229,7 +227,6 @@ async def async_step_home(self, user_input=None):
self._errors = {}

if user_input is not None:
user_input[CONF_NAME] = slugify(user_input[CONF_NAME].lower())
user_input[CONF_INTERVAL] = 3600
user_input[CONF_UOM] = True
self._data.update(user_input)
Expand Down Expand Up @@ -273,7 +270,6 @@ async def async_step_station_list(self, user_input=None):
self._errors = {}

if user_input is not None:
user_input[CONF_NAME] = slugify(user_input[CONF_NAME].lower())
user_input[CONF_INTERVAL] = 3600
user_input[CONF_UOM] = True
self._data.pop(CONF_POSTAL)
Expand Down
6 changes: 4 additions & 2 deletions custom_components/gasbuddy/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import ATTR_ATTRIBUTION, ATTR_LATITUDE, ATTR_LONGITUDE
from homeassistant.helpers.update_coordinator import CoordinatorEntity
from homeassistant.util import slugify

from .const import (
CONF_NAME,
Expand Down Expand Up @@ -57,8 +58,9 @@ def __init__(
self._state = None
self._icon = sensor_description.icon
self._cash = sensor_description.cash

self._attr_name = f"{self._config.data[CONF_NAME]} {self._name}"
self._attr_name = (
f"{slugify(self._config.data[CONF_NAME]).lower()} {self._name}"
)
self._attr_unique_id = f"{self._name}_{self._unique_id}"

@property
Expand Down
12 changes: 6 additions & 6 deletions tests/test_config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@
CONF_STATION_ID: "208656",
},
"user",
"gas_station",
DEFAULT_NAME,
{
CONF_NAME: "gas_station",
CONF_NAME: DEFAULT_NAME,
CONF_STATION_ID: "208656",
CONF_INTERVAL: 3600,
CONF_UOM: True,
Expand Down Expand Up @@ -99,9 +99,9 @@ async def test_form_home(
CONF_STATION_ID: "208656",
CONF_NAME: DEFAULT_NAME,
},
"gas_station",
DEFAULT_NAME,
{
CONF_NAME: "gas_station",
CONF_NAME: DEFAULT_NAME,
CONF_STATION_ID: "208656",
CONF_INTERVAL: 3600,
CONF_UOM: True,
Expand Down Expand Up @@ -173,9 +173,9 @@ async def test_form_postal(
CONF_STATION_ID: "208656",
},
"user",
"gas_station",
DEFAULT_NAME,
{
CONF_NAME: "gas_station",
CONF_NAME: DEFAULT_NAME,
CONF_STATION_ID: "208656",
CONF_INTERVAL: 3600,
CONF_UOM: True,
Expand Down
Loading