<commit_before>"""
-*- test-case-name: PyHouse.src.Modules.irrigation.test.test_irrigation -*-

@name: PyHouse/src/Modules/irrigation/test/irrigation.py
@author: briank
@contact: <EMAIL>>
@Copyright: (c)  2014 by briank
@license: MIT License
@note: Created on Jul 4, 2014
@Summary:

"""

# Import system type stuff
import xml.etree.ElementTree as ET

# Import PyMh files
from Modules.Core.data_objects import IrrigationData
from Modules.Utilities import xml_tools
from Modules.Computer import logging_pyh as Logging
# from Modules.Utilities.tools import PrettyPrintAny

g_debug = 0
LOG = Logging.getLogger('PyHouse.Irrigation  ')


class ReadWriteConfigXml(xml_tools.XmlConfigTools):
    """
    """
    m_count = 0

    def _read_irrigation_data(self, p_obj, p_xml):
        """
        @return: a IrrigationData object.
        """
        p_obj.ControllerFamily = self.get_text_from_xml(p_xml, 'ControllerFamily')
        return p_obj

    def _read_family_data(self, p_obj, p_xml):
        try:
            l_family = p_obj.ControllerFamily
            l_api = self.m_pyhouse_obj.House.RefOBJs.FamilyData[l_family].FamilyModuleAPI
            l_api.extract_device_xml(p_obj, p_xml)
        except KeyError:
            pass

    def read_one_irrigation_xml(self, p_item_element):
        """
        @return: an IrrigationData object
        """
        l_obj = IrrigationData()
        self.read_base_object_xml(l_obj, p_item_element)
        l_obj.Key = self.m_count  # Renumber
        self._read_irrigation_data(l_obj, p_item_element)
        self._read_family_data(l_obj, p_item_element)
        return l_obj

    def read_all_irrigation_xml(self, p_sect_element):
        """
        """
        l_xml_sect = self.setup_xml(self.m_pyhouse_obj)
        l_ret = {}
        self.m_count = 0
        if l_xml_sect == None:
            return l_ret
        try:
            for l_xml in p_sect_element.iterfind('Irrigation'):
                l_obj = self.read_one_irrigation_xml(l_xml)
                l_ret[self.m_count] = l_obj
                self.m_count += 1
        except AttributeError as e:
            LOG.error('ERROR is Reading irrigation information - {0:}'.format(e))
        # PrettyPrintAny(self.m_pyhouse_obj.House.DeviceOBJs.Irrigation, 'irrigation - ReadAll ', 100)
        return l_ret


    def _write_irrigation_data(self, p_obj, p_xml):
        pass

    def _write_family_data(self, p_obj, p_xml):
        try:
            l_api = self.m_pyhouse_obj.House.DeviceOBJs.FamilyData[p_obj.ControllerFamily].FamilyModuleAPI
            l_api.insert_device_xml(p_xml, p_obj)
        except KeyError:
            pass

    def write_one_thermostat_xml(self, p_thermostat_obj):
        """
        """
        l_xml = self.write_base_object_xml('Irrigation', p_thermostat_obj)
        self._write_irrigation_data(p_thermostat_obj, l_xml)
        self._write_family_data(p_thermostat_obj, l_xml)
        return l_xml

    def write_all_irrigation_xml(self, p_thermostat_sect_obj):
        """Create a sub tree for 'Irrigation' - the sub elements do not have to be present.
        @return: a sub tree ready to be appended to "something"
        """
        l_xml = ET.Element('IrrigationSection')
        self.m_count = 0
        try:
            for l_obj in p_thermostat_sect_obj.itervalues():
                l_entry = self.write_one_thermostat_xml(l_obj)
                l_xml.append(l_entry)
                self.m_count += 1
        except AttributeError as e:
            LOG.error('ERROR in saving irrigation data - {0:}'.format(e))
        return l_xml


class Utility(ReadWriteConfigXml):
    """
    """

    def update_pyhouse_obj(self, p_pyhouse_obj):
        p_pyhouse_obj.House.DeviceOBJs.Irrigation = IrrigationData()

    def add_api_references(self, p_pyhouse_obj):
        pass

    def setup_xml(self, p_pyhouse_obj):<commit_msg>Fix irrigation<commit_after>"""
-*- test-case-name: PyHouse.src.Modules.irrigation.test.test_irrigation -*-

@name: PyHouse/src/Modules/irrigation/test/irrigation.py
@author: briank
@contact: <EMAIL>>
@Copyright: (c)  2014 by briank
@license: MIT License
@note: Created on Jul 4, 2014
@Summary:

"""

# Import system type stuff
import xml.etree.ElementTree as ET

# Import PyMh files
from Modules.Core.data_objects import IrrigationData
from Modules.Utilities import xml_tools
from Modules.Computer import logging_pyh as Logging
# from Modules.Utilities.tools import PrettyPrintAny

g_debug = 0
LOG = Logging.getLogger('PyHouse.Irrigation     ')


class ReadWriteConfigXml(xml_tools.XmlConfigTools):
    """
    """
    m_count = 0

    def _read_irrigation_data(self, p_obj, p_xml):
        """
        @return: a IrrigationData object.
        """
        p_obj.ControllerFamily = self.get_text_from_xml(p_xml, 'ControllerFamily')
        return p_obj

    def _read_family_data(self, p_obj, p_xml):
        try:
            l_family = p_obj.ControllerFamily
            l_api = self.m_pyhouse_obj.House.RefOBJs.FamilyData[l_family].FamilyModuleAPI
            l_api.extract_device_xml(p_obj, p_xml)
        except KeyError:
            pass

    def read_one_irrigation_xml(self, p_item_element):
        """
        @return: an IrrigationData object
        """
        l_obj = IrrigationData()
        self.read_base_object_xml(l_obj, p_item_element)
        l_obj.Key = self.m_count  # Renumber
        self._read_irrigation_data(l_obj, p_item_element)
        self._read_family_data(l_obj, p_item_element)
        return l_obj

    def read_all_irrigation_xml(self, p_sect_element):
        """
        """
        l_xml_sect = self.setup_xml(self.m_pyhouse_obj)
        l_ret = {}
        self.m_count = 0
        if l_xml_sect == None:
            return l_ret
        try:
            for l_xml in p_sect_element.iterfind('Irrigation'):
                l_obj = self.read_one_irrigation_xml(l_xml)
                l_ret[self.m_count] = l_obj
                self.m_count += 1
        except AttributeError as e:
            LOG.error('ERROR is Reading irrigation information - {0:}'.format(e))
        # PrettyPrintAny(self.m_pyhouse_obj.House.DeviceOBJs.Irrigation, 'irrigation - ReadAll ', 100)
        return l_ret


    def _write_irrigation_data(self, p_obj, p_xml):
        pass

    def _write_family_data(self, p_obj, p_xml):
        try:
            l_api = self.m_pyhouse_obj.House.RefOBJs.FamilyData[p_obj.ControllerFamily].FamilyModuleAPI
            l_api.insert_device_xml(p_xml, p_obj)
        except KeyError:
            pass

    def write_one_irrigation_xml(self, p_irrigation_obj):
        """
        """
        l_xml = self.write_base_object_xml('Irrigation', p_irrigation_obj)
        self._write_irrigation_data(p_irrigation_obj, l_xml)
        self._write_family_data(p_irrigation_obj, l_xml)
        return l_xml

    def write_all_irrigation_xml(self, p_irrigation_sect_obj):
        """Create a sub tree for 'Irrigation' - the sub elements do not have to be present.
        @return: a sub tree ready to be appended to "something"
        """
        l_xml = ET.Element('IrrigationSection')
        self.m_count = 0
        try:
            for l_obj in p_irrigation_sect_obj.itervalues():
                l_entry = self.write_one_irrigation_xml(l_obj)
                l_xml.append(l_entry)
                self.m_count += 1
        except AttributeError as e:
            LOG.error('ERROR in saving irrigation data - {0:}'.format(e))
        return l_xml


class Utility(ReadWriteConfigXml):
    """
    """

    def update_pyhouse_obj(self, p_pyhouse_obj):
        p_pyhouse_obj.House.DeviceOBJs.Irrigation = IrrigationData()

    def add_api_references(self, p_pyhouse_obj):
        pass

    def setup_xml(self, p_pyhouse_obj):
{'fraction_non_alphanumeric': 0.09047434406100556, 'fraction_numerical': 0.005169962517771746, 'mean_word_length': 2.627754336615096, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 68}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '232255', 'n_tokens_mistral': 2669, 'n_tokens_neox': 2577, 'n_words': 490}