Description
Dear magico13,
I open a new issue because to comment an old one (#32) don't generate a notice, I think.
Using your example(s) I obtained correct results only with the one you shown results in the "readme.md" file.
I'm aware to need learnig on Python, Java and more other things, like a lot of people...
For a programmer like you it's easy and fast to complete coding of your examples, but a lot of us dont'know too much things.
During my training I made various trite errors, (syntax and others), after I founded Spyder, it's a great help to have a correct Python syntax.
Then, in the first example of readme.md file we obtain the list of instant data of all devices matched with our Emporia's account. It's correct, I have two devices and I obtain both's data. (Not always, and sometimes not all, I think it depend from the instant conection quality)
During last year I red a lot of news, forum etc on Emporia vue, like the Emporia's staff criticism on the enormous quantity of requests to them servers originated by your software, and it's normal, because if you need to obtain high resolution data you'll ask continuosly to servers...
So I'd like to ask only when I need, for example for a second resolution every less than three hours, because three hours are the limit of seconds interval on Emporia servers. (or three days for the minute, and so on).
It is the readme.md section I thought to use.
### Get usage over time
# ```python
vue = PyEmVue()
vue.login(id_token='id_token',
access_token='access_token',
refresh_token='refresh_token')
devices = vue.get_devices()
usage_over_time, start_time = vue.get_chart_usage(devices[0].channels[0], datetime.datetime.now(datetime.timezone.utc)-datetime.timedelta(days=7), datetime.datetime.now(datetime.timezone.utc), scale=Scale.DAY.value, unit=Unit.KWH.value)
print('Usage for the last seven days starting', start_time.isoformat())
for usage in usage_over_time:
print(usage, 'kwh')
# ```
Gets the usage in the scale and unit provided over the given time range. Returns a tuple with the first element the usage list and the second the datetime that the range starts.
#### Arguments
- **channel**: A VueDeviceChannel object, typically pulled from a VueDevice.
- **start**: The start time for the time period. Defaults to now if None.
- **end**: The end time for the time period. Default to now if None.
- **scale**: The time scale to check the usage over.
- **unit**: The unit of measurement.
It is the code I wrote the first time, adding the first two rows from the other code.
import pyemvue
from pyemvue.enums import Scale, Unit
### Get usage over time
# ```python
vue = pyemvue()
vue.login(id_token='id_token',
access_token='access_token',
refresh_token='refresh_token')
devices = vue.get_devices()
usage_over_time, start_time = vue.get_chart_usage(devices[0].channels[0], datetime.datetime.now(datetime.timezone.utc)-datetime.timedelta(days=7), datetime.datetime.now(datetime.timezone.utc), scale=Scale.DAY.value, unit=Unit.KWH.value)
print('Usage for the last seven days starting', start_time.isoformat())
for usage in usage_over_time:
print(usage, 'kwh')
# ```
# Gets the usage in the scale and unit provided over the given time range. Returns a tuple with the first element the usage list and the second the datetime that the range starts.
#### Arguments
# - **channel**: A VueDeviceChannel object, typically pulled from a VueDevice.
# - **start**: The start time for the time period. Defaults to now if None.
# - **end**: The end time for the time period. Default to now if None.
# - **scale**: The time scale to check the usage over.
# - **unit**: The unit of measurement.
Obtaining the next message on the console.
Traceback (most recent call last):
File "/home/ammi/PyEmVue-master/PyEmVue/PPyEmVue_27.py", line 15, in <module>
vue = pyemvue()
TypeError: 'module' object is not callable
It is the code I wrote the second time (replacing the "vue =" rows with the other proven for my account access).
import pyemvue
from pyemvue.enums import Scale, Unit
# Crea l'oggetto "vue" (?)
vue = pyemvue.PyEmVue()
vue.login(username='MIAMAIL', password='MIAPASSWORD', token_storage_file='keys=json')
#
### Get usage over time
## # ```python
## vue = pyemvue()
## vue.login(id_token='id_token',
## access_token='access_token',
## refresh_token='refresh_token')
devices = vue.get_devices()
usage_over_time, start_time = vue.get_chart_usage(devices[0].channels[0], datetime.datetime.now(datetime.timezone.utc)-datetime.timedelta(days=7), datetime.datetime.now(datetime.timezone.utc), scale=Scale.DAY.value, unit=Unit.KWH.value)
print('Usage for the last seven days starting', start_time.isoformat())
for usage in usage_over_time:
print(usage, 'kwh')
# ```
# Gets the usage in the scale and unit provided over the given time range. Returns a tuple with the first element the usage list and the second the datetime that the range starts.
#### Arguments
# - **channel**: A VueDeviceChannel object, typically pulled from a VueDevice.
# - **start**: The start time for the time period. Defaults to now if None.
# - **end**: The end time for the time period. Default to now if None.
# - **scale**: The time scale to check the usage over.
# - **unit**: The unit of measurement.
Obtaining the next message on the console.
Traceback (most recent call last):
File "/home/ammi/PyEmVue-master/PyEmVue/PPyEmVue_28.py", line 26, in <module>
usage_over_time, start_time = vue.get_chart_usage(devices[0].channels[0], datetime.datetime.now(datetime.timezone.utc)-datetime.timedelta(days=7), datetime.datetime.now(datetime.timezone.utc), scale=Scale.DAY.value, unit=Unit.KWH.value)
NameError: name 'datetime' is not defined
It is the code I wrote the third time (inserting datatime call).
import pyemvue
from pyemvue.enums import Scale, Unit
from datetime import datetime
# Crea l'oggetto "vue" (?)
vue = pyemvue.PyEmVue()
vue.login(username='MIAMAIL', password='MIAPASSWORD', token_storage_file='keys=json')
#
### Get usage over time
## # ```python
## vue = pyemvue()
## vue.login(id_token='id_token',
## access_token='access_token',
## refresh_token='refresh_token')
devices = vue.get_devices()
usage_over_time, start_time = vue.get_chart_usage(devices[0].channels[0], datetime.datetime.now(datetime.timezone.utc)-datetime.timedelta(days=7), datetime.datetime.now(datetime.timezone.utc), scale=Scale.DAY.value, unit=Unit.KWH.value)
print('Usage for the last seven days starting', start_time.isoformat())
for usage in usage_over_time:
print(usage, 'kwh')
# ```
# Gets the usage in the scale and unit provided over the given time range. Returns a tuple with the first element the usage list and the second the datetime that the range starts.
#### Arguments
# - **channel**: A VueDeviceChannel object, typically pulled from a VueDevice.
# - **start**: The start time for the time period. Defaults to now if None.
# - **end**: The end time for the time period. Default to now if None.
# - **scale**: The time scale to check the usage over.
# - **unit**: The unit of measurement.
Obtaining the next message on the console.
Traceback (most recent call last):
File "/home/ammi/PyEmVue-master/PyEmVue/PPyEmVue_28.py", line 26, in <module>
usage_over_time, start_time = vue.get_chart_usage(devices[0].channels[0], datetime.datetime.now(datetime.timezone.utc)-datetime.timedelta(days=7), datetime.datetime.now(datetime.timezone.utc), scale=Scale.DAY.value, unit=Unit.KWH.value)
AttributeError: type object 'datetime.datetime' has no attribute 'datetime'
Today, reading all other issues (open and not) I found the #42 code. Tried it and under the result
Here the issue #42 code
# Copied from magico13 + pyemvue #42 issue
from pyemvue.pyemvue import PyEmVue, Scale, Unit
import datetime
username='mymail'
password='mypsw'
vue = PyEmVue()
vue.login(username, password)
print('Logged in.')
print()
device_gids = []
devices = vue.get_devices()
for device in devices:
if not device.device_gid in device_gids: device_gids.append(device.device_gid)
now = datetime.datetime.now(datetime.timezone(datetime.timedelta(hours=-5))) # This is my timezone, yours may vary
usageDict = vue.get_device_list_usage(device_gids, now, Scale.SECOND.value, Unit.KWH.value)
for (gid, usageDevice) in usageDict.items():
for (channelNum, usageChannel) in usageDevice.channels.items():
# unit is kWh/s, multiply by 3600 seconds/hour to get kW, multiply by 1000 to get W
# if the usage is ever None this will throw an exception so you should check for that and replace it with 0
scaledUsage = 3600*1000*usageChannel.usage
print(f'{gid} - {channelNum} - {usageChannel.name} - {scaledUsage}W')
Obtaining the next message on the console.
Traceback (most recent call last):
File "/home/ammi/PyEmVue-master/PyEmVue/PPyEmVue_28.py", line 26, in <module>
usage_over_time, start_time = vue.get_chart_usage(devices[0].channels[0], datetime.datetime.now(datetime.timezone.utc)-datetime.timedelta(days=7), datetime.datetime.now(datetime.timezone.utc), scale=Scale.DAY.value, unit=Unit.KWH.value)
AttributeError: type object 'datetime.datetime' has no attribute 'datetime'
So I need to ask to you.
I think you could write some code rows more than actual readme file...
I hope it.