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 Pylint issues #355

Merged
merged 8 commits into from
Feb 18, 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
9 changes: 1 addition & 8 deletions .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
disable=
duplicate-code,
fixme,
format,
line-too-long,
invalid-name,
too-many-public-methods,
too-few-public-methods,
Expand All @@ -16,18 +16,11 @@ disable=
consider-merging-isinstance,
consider-using-dict-items,
consider-using-generator,
consider-using-in,
deprecated-decorator,
f-string-without-interpolation,
logging-fstring-interpolation,
logging-not-lazy,
missing-class-docstring,
missing-function-docstring,
missing-module-docstring,
missing-timeout,
no-else-raise,
no-else-return,
pointless-string-statement,
raise-missing-from,
super-init-not-called,
too-many-boolean-expressions,
Expand Down
13 changes: 5 additions & 8 deletions PyViCare/PyViCare.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@
logger = logging.getLogger('ViCare')
logger.addHandler(logging.NullHandler())

""""Viessmann ViCare API Python tools"""


class PyViCare:
""""Viessmann ViCare API Python tools"""
def __init__(self) -> None:
self.cacheDuration = 60

Expand All @@ -36,8 +35,7 @@
def __buildService(self, accessor, roles):
if self.cacheDuration > 0:
return ViCareCachedService(self.oauth_manager, accessor, roles, self.cacheDuration)
else:
return ViCareService(self.oauth_manager, accessor, roles)
return ViCareService(self.oauth_manager, accessor, roles)

def __loadInstallations(self):
installations = self.oauth_manager.get(
Expand All @@ -54,7 +52,7 @@
for installation in self.installations:
for gateway in installation.gateways:
for device in gateway.devices:
if device.deviceType != "heating" and device.deviceType != "zigbee" and device.deviceType != "vitoconnect" and device.deviceType != "electricityStorage" and device.deviceType != "EEBus" and device.deviceType != "hems" and device.deviceType != "tcu" and device.deviceType != "ventilation":
if device.deviceType not in ["heating", "zigbee", "vitoconnect", "electricityStorage", "EEBus", "hems", "tcu", "ventilation"]:
continue # we are only interested in heating, photovoltaic, electricityStorage, hems and ventilation devices

if device.id == "gateway" and device.deviceType == "vitoconnect":
Expand All @@ -67,13 +65,13 @@
device.id = "0" # hems has no device id, so we use 0

if device.id == "EEBUS" and device.deviceType == "EEBus":
device.id = "0" # EEBus has no device id,

Check failure on line 68 in PyViCare/PyViCare.py

View workflow job for this annotation

GitHub Actions / build (3.8)

E261 at least two spaces before inline comment

Check failure on line 68 in PyViCare/PyViCare.py

View workflow job for this annotation

GitHub Actions / build (3.9)

E261 at least two spaces before inline comment

accessor = ViCareDeviceAccessor(
installation.id, gateway.serial, device.id)
service = self.__buildService(accessor, device.roles)

logger.info(f"Device found: {device.modelId}")
logger.info("Device found: %s", device.modelId)

yield PyViCareDeviceConfig(service, device.id, device.modelId, device.status)

Expand All @@ -91,5 +89,4 @@
return DictWrap(v)
if isinstance(v, str) and len(v) == 24 and v[23] == 'Z' and v[10] == 'T':
return datetime.strptime(v, '%Y-%m-%dT%H:%M:%S.%f%z')
else:
return v
return v
29 changes: 14 additions & 15 deletions PyViCare/PyViCareAbstractOAuthManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def get(self, url: str) -> Any:
try:
logger.debug(self.__oauth)
response = self.__oauth.get(f"{API_BASE_URL}{url}", timeout=31).json()
logger.debug(f"Response to get request: {response}")
logger.debug("Response to get request: %s", response)
self.__handle_expired_token(response)
self.__handle_rate_limit(response)
self.__handle_server_error(response)
Expand Down Expand Up @@ -69,21 +69,20 @@ def __handle_command_error(self, response):
if ("statusCode" in response and response["statusCode"] >= 400):
raise PyViCareCommandError(response)

"""POST URL using OAuth session. Automatically renew the token if needed
Parameters
----------
url : str
URL to get
data : str
Data to post

Returns
-------
result: json
json representation of the answer
"""

def post(self, url, data) -> Any:
"""POST URL using OAuth session. Automatically renew the token if needed
Parameters
----------
url : str
URL to get
data : str
Data to post

Returns
-------
result: json
json representation of the answer
"""
headers = {"Content-Type": "application/json",
"Accept": "application/vnd.siren+json"}
try:
Expand Down
4 changes: 2 additions & 2 deletions PyViCare/PyViCareBrowserOAuthManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,14 @@ def handlerWithCallbackWrapper(*args):
logger.debug("Timeout reached")
raise PyViCareBrowserOAuthTimeoutReachedError()

logger.debug(f"Location: {location}")
logger.debug("Location: %s", location)

oauth_session.fetch_token(TOKEN_URL, authorization_response=location, code_verifier=code_verifier)

if oauth_session.token is None:
raise PyViCareInvalidCredentialsError()

logger.debug(f"Token received: {oauth_session.token}")
logger.debug("Token received: %s", oauth_session.token)
self.__storeToken(oauth_session.token)
logger.info("New token created")
return oauth_session
Expand Down
7 changes: 3 additions & 4 deletions PyViCare/PyViCareDeviceConfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def asRoomSensor(self):

def asElectricalEnergySystem(self):
return ElectricalEnergySystem(self.service)

def asGateway(self):
return Gateway(self.service)

Expand Down Expand Up @@ -94,11 +94,10 @@ def asAutoDetectDevice(self):

for (creator_method, type_name, roles) in device_types:
if re.search(type_name, self.device_model) or self.service.hasRoles(roles):
logger.info(f"detected {self.device_model} {creator_method.__name__}")
logger.info("detected %s %s", self.device_model, creator_method.__name__)
return creator_method()

logger.info(
f"Could not auto detect {self.device_model}. Use generic device.")
logger.info("Could not auto detect %s. Use generic device.", self.device_model)
return self.asGeneric()

def get_raw_json(self):
Expand Down
Loading
Loading