Difference between revisions of "Fritzbox-java-api"

From BITPlan Wiki
Jump to navigation Jump to search
Line 80: Line 80:
 
             Aquarium |        AVM |  FRITZ!DECT 200 | 08761 0033476
 
             Aquarium |        AVM |  FRITZ!DECT 200 | 08761 0033476
 
           Wohnzimmer |        AVM |  FRITZ!DECT 200 | 08761 0092893
 
           Wohnzimmer |        AVM |  FRITZ!DECT 200 | 08761 0092893
 +
</source>
 +
 +
== read devices ==
 +
<source lang='bash'>
 +
java -jar fritzbox-java-api-0.4.2.jar -r Aquarium Wohnzimmer
 +
name: Aquarium
 +
  id: 087610033476
 +
alive: true
 +
  on: false
 +
uses:    0    W
 +
used:  940,882 kWh
 +
temp:    25,0  °C
 +
 +
name: Wohnzimmer
 +
  id: 087610092893
 +
alive: true
 +
  on: true
 +
uses:    1    W
 +
used:    35,510 kWh
 +
temp:    24,5  °C
 
</source>
 
</source>
  
 
= Links =
 
= Links =
 
* https://www.pcwelt.de/ratgeber/Dect-Funksteckdosen-10022547.html
 
* https://www.pcwelt.de/ratgeber/Dect-Funksteckdosen-10022547.html

Revision as of 13:05, 26 October 2017

Unit tests

The unit tests can be run with:

mvn test

If you did not setup your configuration file yet there will be a warning: You might want to set your application properties in $HOME.fritzbox/application.properties When the application properties are set more tests are run. E.g. one test should show "Logged in with session id ..."

Configuration File

You might want to set your application properties in $HOME/.fritzbox/application.properties

fritzbox.url=http://fritz.box:443
fritzbox.username=user
fritzbox.password=secret

Code Example

see https://github.com/WolfgangFahl/fritzbox-java-api/blob/master/src/main/java/com/github/kaklakariada/fritzbox/TestDriver.java

 final Config config = ConfigService.readConfig();

    LOG.info("Logging in to '{}' with username '{}'", config.baseUrl,
        config.username);
    final HomeAutomation homeAutomation = HomeAutomation.connect(config);

    final DeviceList devices = homeAutomation.getDeviceListInfos();
    LOG.info("Found {} devices", devices.getDevices().size());
    for (final Device device : devices.getDevices()) {
      LOG.info("\t{}", device);
    }

    final List<String> ids = homeAutomation.getSwitchList();
    LOG.info("Found {} device ids: {}", ids.size(), ids);

    if (devices.getDevices().isEmpty()) {
      homeAutomation.logout();
      return;
    }

    for (final String ain : ids) {
      testHomeAutomation(homeAutomation, ain);
      // testEnergyStats(homeAutomation.getSession(), ain);
}

CmdLine

Help / Usage

java -jar fritzbox-java-api-0.4.2.jar -h

Help
FritzBox Java API Command Line Version: 0.4.2

github: https://github.com/kaklakariada/fritzbox-java-api

  usage: java -jar fritzbox.jar
 -d (--debug)         : debug
                        create additional debug output if this switch is used
                        (Vorgabe: false)
 -h (--help)          : help
                        show this usage (Vorgabe: true)
 -l (--list)          : list
                        list devices (Vorgabe: false)
 -r (--read) STRING[] : read
                        read the given devices
 -s (--set) STRING[]  : set
                        set the given devices to the givnen states e.g. main off
 -v (--version)       : showVersion
                        show current version if this switch is used (Vorgabe:
                        false)

List devices

java -jar fritzbox-java-api-0.4.2.jar -l
                Name |         By |         Product | Identifier
---------------------+------------+-----------------+-------------------------
            Aquarium |        AVM |  FRITZ!DECT 200 | 08761 0033476
          Wohnzimmer |        AVM |  FRITZ!DECT 200 | 08761 0092893

read devices

java -jar fritzbox-java-api-0.4.2.jar -r Aquarium Wohnzimmer
 name: Aquarium
   id: 087610033476 
alive: true
   on: false
 uses:     0     W
 used:   940,882 kWh
 temp:    25,0   °C

 name: Wohnzimmer
   id: 087610092893 
alive: true
   on: true
 uses:     1     W
 used:    35,510 kWh
 temp:    24,5   °C

Links