status_json.py 32.5 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794
#import math
import doctest
import json
import os

# --- update the path of Python 
py_path = os.sys.path
py_pwd = os.getcwd()
if (py_pwd not in py_path):
    (os.sys.path).append(py_pwd)
py_pwd = os.getcwd() + "/.."
if (py_pwd not in py_path):
    (os.sys.path).append(py_pwd)
py_pwd = os.getcwd() + "/../.."
if (py_pwd not in py_path):
    (os.sys.path).append(py_pwd)

import utils.celme as celme

# ========================================================
# ========================================================
# === Status_json
# ========================================================
# ========================================================

class Status_json:
    """ Class to manage Json file reports into python variables and vice versa

Example a a very wimple Json file report contents:
{
  "frame_model": "1.3",
  "producer_name": "PLC",
  "producer_version": "20180909",
  "entities": [
    {
      "entity_name": "PLC_STATUS",
      "origin": "Raspberry",
      "version_firmware": "20180924A",
      "site": "MyObservatory",
      "date": "2019-01-10T20:20:20.738",
      "devices": [
        {
          "device_name": "DHT22",
          "device_type": "meteo",
          "serial_number": "1",
          "error_code": "0",
          "device_values": [
            {
              "name": "OutsideTemperature",
              "data_type": "float",
              "value": "22",
              "unit": "degC",
              "monitoring_name": "Temperature_outside",
              "comment": "Temperature",
              "date_data": "2019-01-10T20:20:20.738"
            }
          ]
        }
      ]
    }
  ]
}    
          
A value is stored in a UFKI (Unique Four Key Identifier):
UFKI = entity_name device_name serial_number name

No support for hjson. See the following link to do that:
https://github.com/hjson/hjson-py

    
    Usage:
    ------

    First, instanciate an object from the class:    
    report = report.Status_json()

    Informations:
    -------------
    
    help(Status_json)
    Status_json().infos("doctest")
    Status_json().infos("doc_methods")
    """
# ========================================================
# === attributes
# ========================================================

    # --- multiplicators for units
    _status = []
    _entity_name = ""
    _device_name = ""
    _serial_number = ""
    
# ========================================================
# === internal methods
# ========================================================

    def _init(self,status=""):
        """ Initialize internal attributes.

        Inputs:
        -------
        status is a list of dictionnaries according a predefined format.
        
        Usage:
        ------        
        report = report.Status_json()
        """
        self._status = status
        self._entity_name = ""
        self._device_name = ""
        self._serial_number = ""

    def _is_number(self,s):
        """ Return True if the string is a number else return False.

        Usage:
        ------    
        >>> report = report.Status_json()
        >>> report._is_number("3e5")
        True
        >>> report._is_number("3a5")
        False
        """
        try:
            float(s)
            return True
        except ValueError:
            pass 
        try:
            import unicodedata
            unicodedata.numeric(s)
            return True
        except (TypeError, ValueError):
            pass 
        return False
    
    ####################################################################
    # To read a Status
    ####################################################################
    
    def _get_indice_from_entities(self, entities, entity_name):
        indice = 0
        found = -1
        for entity in entities:
            #print("{} et {}".format(entity,entity_name))
            if entity == entity_name:
                found = indice
                break
            indice += 1
        return found
    
    def _get_indice_from_devices(self, devices, device_name, serial_number):
        indice = 0
        found = -1
        for device in devices:
            cur_device_name = device['device_name']
            cur_serial_number = device['serial_number']
            #print("{} et {}".format(device,device_name))
            if (cur_device_name == device_name) and ( cur_serial_number == serial_number):
                found = indice
                break
            indice += 1
        return found
    
    def _get_entity_names(self):
        #entities = self._status['statuses'][0]['entities']
        entities = self._status['entities']
        entity_names = []
        for entity in entities:
            entity_names.append(entity['entity_name'])
        return entity_names
        
    def _get_device_nameserials(self, entity_name):
        entities = self._get_entity_names()
        indice = self._get_indice_from_entities(entities,entity_name)
        if indice == -1:
            return ""
        #devices = self._status['statuses'][0]['entities'][indice]['devices']
        devices = self._status['entities'][indice]['devices']
        device_names = []
        for device in devices:
            devs = {'device_name':device['device_name'], 'serial_number':device['serial_number']}
            #print("devs={} ".format(devs))
            device_names.append(devs)
        return device_names
    
    def _get_value_names(self, entity_name, device_name, serial_number):
        entities = self._get_entity_names()
        indicee = self._get_indice_from_entities(entities,entity_name)
        if indicee == -1:
            return ""
        #devices = self._status['statuses'][0]['entities'][indicee]['devices']
        devices = self._status['entities'][indicee]['devices']
        indiced = self._get_indice_from_devices(devices, device_name, serial_number)
        device = devices[indiced]
        #print("device={} ".format(device))
        values = device['device_values']
        value_names = []
        for value in values:
            #print("value={} ".format(value))
            value_names.append(value['name'])
        return value_names
    
    def _get_value_name_values(self, entity_name, device_name, serial_number, value_name):
        entities = self._get_entity_names()
        indicee = self._get_indice_from_entities(entities,entity_name)
        if indicee == -1:
            return ""
        #devices = self._status['statuses'][0]['entities'][indicee]['devices']
        devices = self._status['entities'][indicee]['devices']
        indiced = self._get_indice_from_devices(devices, device_name, serial_number)
        device = devices[indiced]
        #print("device={} ".format(device))
        values = device['device_values']
        for value in values:
            if value_name == value['name']:
                return value
        return ""
    
    def _set_value_name_values(self, entity_name, device_name, serial_number, value_name, dico):
        entities = self._get_entity_names()
        indicee = self._get_indice_from_entities(entities,entity_name)
        if indicee == -1:
            return ""
        #devices = self._status['statuses'][0]['entities'][indicee]['devices']
        devices = self._status['entities'][indicee]['devices']
        indiced = self._get_indice_from_devices(devices, device_name, serial_number)
        device = devices[indiced]
        #print("device={} ".format(device))
        values = device['device_values']
        indicev = 0
        for value in values:
            if value_name == value['name']:
                #self._status['statuses'][0]['entities'][indicee]['devices'][indiced]['device_values'][indicev] = dico
                self._status['entities'][indicee]['devices'][indiced]['device_values'][indicev] = dico
                break
            indicev += 1
        return ""

    ####################################################################
    # To create a Status
    ####################################################################
    
    def _status_new(self, producer_name, producer_version):
        status_header = {'frame_model':'1.3', 'producer_name':producer_name, 'producer_version':producer_version, 'entities':[]}
        #self._status = { 'statuses':[] }
        #self._status['statuses'].append(status_header)
        self._status = status_header
    
    def _status_new_entity(self, entity_name, theorigin, version_firmware, site, date=""):
        if date=="":
            date = (celme.Date("now")).iso()
        entity= {'entity_name':entity_name, 'origin':theorigin, 'version_firmware':version_firmware, 'site':site, 'date':date, 'devices':[]}
        #self._status['statuses'][0]['entities'].append(entity);
        self._status['entities'].append(entity);
    
    def _status_entity_new_device(self, entity_name, device_name, device_type, serial_number, error_code):        
        entities = self._get_entity_names()
        indicee = self._get_indice_from_entities(entities,entity_name)
        if indicee == -1:
            return ""
        device = {'device_name':device_name, 'device_type':device_type, 'serial_number':serial_number, 'error_code':error_code, 'device_values':[]}
        #self._status['statuses'][0]['entities'][indicee]['devices'].append(device)
        self._status['entities'][indicee]['devices'].append(device)
    
    def _status_entity_device_new_value(self, entity_name, device_name, serial_number, name, data_type, value, unit="", monitoring_name="", comment="", date_data=""):
        entities = self._get_entity_names()
        indicee = self._get_indice_from_entities(entities,entity_name)
        if indicee == -1:
            return ""
        #devices = self._status['statuses'][0]['entities'][indicee]['devices']
        devices = self._status['entities'][indicee]['devices']
        indiced = self._get_indice_from_devices(devices, device_name, serial_number)
        if indiced == -1:
            return ""
        if date_data=="":
            date_data = (celme.Date("now")).iso()
        else:
            date_data = (celme.Date(date_data)).iso()
        dico = {'name':name, 'data_type':data_type, 'value':value, 'unit':unit, 'monitoring_name':monitoring_name, 'comment':comment, 'date_data':date_data}
        #self._status['statuses'][0]['entities'][indicee]['devices'][indiced]['device_values'].append(dico)
        self._status['entities'][indicee]['devices'][indiced]['device_values'].append(dico)
    
# ========================================================
# === status_json methods
# ========================================================

    def new_status(self, producer_name, producer_version):
        """ Initialize a new status
        
        Inputs:
        -------
        Dictionary keys of the creator.
        
        Usage:
        ------
        >>> report = report.Status_json()
        >>> report.new_status("PLC","20180909")
        
        Related topics:
        ---------------
        Method append_entity
        """
        self._init()
        self._status_new(producer_name, producer_version)

    def append_entity(self, entity_name, theorigin, version_firmware, site, date=""):
        """ Append a new entity to a creator
        
        Inputs:
        -------
        Dictionary keys of the entity.
        
        Usage:
        ------
        >>> report = report.Status_json()
        >>> report.new_status("PLC","20180909")
        >>> rep.append_entity("PLC_STATUS", "Raspberry", "20180924A", "MyObservatory")
        
        Related topics:
        ---------------
        Methods append_device, get_entities
        """
        self._status_new_entity(entity_name, theorigin, version_firmware, site, date)
        self._entity_name = entity_name

    def append_device(self, device_name, device_type, serial_number, error_code):
        """ Append a new device to an entity
        
        Inputs:
        -------
        Dictionary keys of the device.
        
        Usage:
        ------
        >>> report = report.Status_json()
        >>> report.new_status("PLC","20180909")
        >>> rep.append_entity("PLC_STATUS", "Raspberry", "20180924A", "MyObservatory")
        >>> rep.append_device("DHT22", "meteo", "1", "0")
        
        Related topics:
        ---------------
        Methods append_value, get_devices
        """
        entity_name = self._entity_name
        self._status_entity_new_device(entity_name, device_name, device_type, serial_number, error_code)
        self._device_name = device_name
        self._serial_number = serial_number
        
    def append_value(self, name, data_type, value, unit="", monitoring_name="", comment="", date_data=""):
        """ Append a new value to a device
        
        Inputs:
        -------
        Dictionary keys of the device_value.
        
        Usage:
        ------
        >>> report = report.Status_json()
        >>> report.new_status("PLC","20180909")
        >>> rep.append_entity("PLC_STATUS", "Raspberry", "20180924A", "MyObservatory")
        >>> rep.append_device("DHT22", "meteo", "1", "0")
        >>> rep.append_value(  "OutsideTemperature",  "float","22","degC","temperature","Temperature","")
        
        Related topics:
        ---------------
        Methods append_value, get_devices
        """
        entity_name = self._entity_name
        device_name = self._device_name
        serial_number = self._serial_number
        self._status_entity_device_new_value(entity_name, device_name, serial_number, name, data_type, value, unit, monitoring_name, comment, date_data)
        
    def load_json(self, full_filename):        
        """ Load a Json file as an object
        
        Inputs:
        -------
        full_filename is the path + file name of the Json file
        
        Usage:
        ------
        >>> report = report.Status_json()
        >>> report.load_json("")
        
        Related topics:
        ---------------
        The Json file does not have any comment
        """
        if (full_filename != ""):
            with open(full_filename, "r") as read_file:
                self._status = json.load(read_file)
            
    def save_json(self, full_filename):        
        """ Save a Json file from an object
        
        Inputs:
        -------
        full_filename is the path + file name of the Json file
        
        Usage:
        ------
        >>> report = report.Status_json()
        >>> report.create_a_simple_report_for_tests()
        >>> report.save_json("")
        
        Related topics:
        ---------------
        The Json file will not have any comment
        """
        if (full_filename != "") and (self._status != ""):
            json_string = json.dumps(self._status, indent=2)
            with open(full_filename, "w") as write_file:
                write_file.write(json_string)

    def create_a_simple_report_for_tests(self):        
        """ Create a simple report for tests
        
        Inputs:
        -------
        None.
        
        Usage:
        ------
        >>> report = report.Status_json()
        >>> report.create_a_simple_report_for_tests()
        
        Related topics:
        ---------------
        The Json file will not have any comment
        """
        self.new_status("PLC","20180909")
        self.append_entity("PLC_STATUS", "Raspberry", "20180924A", "MyObservatory")
        self.append_device("DHT22", "meteo", "1", "0")
        self.append_value(  "OutsideTemperature",  "float","22","degC","temperature","Temperature")
        #full_filename = "test.json"
        #self.save_json(full_filename)        
                    
# ========================================================
# === get/set methods
# ========================================================

    def get_error_message(self, error_code):
        """ Get the message of a given error code
        
        Inputs:
        -------
        integer number corresponding to an error code.

        Outputs:
        -------
        The string message of the error code.
        
        Usage:
        ------
        >>> rep.get_error_message(102)
        >>> 'Disk full'
        
        Related topics:
        ---------------
        """
        errs = []
        errs.append( {'code':0, 'message':"No error", 'version':"1.0"} )
        # errors
        errs.append( {'code':1    , 'message':"Unreferenced error", 'version':"1.2"} )
        errs.append( {'code':2    , 'message':"System error", 'version':"1.2"} )
        errs.append( {'code':3	 , 'message':"Device temperature too high", 'version':"1.2"} )
        errs.append( {'code':4	 , 'message':"Device temperature too low", 'version':"1.2"} )
        errs.append( {'code':101	 , 'message':"Disk not found", 'version':"1.2"} )
        errs.append( {'code':102	 , 'message':"Disk full", 'version':"1.2"} )
        errs.append( {'code':111	 , 'message':"File not found", 'version':"1.2"} )
        errs.append( {'code':112	 , 'message':"File opening failure", 'version':"1.2"} )
        errs.append( {'code':113	 , 'message':"File reading error", 'version':"1.2"} )
        errs.append( {'code':114	 , 'message':"File writing error", 'version':"1.2"} )
        errs.append( {'code':1001 , 'message':"Power supply off", 'version':"1.2"} )
        errs.append( {'code':1002 , 'message':"Power supply over voltage", 'version':"1.2"} )
        errs.append( {'code':2001 , 'message':"Data connection failed", 'version':"1.2"} )
        errs.append( {'code':2002 , 'message':"Data checksum error", 'version':"1.2"} )
        errs.append( {'code':2003 , 'message':"Data value out of range", 'version':"1.2"} )
        errs.append( {'code':2004 , 'message':"No data", 'version':"1.2"} )
        errs.append( {'code':2005 , 'message':"No response after timeout", 'version':"1.2"} )
        errs.append( {'code':2006 , 'message':"Data raw frame error", 'version':"1.2"} )
        # warnings        
        errs.append( {'code':-3	 , 'message':"Device temperature reaching high limit", 'version':"1.2"} )
        errs.append( {'code':-4	 , 'message':"Device temperature reaching low limit", 'version':"1.2"} )
        errs.append( {'code':-102 , 'message':"Disk almost full", 'version':"1.2"} )
        errs.append( {'code':-2003, 'message':"Data value not consistent", 'version':"1.2"} )
        # find the message        
        messages = [err['message'] for err in errs if err['code']==error_code]
        return messages[0]

    def get_monitoring_names(self, monitoring_name=""):
        """ Get the list of available monitoring names
        
        Inputs:
        -------
        Optional: A particular monitoring name

        Outputs:
        -------
        List of dictionaries of available monitoring names.
        If the optional particular monitoring name is specified as input then 
        return only the dictionary of that monitoring name. 
        
        Usage:
        ------
        >>> rep.get_monitoring_names("Wind_speed")
        >>> [{'monitoring_name': 'Wind_speed', 'section': 'weather', 'description': '', 'version': '1.1'}]
        
        Related topics:
        ---------------
        """
        monitors = []
        # Weather
        monitors .append( {'monitoring_name':"Temperature_outside", 'section':"weather", 'description':"Ambiant temperature", 'version':"1.1"} )
        monitors .append( {'monitoring_name':"Temperature_sky", 'section':"weather", 'description':"Cloud coverage", 'version':"1.1"} )
        monitors .append( {'monitoring_name':"Humidity_outside", 'section':"weather", 'description':"Ambiant humidity", 'version':"1.1"} )
        monitors .append( {'monitoring_name':"Pressure_outside", 'section':"weather", 'description':"Ambiant pressure (not corrected to sea level)", 'version':"1.1"} )
        monitors .append( {'monitoring_name':"Wind_speed", 'section':"weather", 'description':"", 'version':"1.1"} )
        monitors .append( {'monitoring_name':"Wind_direction", 'section':"weather", 'description':"0=N, 90=E", 'version':"1.1"} )
        monitors .append( {'monitoring_name':"Rain_boolean", 'section':"weather", 'description':"0=No rain, 1=Rain", 'version':"1.1"} )
        # Housing
        monitors .append( {'monitoring_name':"State_dome_shutter_east", 'section':"housing", 'description':'0=Closed 1=Opened 2=Intermediate3=Closing, 4=Opening, 5=Undefined', 'version':"1.2"} )
        monitors .append( {'monitoring_name':"State_dome_shutter_west", 'section':"housing", 'description':'0=Closed 1=Opened 2=Intermediate3=Closing, 4=Opening, 5=Undefined', 'version':"1.2"} )
        monitors .append( {'monitoring_name':"Direction_dome_shutter", 'section':"housing", 'description':'0=N, 90=E', 'version':"1.2"} )
        monitors .append( {'monitoring_name':"State_roof", 'section':"housing", 'description':'0=Closed 1=Opened 2=Intermediate	3=Closing, 4=Opening, 5=Undefined', 'version':"1.2"} )
        monitors .append( {'monitoring_name':"State_roof_north", 'section':"housing", 'description':'0=Closed 1=Opened 2=Intermediate	3=Closing, 4=Opening, 5=Undefined', 'version':"1.2"} )
        monitors .append( {'monitoring_name':"State_roof_south", 'section':"housing", 'description':'0=Closed 1=Opened 2=Intermediate 3=Closing, 4=Opening, 5=Undefined', 'version':"1.2"} )
        # Power supply
        monitors .append( {'monitoring_name':"Voltage_input", 'section':"powersupply", 'description':'', 'version':"1.2"} )
        monitors .append( {'monitoring_name':"Voltage_output", 'section':"powersupply", 'description':'', 'version':"1.2"} )
        # Instruments
        monitors .append( {'monitoring_name':"Temperature_mirror", 'section':"Instruments", 'description':'Mirrors temperatures (M1, M2, etc)', 'version':"1.2"} )
        monitors .append( {'monitoring_name':"Position_filterwheel", 'section':"Instruments", 'description':'', 'version':"1.2"} )
        monitors .append( {'monitoring_name':"Position_focuser", 'section':"Instruments", 'description':'Positions of focusers (M2, channel1, etc.)', 'version':"1.2"} )
        monitors .append( {'monitoring_name':"Temperature_sensor", 'section':"Instruments", 'description':'', 'version':"1.2"} )      
        # Image quality 
        monitors .append( {'monitoring_name':"PSF_FWHM", 'section':"Imagequality", 'description':'Image quality', 'version':"1.2"} )
        monitors .append( {'monitoring_name':"ZeroMag", 'section':"Imagequality", 'description':'Transparency', 'version':"1.2"} )
        monitors .append( {'monitoring_name':"SkyMag", 'section':"Imagequality", 'description':'Background brightness', 'version':"1.2"} )
        if monitoring_name!="":
            # find the message        
            print("Etape 1")
            dico = [monitor for monitor in monitors if monitor['monitoring_name']==monitoring_name]
            return dico
        return monitors
              
    def get_entities(self):
        """ Get the current entities
        
        Inputs:
        -------
        None.
        
        Usage:
        ------
        >>> report = report.Status_json()
        >>> print("{}",format(report.get_entities()))
        
        Related topics:
        ---------------
        """
        entities = []
        if self._status != "":
            entities = self._get_entity_names()
        return entities

    def get_devices(self, only_entity_name=""):
        """ Get the current devices
        
        Inputs:
        -------
        None or a device name to check if exists.
        
        Usage:
        ------
        >>> report = report.Status_json()
        >>> print("{}",format(report.get_devices()))
        
        Related topics:
        ---------------
        """
        res = []
        if self._status != "":
            entities = self._get_entity_names()
            for entity_name in entities:
                devices = []
                if (only_entity_name==""):                    
                    devices = self._get_device_nameserials(entity_name)
                else:
                    if (only_entity_name==entity_name):
                        devices = self._get_device_nameserials(entity_name)
                for device in devices:
                    re = [entity_name, device['device_name'], device['serial_number']]
                    res.append(re)
        return res

    def get_ufkis(self, only_device_name="", only_serial_number="", getvalue=False):
        """ Get the current values
        
        Inputs:
        -------
        None or a device name + serial number + value to check if exists.
        
        Usage:
        ------
        >>> report = report.Status_json()
        >>> print("{}",format(report.get_devices()))
        >>> print("{}",format(report.get_ufkis("","",True))
        
        Related topics:
        ---------------
        """
        res = []
        if self._status != "":
            entities = self._get_entity_names()
            for entity_name in entities:        
                devices = self._get_device_nameserials(entity_name)
                for device in devices:
                    device_name = device['device_name']
                    serial_number = device['serial_number']
                    value_names = []
                    if (only_device_name=="") or (only_serial_number==""):                        
                        value_names = self._get_value_names(entity_name, device_name, serial_number)
                    else:
                        if (only_device_name==device_name) or (only_serial_number==serial_number):                        
                            value_names = self._get_value_names(entity_name, device_name, serial_number)
                    for value_name in value_names:
                        if getvalue==False:
                            re = [entity_name, device_name, serial_number, value_name]
                        else:
                            val = self._get_value_name_values(entity_name, device_name, serial_number, value_name)
                            re = [entity_name, device_name, serial_number, value_name, val]
                        res.append(re)
        return res

    def get_sensors(self, only_device_name="", only_serial_number="", getvalue=False):
        """ Get the current values. Alias of get_ufkis.
        """
        return self.get_ufkis(only_device_name, only_serial_number, getvalue);
        
    def get_values(self, only_device_name="", only_serial_number="", getvalue=False):
        """ Get the current values. Alias of get_ufkis.
        """
        return self.get_ufkis(only_device_name, only_serial_number, getvalue);
        

# ========================================================
# === debug methods
# ========================================================
    
    def infos(self, action) -> None:
        """ To get informations about this class
        
        :param action: A command to run a debug action (see examples).
        :type action: string
        
        :Example:
            
        Status_json().infos("doctest")
        Status_json().infos("doc_methods")
        Status_json().infos("internal_attributes")
        Status_json().infos("public_methods")        
        """
        if (action == "doc_methods"):
            publics = [x for x in dir(self) if x[0]!="_"]
            for public in publics:
                varname = "{}".format(public)
                if (callable(getattr(self,varname))==True):
                    print("\n{:=^40}".format(" method "+varname+" "))
                    t = "Angle()."+varname+".__doc__"
                    tt =eval(t)
                    print(tt)
        if (action == "doctest"):
            if __name__ == "__main__":
                print("\n{:~^40}".format("doctest"))
                #doctest.testmod(verbose=True, extraglobs={'objangle': Angle()})
                doctest.testmod(verbose=True)
        if (action == "internal_attributes"):
            internals = [x for x in dir(self) if x[0]=="_" and x[1]!="_"]
            for internal in internals:
                varname = "{}".format(internal)
                #if (hasattr(self,varname)==True):
                if (callable(getattr(self,varname))==False):
                    print(varname + "=" + str(getattr(self,varname)))
        if (action == "public_methods"):
            publics = [x for x in dir(self) if x[0]!="_"]
            for public in publics:
                varname = "{}".format(public)
                if (callable(getattr(self,varname))==True):
                    print(varname)


# ========================================================
# === special methods
# ========================================================
        
    def __init__(self, status=""):
        """ Object initialization where angle is the input in any format.

        :param angle : An angle in any supported format (cf. help(Angle))
        :type angle : string
        
        """
        self._init(status)

# ========================================================
# ========================================================
# ========================================================

# Examples of execution

if __name__ == "__main__":
        
    # --- update the path of Python if necessary
    
    import report
    
    # ===============================
    # --- Write a very sipmle Json
    # ===============================
    print("Make a new report")
    rep = report.Status_json()
    rep.new_status("PLC","20180909")
    rep.append_entity("PLC_STATUS", "Raspberry", "20180924A", "MyObservatory")
    # --- one device with one value
    rep.append_device("DHT22", "meteo", "1", "0")
    rep.append_value(  "OutsideTemperature",  "float","22","degC","Temperature_outside","Temperature","now")
    # --- List the UFKIs
    ufkis = rep.get_ufkis("","",False)
    print(" List of all UFKIs:")
    for ufki in ufkis:
        print("  UFKI = {}".format(ufki))
    # --- save the Json file
    rep.save_json("plc_verysimple.json")
    
    # ===============================
    # --- Write a more complex Json
    # ===============================
    print("Make a new report")
    rep = report.Status_json()
    rep.new_status("PLC","20180909")
    rep.append_entity("PLC_STATUS", "Raspberry", "20180924A", "Guitalens Observatory")
    # --- device Came
    rep.append_device("Came", "roof_controler", "124", "0")
    rep.append_value(  "Error_code",  "int","0","","","0=OK 1=PowerPB 2=SwitchPB","now")
    rep.append_value(  "Power_input", "int","0","","","0=0Volt 1=24Volts","now")
    rep.append_value(  "Mode_came",   "int","0","","","0=Manual 1=Auto","now")
    rep.append_value(  "Roof_state",  "int","0","","","0=Closed 1=Opened 2=Intermediate","now")
    # --- device CV7
    rep.append_device("CV7", "weather_station", "RET6789", "0")
    rep.append_value(  "Error_code",  "int","0","","","0=OK 1=SerialPB 2=FramePB","now")
    rep.append_value(  "Power_input",  "int","0","","","0=0Volt 1=12Volts (Power from MiFe board)","now")
    rep.append_value(  "Wind_dir",  "float","0","degrees","Wind_direction","0=North 90=East","now")
    rep.append_value(  "Wind_speed",  "float","0","m/s","Wind_spped","Wind speed from ultrasonic sensors","now")
    rep.append_value(  "OutsideTemperature",  "float","0","degC","Temperature_outside","Temperature of the anemometer","now")
    # --- device DHT22
    rep.append_device("DHT22", "weather_station", "123", "0")
    rep.append_value(  "Error_code",  "int","0","","","0=OK 1=CheksumPB 2=LengthPB 3=NodataPB","now")
    rep.append_value(  "Temperature",  "float","21","degC","temperature","Temperature inside PLX box","now")
    rep.append_value(  "Humidity",  "float","77","percent","humidity","Humidity inside PLX box","now")
    # --- device RG11
    rep.append_device("RG11", "weather_station", "TY67", "0")
    rep.append_value(  "Error_code",  "int","0","","","0=OK +1=PowerPB +2=NopowerPB +4=AllonePB","now")
    rep.append_value(  "RainSate",  "int","0","","rain","0=Dry 1=Rain 2=Unknown","now")
    # --- device MLX90614
    rep.append_device("MLX90614", "weather_station", "1", "0")
    rep.append_value(  "Error_code",  "int","0","","","0=OK 1=DataPB","now")
    rep.append_value(  "SkyTemperature",  "float","-15.67","degC","Temperature_sky","Temperature of the sky","now")
    rep.append_value(  "CanTemperature",  "float","22.47","degC","","Temperature of the TO can","now")
    # --- List the UFKIs
    ufkis = rep.get_ufkis("","",False)
    print(" List of all UFKIs:")
    for ufki in ufkis:
        print("  UFKI = {}".format(ufki))
    # --- save the Json file
    rep.save_json("plc_guitalens.json")
    
    # ===============================
    # --- Read an existing Json
    # ===============================
    rep = report.Status_json()
    path_filename = "plc_verysimple.json"
    print("Analysis of the file {}:".format(path_filename))
    rep.load_json(path_filename)
    res = rep.get_entities()
    print(" entities = {}".format(res))
    res = rep.get_devices()
    print(" devices = {}".format(res))
    print(" List of all UFKIs:")
    ufkis = rep.get_ufkis("","",True)
    for ufki in ufkis:
        print("  UFKI = {}".format(ufki))