# Path: python/tHome/eagle/messages/Base.py
# class Base:
#    def __init__( self, name, node=None ):
#       self.name = name
# 
#       # Copy the attributes.
#       if node is not None:
#          for child in node:
#             setattr( self, child.tag, child.text )
# 
#       # Convert hex values to int and float.
#       convert.hexKeys( self, self._numHexKeys, float )
#       convert.hexKeys( self, self._intHexKeys, int )
# 
#    #------------------------------------------------------------------------
#    def msgDict( self ):
#       assert( self._jsonKeys )
# 
#       msg = {}
#       for key in self._jsonKeys:
#          if hasattr( self, key ):
#             msg[key] = getattr( self, key )
#             
#       if hasattr( self, "TimeUnix" ):
#          msg["Time"] = self.TimeUnix
# 
#       return msg
#       
#       
#    #------------------------------------------------------------------------
#    def _format( self, indent=3 ):
#       i = " "*indent
#       s = "%s(\n" % self.name
# 
#       for key in dir( self ):
#          if key[0] == "_":
#             continue
#          
#          v = getattr( self, key )
#          if callable( v ):
#             continue
# 
#          if hasattr( v, "_format" ):
#             s += "%s%s : %s,\n" % ( i, key, v._format( indent+3 ) )
#          elif isinstance( v, str ):
#             s += "%s%s : '%s',\n" % ( i, key, v )
#          else:
#             s += "%s%s : %s,\n" % ( i, key, v )
# 
#       s += "%s)" % i
#       return s
#       
#    #------------------------------------------------------------------------
#    def __str__( self ):
#       return self._format()
#       
#    def __repr__( self ):
#       return self.__str__()
# 
#    #------------------------------------------------------------------------


from .Base import Base
      ShortAddr     int

   Sample:
   
   <NetworkInfo>
     <DeviceMacId>0xd8d5b9000000103f</DeviceMacId>
     <CoordMacId>0x000781000086d0fe</CoordMacId>
     <Status>Connected</Status>
     <Description>Successfully Joined</Description>
     <ExtPanId>0x000781000086d0fe</ExtPanId>
     <Channel>20</Channel>
     <ShortAddr>0xe1aa</ShortAddr>
     <LinkStrength>0x64</LinkStrength>
   </NetworkInfo>
   """

   # Hex keys turn into floats or ints.  Taken care of automatically
   # in Base.__init__().
   _numHexKeys = []
   _intHexKeys = [ "DeviceMacId", "CoordMacId", "ExtPanId", "ShortAddr",
                   "StatusCode", "LinkStrength" ]

   _jsonKeys = [ "DeviceMacid", "Status", "LinkStrength", "Description",
                 "Channel" ]
   
   #------------------------------------------------------------------------
   def __init__( self, node ):
      """node == xml ETree node
      """
      assert( node.tag == "NetworkInfo" )

# Path: python/tHome/eagle/messages/Base.py
# class Base:
#    def __init__( self, name, node=None ):
#       self.name = name
# 
#       # Copy the attributes.
#       if node is not None:
#          for child in node:
#             setattr( self, child.tag, child.text )
# 
#       # Convert hex values to int and float.
#       convert.hexKeys( self, self._numHexKeys, float )
#       convert.hexKeys( self, self._intHexKeys, int )
# 
#    #------------------------------------------------------------------------
#    def msgDict( self ):
#       assert( self._jsonKeys )
# 
#       msg = {}
#       for key in self._jsonKeys:
#          if hasattr( self, key ):
#             msg[key] = getattr( self, key )
#             
#       if hasattr( self, "TimeUnix" ):
#          msg["Time"] = self.TimeUnix
# 
#       return msg
#       
#       
#    #------------------------------------------------------------------------
#    def _format( self, indent=3 ):
#       i = " "*indent
#       s = "%s(\n" % self.name
# 
#       for key in dir( self ):
#          if key[0] == "_":
#             continue
#          
#          v = getattr( self, key )
#          if callable( v ):
#             continue
# 
#          if hasattr( v, "_format" ):
#             s += "%s%s : %s,\n" % ( i, key, v._format( indent+3 ) )
#          elif isinstance( v, str ):
#             s += "%s%s : '%s',\n" % ( i, key, v )
#          else:
#             s += "%s%s : %s,\n" % ( i, key, v )
# 
#       s += "%s)" % i
#       return s
#       
#    #------------------------------------------------------------------------
#    def __str__( self ):
#       return self._format()
#       
#    def __repr__( self ):
#       return self.__str__()
# 
#    #------------------------------------------------------------------------


# Path: python/tHome/eagle/messages/NetworkInfo.py
from .Base import Base

      ShortAddr     int

   Sample:
   
   <NetworkInfo>
     <DeviceMacId>0xd8d5b9000000103f</DeviceMacId>
     <CoordMacId>0x000781000086d0fe</CoordMacId>
     <Status>Connected</Status>
     <Description>Successfully Joined</Description>
     <ExtPanId>0x000781000086d0fe</ExtPanId>
     <Channel>20</Channel>
     <ShortAddr>0xe1aa</ShortAddr>
     <LinkStrength>0x64</LinkStrength>
   </NetworkInfo>
   """

   # Hex keys turn into floats or ints.  Taken care of automatically
   # in Base.__init__().
   _numHexKeys = []
   _intHexKeys = [ "DeviceMacId", "CoordMacId", "ExtPanId", "ShortAddr",
                   "StatusCode", "LinkStrength" ]

   _jsonKeys = [ "DeviceMacid", "Status", "LinkStrength", "Description",
                 "Channel" ]
   
   #------------------------------------------------------------------------
   def __init__( self, node ):
      """node == xml ETree node
      """
      assert( node.tag == "NetworkInfo" )

      Base.__init__( self, "NetworkInfo", node )