-
-
Notifications
You must be signed in to change notification settings - Fork 101
introduce the Metric class #113
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
Conversation
🎉 HACS repository validator action summary 🎉 |
👉 View analysis in DeepCode’s Dashboard | Configure the bot👉 The DeepCode service and API will be deprecated in August, 2021. Here is the information how to migrate. Thank you for using DeepCode 🙏 ❤️ !If you are using our plugins, you might be interested in their successors: Snyk's JetBrains plugin and Snyk's VS Code plugin. |
@lbbrhzn , sorry I appear to have made a mistake trying to merge your metrics_class into my repo for testing. Are you able to revert this as I can't seem to? |
yes. I did:
|
custom_components/ocpp/api.py
Outdated
@@ -793,23 +796,27 @@ def on_meter_values(self, connector_id: int, meter_value: Dict, **kwargs): | |||
processed_keys = [] | |||
for idx, sv in enumerate(bucket[om.sampled_value.name]): | |||
if m in sv and om.phase.value not in sv: | |||
self._metrics[sv[m]] = round(float(sv[om.value.value]), 1) | |||
self._metrics[sv[m]].value = round(float(sv[om.value.value]), 1) | |||
if om.unit.value in sv: | |||
if sv[om.unit.value] == DEFAULT_POWER_UNIT: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not as a result of your changes but in reviewing I've noticed there should be a line here to set the units:
self._metrics[sv[m]].unit = sv[om.unit.value]
Directly after the statement if om.unit.value in sv:
that is...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, I'll add that
@@ -167,27 +168,30 @@ async def on_connect(self, websocket, path: str): | |||
cp = self.charge_points[self.cpid] | |||
await self.charge_points[self.cpid].reconnect(websocket) | |||
except Exception as e: | |||
_LOGGER.info(f"Exception occurred:\n{e}") | |||
_LOGGER.error(f"Exception occurred:\n{e}", exc_info=True) | |||
|
|||
finally: | |||
self.charge_points[self.cpid].status = STATE_UNAVAILABLE | |||
_LOGGER.info(f"Charger {cp_id} disconnected from {self.host}:{self.port}.") | |||
|
|||
def get_metric(self, cp_id: str, measurand: str): | |||
"""Return last known value for given measurand.""" | |||
if cp_id in self.charge_points: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this need and (measurand in self.charge_points[cp_id]._metrics)
as per lines 191-193?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No. I've made _metrics a defaultdict
. As a result, any metric that is not (yet) defined will have default values (None)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Useful to know as I was having lots of issues with missing dictionary values.
Does that also mean and (measurand in self.charge_points[cp_id]._metrics)
can be removed from lines 191-193?
finally: | ||
self.charge_points[self.cpid].status = STATE_UNAVAILABLE | ||
_LOGGER.info(f"Charger {cp_id} disconnected from {self.host}:{self.port}.") | ||
|
||
def get_metric(self, cp_id: str, measurand: str): | ||
"""Return last known value for given measurand.""" | ||
if cp_id in self.charge_points: | ||
return self.charge_points[cp_id].get_metric(measurand) | ||
return self.charge_points[cp_id]._metrics[measurand].value | ||
return None | ||
|
||
def get_unit(self, cp_id: str, measurand: str): | ||
"""Return unit of given measurand.""" | ||
if cp_id in self.charge_points: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As per comment above
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No. I've made metrics a defaultdict
. As a result, any metric that is not (yet) defined will have default values (None)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good!
No description provided.