Skip to content

Commit

Permalink
snake_case (PEP 8) used for your namings. So mobilePlatform needs to …
Browse files Browse the repository at this point in the history
…be mobile_platform

cleanup const for unused secrete and comments
  • Loading branch information
myTselection committed Jan 30, 2025
1 parent 49404d5 commit 9d0a5c9
Show file tree
Hide file tree
Showing 11 changed files with 41 additions and 50 deletions.
4 changes: 2 additions & 2 deletions custom_components/mobile_vikings/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@


async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Set up MobileVikings from a config entry."""
"""Set up MobileVikings / JimMobile from a config entry."""
hass.data.setdefault(DOMAIN, {})[entry.entry_id] = {}

for platform in PLATFORMS:
hass.data[DOMAIN][entry.entry_id].setdefault(platform, set())

client = MobileVikingsClient(
hass=hass,
mobilePlatform=entry.data.get('mobilePlatform', MOBILE_VIKINGS), # Default to MOBILE_VIKINGS for backward compatibility
mobile_platform=entry.data.get('mobile_platform', MOBILE_VIKINGS), # Default to MOBILE_VIKINGS for backward compatibility
username=entry.data[CONF_USERNAME],
password=entry.data[CONF_PASSWORD],

Expand Down
6 changes: 3 additions & 3 deletions custom_components/mobile_vikings/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,16 +145,16 @@ async def async_setup_entry(
"coordinator"
]
entities: list[MobileVikingsBinarySensor] = []
mobilePlatform = coordinator.client.mobilePlatform
mobile_platform = coordinator.client.mobile_platform


for subscription_id, subscription_data in coordinator.data.get(
"subscriptions", []
).items():
# Add static sensors from SUBSCRIPTION_SENSOR_TYPES
for sensor_type in SUBSCRIPTION_SENSOR_TYPES:
if not sensor_type.mobile_platforms or mobilePlatform not in sensor_type.mobile_platforms:
_LOGGER.debug(f"Skipping {sensor_type.key}-{sensor_type.translation_key} for mobile platform {mobilePlatform}")
if not sensor_type.mobile_platforms or mobile_platform not in sensor_type.mobile_platforms:
_LOGGER.debug(f"Skipping {sensor_type.key}-{sensor_type.translation_key} for mobile platform {mobile_platform}")
continue
_LOGGER.debug(
f"Searching for {sensor_type.key}-{sensor_type.translation_key}"
Expand Down
24 changes: 12 additions & 12 deletions custom_components/mobile_vikings/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class AuthenticationError(Exception):
class MobileVikingsClient:
"""Asynchronous client for interacting with the Mobile Vikings API."""

def __init__(self, hass, username, password, mobilePlatform, tokens=None):
def __init__(self, hass, username, password, mobile_platform, tokens=None):
"""Initialize the MobileVikingsClient.
Parameters
Expand All @@ -41,7 +41,7 @@ def __init__(self, hass, username, password, mobilePlatform, tokens=None):
The username for authenticating with the Mobile Vikings API.
password : str
The password for authenticating with the Mobile Vikings API.
mobilePlatform : str
mobile_platform : str
The name of the mobile platform to connect to (Mobile Vikings or Jim Mobile).
tokens : dict, optional
A dictionary containing token information (refresh_token, access_token, expiry).
Expand All @@ -50,7 +50,7 @@ def __init__(self, hass, username, password, mobilePlatform, tokens=None):
self.hass = hass
self.username = username
self.password = password
self.mobilePlatform = mobilePlatform
self.mobile_platform = mobile_platform
self.refresh_token = None
self.access_token = None
self.expires_in = None
Expand All @@ -70,9 +70,9 @@ async def close(self):

async def authenticate(self):
"""Authenticate with the Mobile Vikings / JimMobile API."""
actualClientId = CLIENT_ID_JIMMOBILE if self.mobilePlatform == JIM_MOBILE else CLIENT_ID
actualClientSecretTag = CLIENT_SECRET_TAG_JIMMOBILE if self.mobilePlatform == JIM_MOBILE else CLIENT_SECRET_TAG
actualClientSecretValue = CLIENT_SECRET_VALUE_JIMMOBILE if self.mobilePlatform == JIM_MOBILE else CLIENT_SECRET
actual_client_id = CLIENT_ID_JIMMOBILE if self.mobile_platform == JIM_MOBILE else CLIENT_ID
actual_client_secret_tag = CLIENT_SECRET_TAG_JIMMOBILE if self.mobile_platform == JIM_MOBILE else CLIENT_SECRET_TAG
actual_client_secret_value = CLIENT_SECRET_VALUE_JIMMOBILE if self.mobile_platform == JIM_MOBILE else CLIENT_SECRET
if self._is_token_valid():
self.client.headers["Authorization"] = f"Bearer {self.access_token}"
else:
Expand All @@ -82,8 +82,8 @@ async def authenticate(self):
{
"refresh_token": self.refresh_token,
"grant_type": "refresh_token",
"client_id": actualClientId,
actualClientSecretTag: actualClientSecretValue,
"client_id": actual_client_id,
actual_client_secret_tag: actual_client_secret_value,
}
)
else:
Expand All @@ -93,8 +93,8 @@ async def authenticate(self):
"username": self.username,
"password": self.password,
"grant_type": "password",
"client_id": actualClientId,
actualClientSecretTag: actualClientSecretValue,
"client_id": actual_client_id,
actual_client_secret_tag: actual_client_secret_value,
}
)

Expand Down Expand Up @@ -154,7 +154,7 @@ async def handle_request(
if authenticate_request is False:
await self.authenticate()

if self.mobilePlatform == MOBILE_VIKINGS:
if self.mobile_platform == MOBILE_VIKINGS:
url = BASE_URL + endpoint
else:
url = BASE_URL_JIMMOBILE + endpoint
Expand Down Expand Up @@ -224,7 +224,7 @@ async def get_loyalty_points_balance(self):
dict or None: A dictionary containing loyalty points balance, or None if request fails.
"""
if self.mobilePlatform == JIM_MOBILE:
if self.mobile_platform == JIM_MOBILE:
# not existing for Jim Mobile
return {'error': 'not existing for Jim Mobile'}
return await self.handle_request("/loyalty-points/balance")
Expand Down
8 changes: 4 additions & 4 deletions custom_components/mobile_vikings/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
DEFAULT_ENTRY_DATA = MobileVikingsConfigEntryData(
username=None,
password=None,
mobilePlatform=None
mobile_platform=None
)


Expand Down Expand Up @@ -58,7 +58,7 @@ async def async_validate_input(self, user_input: dict[str, Any]) -> None:
hass=self.hass,
username=user_input[CONF_USERNAME],
password=user_input[CONF_PASSWORD],
mobilePlatform=user_input['mobilePlatform']
mobile_platform=user_input['mobile_platform']
)

profile = await client.get_customer_info()
Expand All @@ -77,7 +77,7 @@ async def async_step_connection_init(
if not test["errors"]:
self.new_title = user_input[CONF_USERNAME]
self.new_entry_data |= user_input
if user_input['mobilePlatform'] == JIM_MOBILE:
if user_input['mobile_platform'] == JIM_MOBILE:
await self.async_set_unique_id(f"{DOMAIN}_{JIM_MOBILE}_{user_input[CONF_USERNAME]}")
else:
await self.async_set_unique_id(f"{DOMAIN}_{user_input[CONF_USERNAME]}")
Expand All @@ -86,7 +86,7 @@ async def async_step_connection_init(
return self.finish_flow()
errors = test["errors"]
fields = {
vol.Required('mobilePlatform'): SelectSelector(
vol.Required('mobile_platform'): SelectSelector(
SelectSelectorConfig(
options=[MOBILE_VIKINGS, JIM_MOBILE],
mode=SelectSelectorMode.DROPDOWN
Expand Down
9 changes: 0 additions & 9 deletions custom_components/mobile_vikings/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,10 @@

CLIENT_SECRET_TAG = "client_secret"

Check notice

Code scanning / Bandit

Possible hardcoded password: 'client_secret' Note

Possible hardcoded password: 'client_secret'

# FPID2.2.MCaIbSP%2FL5s3sb2U72khFTgLJ68VabpnVuB6HzKd494%3D.1737890525
# A6c%2FYSmmzklFbQjSNVYlBYUW8yKw%2B2jtxx1ELlyjKIAGOMlgVy5gNfXIvQVFm5dnd071iUbocu3BG6SEl4i5PDGTLqkYqSwu%2FVWaZxAixWOEYMiHxfPmJuIjuF0izA%3D%3D
# client_id: f14262155486a64ebfba
# client_secret: 2e8e068c57a3cf799771b66ef96ab79d0ac1beed

CLIENT_SECRET_TAG_JIMMOBILE = "grant_type"

Check notice

Code scanning / Bandit

Possible hardcoded password: 'grant_type' Note

Possible hardcoded password: 'grant_type'
CLIENT_SECRET_VALUE_JIMMOBILE = "password"

Check notice

Code scanning / Bandit

Possible hardcoded password: 'password' Note

Possible hardcoded password: 'password'
# Client ID for OAuth2 authentication FPID2.2.RdkG7KHis21lWOa3dqN6USEXGLYXTisE7R9hgqY5sJY%3D.1737890466
CLIENT_ID_JIMMOBILE = "JIM"

# Client secret for OAuth2 authentication NLNZtPR68KdXyYQ1Ee1v3LtfMf447RHFtX4g9B0tAvArAYl04yGm4y3mTZbv2VbimrnLxVzwC%2BIp%2FZtgABI4NVIOpc7BmIKuLUW53ZzMYf1kAljzjzaLYu2D0uPDAg%3D%3D
CLIENT_SECRET_JIMMOBILE = "NZtPR68KdXyYQ1Ee1v3LtfMf447RHFtX4g9B0tAvArAYl04yGm4y3mTZbv2VbimrnLxVzwC%2BIp%2FZtgABI4NVIOpc7BmIKuLUW53ZzMYf1kAljzjzaLYu2D0uPDAg"

# Base URL for the Mobile Vikings API
BASE_URL = "https://uwa.mobilevikings.be/latest/mv"

Expand Down
6 changes: 3 additions & 3 deletions custom_components/mobile_vikings/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def __init__(
super().__init__(coordinator)
self.idx = idx
self.entity_description = description
self.mobilePlatform = coordinator.client.mobilePlatform
self.mobile_platform = coordinator.client.mobile_platform
self._identifier = f"{description.key}"
self._attr_device_info = DeviceInfo(
identifiers={
Expand All @@ -49,8 +49,8 @@ def __init__(
},
name=self.entity_description.device_name_fn(self.item),
translation_key=slugify(self.entity_description.device_name_fn(self.item)),
manufacturer=NAME if self.mobilePlatform == MOBILE_VIKINGS else JIM_MOBILE,
configuration_url=WEBSITE if self.mobilePlatform == MOBILE_VIKINGS else WEBSITE_JIMMOBILE,
manufacturer=NAME if self.mobile_platform == MOBILE_VIKINGS else JIM_MOBILE,
configuration_url=WEBSITE if self.mobile_platform == MOBILE_VIKINGS else WEBSITE_JIMMOBILE,
entry_type=DeviceEntryType.SERVICE,
model=self.entity_description.model_fn(self.item),
sw_version=VERSION,
Expand Down
2 changes: 1 addition & 1 deletion custom_components/mobile_vikings/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class MobileVikingsConfigEntryData(TypedDict):

username: str | None
password: str | None
mobilePlatform: str | None
mobile_platform: str | None


@dataclass
Expand Down
10 changes: 5 additions & 5 deletions custom_components/mobile_vikings/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -533,12 +533,12 @@ async def async_setup_entry(
]

entities: list[MobileVikingsSensor] = []
mobilePlatform = coordinator.client.mobilePlatform
mobile_platform = coordinator.client.mobile_platform

# Add static sensors from SENSOR_TYPES
for sensor_type in SENSOR_TYPES:
if mobilePlatform not in sensor_type.mobile_platforms:
_LOGGER.debug(f"Skipping {sensor_type.key}-{sensor_type.translation_key} for mobile platform {mobilePlatform}")
if mobile_platform not in sensor_type.mobile_platforms:
_LOGGER.debug(f"Skipping {sensor_type.key}-{sensor_type.translation_key} for mobile platform {mobile_platform}")
continue
_LOGGER.debug(f"Searching for {sensor_type.key}-{sensor_type.translation_key}")
if sensor_type.key in coordinator.data:
Expand All @@ -549,8 +549,8 @@ async def async_setup_entry(
).items():
# Add static sensors from SUBSCRIPTION_SENSOR_TYPES
for sensor_type in SUBSCRIPTION_SENSOR_TYPES:
if mobilePlatform not in sensor_type.mobile_platforms:
_LOGGER.debug(f"Skipping {sensor_type.key}-{sensor_type.translation_key} for mobile platform {mobilePlatform}")
if mobile_platform not in sensor_type.mobile_platforms:
_LOGGER.debug(f"Skipping {sensor_type.key}-{sensor_type.translation_key} for mobile platform {mobile_platform}")
continue
_LOGGER.debug(
f"Searching for {sensor_type.key}-{sensor_type.translation_key}"
Expand Down
8 changes: 4 additions & 4 deletions custom_components/mobile_vikings/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
"step": {
"connection_init": {
"data": {
"mobilePlatform": "Mobile platform",
"mobile_platform": "Mobile platform",
"password": "Password",
"username": "Username"
},
"description": "Set up your Mobile Vikings or JimMobile user account",
"title": "New Mobile Vikings / JimMobile account"
"description": "Set up your Mobile Vikings or Jim Mobile user account",
"title": "New Mobile Vikings or Jim Mobile account"
}
}
},
Expand Down Expand Up @@ -131,7 +131,7 @@
"data": {
"password": "Password"
},
"description": "To do when you changed your password on 'Mobile Vikings' / 'JimMobile'",
"description": "To use when you changed your password on 'Mobile Vikings' or 'Jim Mobile'",
"title": "Update your password"
}
}
Expand Down
8 changes: 4 additions & 4 deletions custom_components/mobile_vikings/translations/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
"step": {
"connection_init": {
"data": {
"mobilePlatform": "Platform mobile",
"mobile_platform": "Platform mobile",
"password": "Mot de passe",
"username": "Nom d'utilisateur"
},
"description": "Configurez votre compte utilisateur Mobile Vikings ou JimMobile",
"title": "Nouveau compte Mobile Vikings / JimMobile"
"description": "Configurez votre compte utilisateur Mobile Vikings ou Jim Mobile",
"title": "Nouveau compte Mobile Vikings ou Jim Mobile"
}
}
},
Expand Down Expand Up @@ -131,7 +131,7 @@
"data": {
"password": "Mot de passe"
},
"description": "\u00c0 faire lorsque vous avez modifi\u00e9 votre mot de passe sur 'Mobile Vikings' ou 'JimMobile'",
"description": "\u00c0 faire lorsque vous avez modifi\u00e9 votre mot de passe sur 'Mobile Vikings' ou 'Jim Mobile'",
"title": "Mettre \u00e0 jour votre mot de passe"
}
}
Expand Down
6 changes: 3 additions & 3 deletions custom_components/mobile_vikings/translations/nl.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
"step": {
"connection_init": {
"data": {
"mobilePlatform": "Mobiel platform",
"mobile_platform": "Mobiel platform",
"password": "Wachtwoord",
"username": "Gebruikersnaam"
},
"description": "Stel uw Mobile Vikings of JimMobile gebruikersaccount in",
"title": "Nieuw Mobile Vikings / JimMobile account"
"title": "Nieuw Mobile Vikings of JimMobile account"
}
}
},
Expand Down Expand Up @@ -131,7 +131,7 @@
"data": {
"password": "Wachtwoord"
},
"description": "Te doen wanneer u uw wachtwoord op 'Mobile Vikings' of 'JimMobile' heeft gewijzigd",
"description": "Te gebruiken wanneer u uw wachtwoord op 'Mobile Vikings' of 'Jim Mobile' heeft gewijzigd",
"title": "Werk uw wachtwoord bij"
}
}
Expand Down

0 comments on commit 9d0a5c9

Please sign in to comment.