jrester / tesla_powerwall

Python API for Tesla Powerwall
MIT License
73 stars 24 forks source link

Latest update seems to have broken meters #32

Closed Panda88CO closed 2 years ago

Panda88CO commented 2 years ago

I had in my code self.meters = self.TPWlocal.get_meters() solarPwr = self.meters.solar.instant_power

I get 'MetersAggregates' object has no attribute 'solar'

How to fix it ?

jrester commented 2 years ago

This is a change in 0.3.11. Meters can now only be accessed using get_meter(MeterType.SOLAR). This is because some meters may not be available on specific installations.

Panda88CO commented 2 years ago

Ok - is there a simple way to combine the types into one - or do need to keep it as separate results for each type ?

jrester commented 2 years ago

You can iterate over all available meters and collect the attributes you need like this:

meters_aggregates = powerwall.get_meters()
for meter in meters_aggregates.meters:
    meters_aggregates.get_meter(meter).instant_power

What exactly is your usecase? Maybe I can implement a simpler solution directly in the library.

ewosborne commented 2 years ago

I ran into the same thing. My use case is that I'm downloading all the meter data, reshaping it, and uploading it elsewhere. Before this change I just did:

m = pw.get_meters()
metric_data = {
    'solar': [
        ('battery_charge_pct', round(pw.get_charge(), 1)),
        ('battery.imported', m.battery.energy_imported),
        ('battery.exported', m.battery.energy_exported),

To get around this change I just added them back in:

m = pw.get_meters()
m.battery = m.get_meter(MeterType.BATTERY)
m.load = m.get_meter(MeterType.LOAD)
m.site = m.get_meter(MeterType.SITE)
m.solar = m.get_meter(MeterType.SOLAR)

It's a hack, but it works.

jrester commented 2 years ago

Ok, those changes seem to result in more confusion than helping anybody. As such I will revert the changes in 0.3.14, so meters can be accessed using the old method: meters.solar.instant_power as well as using .