<commit_before>package com.kalixia.ha.devices.gce.ecodevices.commands

import com.kalixia.ha.devices.gce.ecodevices.EcoDeviceConfiguration
import com.kalixia.ha.devices.gce.ecodevices.TeleinfoSensor
import com.kalixia.ha.model.quantity.WattsPerHour
import com.netflix.hystrix.HystrixCommand
import com.netflix.hystrix.HystrixCommandGroupKey
import com.netflix.hystrix.HystrixCommandKey
import groovy.util.logging.Slf4j
import groovyx.net.http.HTTPBuilder

import javax.measure.Measurable
import javax.measure.Measure

import static com.kalixia.ha.devices.gce.ecodevices.TeleinfoSensorSlot.TELEINFO1
import static com.kalixia.ha.devices.gce.ecodevices.TeleinfoSensorSlot.TELEINFO2

@Slf4j("LOGGER")
class EcoDeviceXmlParsingCommand extends HystrixCommand<List<Measurable<WattsPerHour>>> {
    private final TeleinfoSensor teleinfo
    private final EcoDeviceConfiguration configuration

    public EcoDeviceXmlParsingCommand(TeleinfoSensor teleinfo, EcoDeviceConfiguration configuration) {
        super(HystrixCommand.Setter
                .withGroupKey(HystrixCommandGroupKey.Factory.asKey("EcoDevice"))
                .andCommandKey(HystrixCommandKey.Factory.asKey("TeleinfoSensor"))
        )
        super.executionTimeInMilliseconds
        this.teleinfo = teleinfo
        this.configuration = configuration
    }

    @Override
    protected List<Measurable<WattsPerHour>> run() throws Exception {
        def http = new HTTPBuilder(configuration.url)
        if (configuration.authenticationConfiguration != null) {
            http.auth.basic configuration.authenticationConfiguration.username,
                    configuration.authenticationConfiguration.password
        }

        LOGGER.info("About to make HTTP call to ${configuration.url}/protect/settings/${teleinfo.slot.slug}")

        List<Measurable<WattsPerHour>> indexes = []
        http.get(path: "/protect/settings/${teleinfo.slot.slug}") { resp, xml ->
            switch (teleinfo.slot) {
                case TELEINFO1:
                    indexes << Measure.valueOf(xml.T1_HCHP.text() as Long, WattsPerHour.UNIT)
                    indexes << Measure.valueOf(xml.T1_HCHC.text() as Long, WattsPerHour.UNIT)
                    break
                case TELEINFO2:
                    indexes << Measure.valueOf(xml.T2_HCHP.text() as Long, WattsPerHour.UNIT)
                    indexes << Measure.valueOf(xml.T2_HCHC.text() as Long, WattsPerHour.UNIT)
                    break
            }
        }

        http.shutdown()

        LOGGER.info("Indexes: HP=${indexes[0]}, HC=${indexes[1]}")
        return indexes
    }
}
<commit_msg>Upgraded Hystrix to 1.3.0. Fixed broken command configuration introduced by a recent refactoring.<commit_after>package com.kalixia.ha.devices.gce.ecodevices.commands

import com.kalixia.ha.devices.gce.ecodevices.EcoDeviceConfiguration
import com.kalixia.ha.devices.gce.ecodevices.TeleinfoSensor
import com.kalixia.ha.model.quantity.WattsPerHour
import com.netflix.hystrix.HystrixCommand
import com.netflix.hystrix.HystrixCommandGroupKey
import com.netflix.hystrix.HystrixCommandKey
import groovy.util.logging.Slf4j
import groovyx.net.http.HTTPBuilder

import javax.measure.Measurable
import javax.measure.Measure

import static com.kalixia.ha.devices.gce.ecodevices.TeleinfoSensorSlot.TELEINFO1
import static com.kalixia.ha.devices.gce.ecodevices.TeleinfoSensorSlot.TELEINFO2

@Slf4j("LOGGER")
class EcoDeviceXmlParsingCommand extends HystrixCommand<List<Measurable<WattsPerHour>>> {
    private final TeleinfoSensor teleinfo
    private final EcoDeviceConfiguration configuration

    public EcoDeviceXmlParsingCommand(TeleinfoSensor teleinfo, EcoDeviceConfiguration configuration) {
        super(HystrixCommand.Setter
                .withGroupKey(HystrixCommandGroupKey.Factory.asKey("EcoDevice"))
                .andCommandKey(HystrixCommandKey.Factory.asKey("Teleinfo"))
        )
        super.executionTimeInMilliseconds
        this.teleinfo = teleinfo
        this.configuration = configuration
    }

    @Override
    protected List<Measurable<WattsPerHour>> run() throws Exception {
        def http = new HTTPBuilder(configuration.url)
        if (configuration.authenticationConfiguration != null) {
            http.auth.basic configuration.authenticationConfiguration.username,
                    configuration.authenticationConfiguration.password
        }

        LOGGER.info("About to make HTTP call to ${configuration.url}/protect/settings/${teleinfo.slot.slug}")

        List<Measurable<WattsPerHour>> indexes = []
        http.get(path: "/protect/settings/${teleinfo.slot.slug}") { resp, xml ->
            switch (teleinfo.slot) {
                case TELEINFO1:
                    indexes << Measure.valueOf(xml.T1_HCHP.text() as Long, WattsPerHour.UNIT)
                    indexes << Measure.valueOf(xml.T1_HCHC.text() as Long, WattsPerHour.UNIT)
                    break
                case TELEINFO2:
                    indexes << Measure.valueOf(xml.T2_HCHP.text() as Long, WattsPerHour.UNIT)
                    indexes << Measure.valueOf(xml.T2_HCHC.text() as Long, WattsPerHour.UNIT)
                    break
            }
        }

        http.shutdown()

        LOGGER.info("Indexes: HP=${indexes[0]}, HC=${indexes[1]}")
        return indexes
    }
}

{'fraction_non_alphanumeric': 0.09323308270676692, 'fraction_numerical': 0.0050751879699248124, 'mean_word_length': 3.064935064935065, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 10}, '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': '5049852', 'n_tokens_mistral': 1618, 'n_tokens_neox': 1566, 'n_words': 246}