Repository navigation
Replies: 3 comments 1 reply
|
I now asked Claude which adjustments need to be made accordingly in all other files of the project especially in : init.py, const.py, config.json, config_flow.py, stellantis.py and eventually en.json Claude AI response :
# before
from .otp.otp import Otp, save_otp, load_otp, ConfigException
# after
from .otp.otp import Otp, save_otp_session, load_otp_session, ConfigException
def new_otp(self, sms_code, pin_code):
try:
self.otp = Otp("bb8e981582b0f31353108fb020bead1c", device_id=str(self.get_config("oauth")["access_token"][:16]))
self.otp.sms_code = sms_code # was: self.otp.smsCode
self.otp.pin_code = pin_code # was: self.otp.codepin
if self.otp.activation_start():
finalyze = self.otp.activation_finalyze()
if finalyze != 0:
raise Exception(finalyze)
except Exception as e:
_LOGGER.error(str(e))
raise Exception(str(e))
self.otp = await self._hass.async_add_executor_job(load_otp_session, otp_file_path)
await self._hass.async_add_executor_job(save_otp_session, self.otp, otp_file_path)
As I reply yes, following response :
# Check if OTP object is already loaded, if not load it
if self.otp is None:
if not os.path.isfile(otp_file_path):
_LOGGER.error(f"Error: OTP file '{otp_file_path}' not found, please reauthenticate")
_LOGGER.debug("---------- END get_otp_code")
raise ConfigEntryAuthFailed("OTP file not found, please reauthenticate")
self.otp = await self._hass.async_add_executor_job(load_otp_session, otp_file_path)
if self.otp is None:
_LOGGER.error(f"Error: OTP file '{otp_file_path}' could not be loaded, please reauthenticate")
_LOGGER.debug("---------- END get_otp_code")
raise ConfigEntryAuthFailed("OTP file could not be loaded, please reauthenticate")
And the corresponding opt.py new updated file consecutively ;) |
|
And as I do not like (at all), in opt.py, the class name "0tp" (starting with a digit and obscur link with otp), Claude propose me to rename the class "Inwebo", what I accepted. Following Claude response :
# import line (~24)
from .otp.otp import Inwebo, save_otp_session, load_otp_session, ConfigException
# ~351 in new_otp
self.otp = Inwebo("bb8e981582b0f31353108fb020bead1c", device_id=str(self.get_config("oauth")["access_token"][:16]))
And the corresponding provided otp.py updated file: EDIT : Option to eventualy rename the class Inwebo to "InweboOTP" or "Inwebo_otp", as desired or prefered, easy to manage 😉 |
|
I have just committed your changes and added further docstrings to the classes and methods in the OTP modules to explain their functionality and usage (assisted by AI). However, I haven't tested the code yet; I might find time for that over the weekend. |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Following @MoellerDi suggestion I moved here this thread
I tried to have a look at the opt code present in the integration, but with no comments and ugly naming, I quickly gave up.☹️
I however asked Claude AI to do a reverse engineering of the code, comment it, and rename variables, methods, symbols to make it more readable (at least for me...)
I'm not expert enough to be able to check all the response and potential consequences, more specifically last paragraph, and to suggest a PR with that, but perhaps somebody could do and/or give his opinion 😉
May be also, such a work could be done with other modules of the integration 😉
Following Claude AI response with a proposed new version of the 3 python files 😀
load.py
otp.py
tokenizer.py
As I forgot the fourth python file of the otp folder I asked Claude to process it as well
Claude AI response :
and the provided updated file :
oaep.py
All reactions