- 
                Notifications
    You must be signed in to change notification settings 
- Fork 20
          Initialize a Grid object with a given Fuse limit
          #610
        
          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
          
     Merged
      
      
            tiyash-basu-frequenz
  merged 7 commits into
  frequenz-floss:v0.x.x
from
tiyash-basu-frequenz:grid_connection
  
      
      
   
  Aug 30, 2023 
      
    
  
     Merged
                    Changes from all commits
      Commits
    
    
            Show all changes
          
          
            7 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      7b4a9fb
              
                Implement a hash method for `Component`
              
              
                tiyash-basu-frequenz a17939d
              
                Refactor optional type declarations in _component.py
              
              
                tiyash-basu-frequenz 2e71987
              
                Add metadata to Components
              
              
                tiyash-basu-frequenz 94ed083
              
                Allow setting grid metadata in mocks
              
              
                tiyash-basu-frequenz b57cee8
              
                Add a module for grid connection points
              
              
                tiyash-basu-frequenz 619858f
              
                Add a Fuse class and use it in Grid
              
              
                tiyash-basu-frequenz d2de571
              
                Use fuse in GridMetadata
              
              
                tiyash-basu-frequenz File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| # License: MIT | ||
| # Copyright © 2023 Frequenz Energy-as-a-Service GmbH | ||
|  | ||
| """Fuse data class.""" | ||
|  | ||
| from dataclasses import dataclass | ||
|  | ||
| from ..timeseries import Current | ||
|  | ||
|  | ||
| @dataclass(frozen=True) | ||
| class Fuse: | ||
| """Fuse data class.""" | ||
|  | ||
| max_current: Current | ||
| """Rated current of the fuse.""" | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| # License: MIT | ||
| # Copyright © 2023 Frequenz Energy-as-a-Service GmbH | ||
|  | ||
| """Grid connection point. | ||
|  | ||
| This module provides the `Grid` type, which represents a grid connection point | ||
| in a microgrid. | ||
| """ | ||
|  | ||
| import logging | ||
| from collections.abc import Iterable | ||
| from dataclasses import dataclass | ||
|  | ||
| from .component import Component | ||
| from .component._component import ComponentCategory | ||
| from .fuse import Fuse | ||
|  | ||
|  | ||
| @dataclass(frozen=True) | ||
| class Grid: | ||
| """A grid connection point.""" | ||
|  | ||
| fuse: Fuse | ||
| """The fuse protecting the grid connection point.""" | ||
|  | ||
|  | ||
| _GRID: Grid | None = None | ||
|  | ||
|  | ||
| def initialize(components: Iterable[Component]) -> None: | ||
| """Initialize the grid connection. | ||
|  | ||
| Args: | ||
| components: The components in the microgrid. | ||
|  | ||
| Raises: | ||
| RuntimeError: If there is more than 1 grid connection point in the | ||
| microgrid, or if the grid connection point is not initialized, | ||
| or if the grid connection point does not have a fuse. | ||
| """ | ||
| global _GRID # pylint: disable=global-statement | ||
|  | ||
| grid_connections = list( | ||
| component | ||
| for component in components | ||
| if component.category == ComponentCategory.GRID | ||
| ) | ||
|  | ||
| grid_connections_count = len(grid_connections) | ||
|  | ||
| if grid_connections_count == 0: | ||
| logging.info( | ||
| "No grid connection found for this microgrid. This is normal for an islanded microgrid." | ||
| ) | ||
| elif grid_connections_count > 1: | ||
| raise RuntimeError( | ||
| f"Expected at most one grid connection, got {grid_connections_count}" | ||
| ) | ||
| else: | ||
| if grid_connections[0].metadata is None: | ||
| raise RuntimeError("Grid metadata is None") | ||
|         
                  daniel-zullo-frequenz marked this conversation as resolved.
              Show resolved
            Hide resolved | ||
|  | ||
| fuse = grid_connections[0].metadata.fuse | ||
|  | ||
| if fuse is None: | ||
|         
                  tiyash-basu-frequenz marked this conversation as resolved.
              Show resolved
            Hide resolved | ||
| raise RuntimeError("Grid fuse is None") | ||
|  | ||
| _GRID = Grid(fuse) | ||
|  | ||
|  | ||
| def get() -> Grid | None: | ||
| """Get the grid connection. | ||
|  | ||
| Note that a microgrid configured as an island will not have a grid | ||
| connection point. For such microgrids, this function will return `None`. | ||
|  | ||
| Returns: | ||
| The grid connection. | ||
| """ | ||
| return _GRID | ||
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
      
      Oops, something went wrong.
        
    
  
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
Uh oh!
There was an error while loading. Please reload this page.