Browse Source

Merge pull request #910 from betacentauri/main

Raspberry Pi: Add log file rotation
pull/928/head
Lukas Pusch 2 years ago
committed by GitHub
parent
commit
685a2c81bd
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      tools/rpi/ahoy.yml.example
  2. 7
      tools/rpi/hoymiles/__main__.py
  3. 8
      tools/rpi/hoymiles/decoders/__init__.py

2
tools/rpi/ahoy.yml.example

@ -7,6 +7,8 @@ ahoy:
filename: 'hoymiles.log'
# DEBUG, INFO, WARNING, ERROR, FATAL
level: 'INFO'
max_log_filesize: 1000000
max_log_files: 1
sunset:
disabled: false

7
tools/rpi/hoymiles/__main__.py

@ -19,6 +19,7 @@ import yaml
from yaml.loader import SafeLoader
import hoymiles
import logging
from logging.handlers import RotatingFileHandler
################################################################################
""" Signal Handler """
@ -298,6 +299,8 @@ def init_logging(ahoy_config):
log_config = ahoy_config.get('logging')
fn = 'hoymiles.log'
lvl = logging.ERROR
max_log_filesize = 1000000
max_log_files = 1
if log_config:
fn = log_config.get('filename', fn)
level = log_config.get('level', 'ERROR')
@ -311,9 +314,11 @@ def init_logging(ahoy_config):
lvl = logging.ERROR
elif level == 'FATAL':
lvl = logging.FATAL
max_log_filesize = log_config.get('max_log_filesize', max_log_filesize)
max_log_files = log_config.get('max_log_files', max_log_files)
if hoymiles.HOYMILES_TRANSACTION_LOGGING:
lvl = logging.DEBUG
logging.basicConfig(filename=fn, format='%(asctime)s %(levelname)s: %(message)s', datefmt='%Y-%m-%d %H:%M:%S', level=lvl)
logging.basicConfig(handlers=[RotatingFileHandler(fn, maxBytes=max_log_filesize, backupCount=max_log_files)], format='%(asctime)s %(levelname)s: %(message)s', datefmt='%Y-%m-%d %H:%M:%S', level=lvl)
dtu_name = ahoy_config.get('dtu',{}).get('name','hoymiles-dtu')
logging.info(f'start logging for {dtu_name} with level: {logging.root.level}')

8
tools/rpi/hoymiles/decoders/__init__.py

@ -515,9 +515,17 @@ class Hm300Decode0B(StatusResponse):
""" reactive power """
return self.unpack('>H', 20)[0]/10
@property
def powerfactor(self):
""" Powerfactor """
return self.unpack('>H', 24)[0]/1000
@property
def temperature(self):
""" Inverter temperature in °C """
return self.unpack('>h', 26)[0]/10
@property
def event_count(self):
""" Event counter """
return self.unpack('>H', 28)[0]
class Hm300Decode0C(Hm300Decode0B):
""" 1121-series mirco-inverters status data """

Loading…
Cancel
Save