Browse Source
			
			
			Merge pull request #238 from chehrlic/chris_vz
			
				RPI: use a requests seesion for the volkszaehler plugin...
			
			
				pull/244/head
			
			
		 
		
			
				
					
						 Andreas Schiffler
					
					3 years ago
						Andreas Schiffler
					
					3 years ago
					
						
							committed by
							
								 GitHub
								GitHub
							
						 
					
				 
				
			 
		 
		
			
				
					
					No known key found for this signature in database
					
						
							GPG Key ID: 4AEE18F83AFDEB23
						
					
				
			
		
		
		
	
		
			
				 2 changed files with 
4 additions and 
2 deletions
			 
			
		 
		
			
				- 
					
					
					 
					tools/rpi/hoymiles/__main__.py
				
- 
					
					
					 
					tools/rpi/hoymiles/outputs.py
				
				
				
					
						
							
								
									
	
		
		
			
				
					|  | @ -72,6 +72,7 @@ def poll_inverter(inverter, retries=4): | 
			
		
	
		
		
			
				
					|  |  |         # Handle the response data if any |  |  |         # Handle the response data if any | 
			
		
	
		
		
			
				
					|  |  |         if response: |  |  |         if response: | 
			
		
	
		
		
			
				
					|  |  |             c_datetime = datetime.now() |  |  |             c_datetime = datetime.now() | 
			
		
	
		
		
			
				
					|  |  |  |  |  |             if hoymiles.HOYMILES_DEBUG_LOGGING: | 
			
		
	
		
		
			
				
					|  |  |                 print(f'{c_datetime} Payload: ' + hoymiles.hexify_payload(response)) |  |  |                 print(f'{c_datetime} Payload: ' + hoymiles.hexify_payload(response)) | 
			
		
	
		
		
			
				
					|  |  |             decoder = hoymiles.ResponseDecoder(response, |  |  |             decoder = hoymiles.ResponseDecoder(response, | 
			
		
	
		
		
			
				
					|  |  |                     request=com.request, |  |  |                     request=com.request, | 
			
		
	
	
		
		
			
				
					|  | 
 | 
			
		
	
								
							
						
					 
					
				 
			 
		
			
			
			
			
			
			
				
				
					
						
							
								
									
	
		
		
			
				
					|  | @ -215,6 +215,7 @@ class VolkszaehlerOutputPlugin(OutputPluginFactory): | 
			
		
	
		
		
			
				
					|  |  |         """ |  |  |         """ | 
			
		
	
		
		
			
				
					|  |  |         super().__init__(**params) |  |  |         super().__init__(**params) | 
			
		
	
		
		
			
				
					|  |  | 
 |  |  | 
 | 
			
		
	
		
		
			
				
					|  |  |  |  |  |         self.session = requests.Session() | 
			
		
	
		
		
			
				
					|  |  |         self.baseurl = config.get('url', 'http://localhost/middleware/') |  |  |         self.baseurl = config.get('url', 'http://localhost/middleware/') | 
			
		
	
		
		
			
				
					|  |  |         self.channels = dict() |  |  |         self.channels = dict() | 
			
		
	
		
		
			
				
					|  |  |         for channel in config.get('channels', []): |  |  |         for channel in config.get('channels', []): | 
			
		
	
	
		
		
			
				
					|  | @ -271,7 +272,7 @@ class VolkszaehlerOutputPlugin(OutputPluginFactory): | 
			
		
	
		
		
			
				
					|  |  |         uid = self.channels[ctype] |  |  |         uid = self.channels[ctype] | 
			
		
	
		
		
			
				
					|  |  |         url = f'{self.baseurl}/data/{uid}.json?operation=add&ts={ts}&value={value}' |  |  |         url = f'{self.baseurl}/data/{uid}.json?operation=add&ts={ts}&value={value}' | 
			
		
	
		
		
			
				
					|  |  |         try: |  |  |         try: | 
			
		
	
		
		
			
				
					
					|  |  |             r = requests.get(url) |  |  |             r = self.session.get(url) | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					|  |  |             if r.status_code != 200: |  |  |             if r.status_code != 200: | 
			
		
	
		
		
			
				
					|  |  |                 raise ValueError('Could not send request (%s)' % url) |  |  |                 raise ValueError('Could not send request (%s)' % url) | 
			
		
	
		
		
			
				
					|  |  |         except ConnectionError as e: |  |  |         except ConnectionError as e: | 
			
		
	
	
		
		
			
				
					|  | 
 |