import json
from relay_api.core.relay import relay
from relay_api.conf.config import relays


def init_relays():
    for r in relays:
        relays[r]["object"] = relay(relays[r]["gpio"])
        relays[r]["state"] = relays[r]["object"].get_state()


def get_all_relays():
    relays_dict = __get_relay_dict()
    return json.dumps(relays_dict)


def get_relay(relay_name):
    if relay_name not in relays:
        return None
    relay_dict = __get_relay_dict(relay_name)
    return json.dumps(relay_dict)


def __get_relay_dict(relay_name=None):
    if relay_name:
        relay_dict = dict.copy(relays["relay_name"])
        del(relay_dict["object"])
        return relay_dict
    relays_dict = dict.copy(relays)
    for r in relays_dict:
        del(relays_dict[r]["object"])
    return relays_dict

import json
from relay_api.core.relay import relay
from relay_api.conf.config import relays


def init_relays():
    for r in relays:
        relays[r]["object"] = relay(relays[r]["gpio"])
        relays[r]["state"] = relays[r]["object"].get_state()


def get_all_relays():
    relays_dict = __get_relay_dict()
    return json.dumps(relays_dict, indent=4)


def get_relay(relay_name):
    if relay_name not in relays:
        return None
    relay_dict = __get_relay_dict(relay_name)
    return json.dumps(relay_dict, indent=4)


def __get_relay_dict(relay_name=None):
    if relay_name:
        relay_dict = dict.copy(relays["relay_name"])
        del(relay_dict["object"])
        return relay_dict
    relays_dict = dict.copy(relays)
    for r in relays_dict:
        del(relays_dict[r]["object"])
    return relays_dict

Add indent in json to improve debugging
Add indent in json to improve debugging

  import json
  from relay_api.core.relay import relay
  from relay_api.conf.config import relays
  
  
  def init_relays():
      for r in relays:
          relays[r]["object"] = relay(relays[r]["gpio"])
          relays[r]["state"] = relays[r]["object"].get_state()
  
  
  def get_all_relays():
      relays_dict = __get_relay_dict()
-     return json.dumps(relays_dict)
+     return json.dumps(relays_dict, indent=4)
  
  
  def get_relay(relay_name):
      if relay_name not in relays:
          return None
      relay_dict = __get_relay_dict(relay_name)
-     return json.dumps(relay_dict)
+     return json.dumps(relay_dict, indent=4)
  
  
  def __get_relay_dict(relay_name=None):
      if relay_name:
          relay_dict = dict.copy(relays["relay_name"])
          del(relay_dict["object"])
          return relay_dict
      relays_dict = dict.copy(relays)
      for r in relays_dict:
          del(relays_dict[r]["object"])
      return relays_dict
  
Add indent in json to improve debugging
## Code Before:
import json
from relay_api.core.relay import relay
from relay_api.conf.config import relays


def init_relays():
    for r in relays:
        relays[r]["object"] = relay(relays[r]["gpio"])
        relays[r]["state"] = relays[r]["object"].get_state()


def get_all_relays():
    relays_dict = __get_relay_dict()
    return json.dumps(relays_dict)


def get_relay(relay_name):
    if relay_name not in relays:
        return None
    relay_dict = __get_relay_dict(relay_name)
    return json.dumps(relay_dict)


def __get_relay_dict(relay_name=None):
    if relay_name:
        relay_dict = dict.copy(relays["relay_name"])
        del(relay_dict["object"])
        return relay_dict
    relays_dict = dict.copy(relays)
    for r in relays_dict:
        del(relays_dict[r]["object"])
    return relays_dict

## Instruction:
Add indent in json to improve debugging
## Code After:
import json
from relay_api.core.relay import relay
from relay_api.conf.config import relays


def init_relays():
    for r in relays:
        relays[r]["object"] = relay(relays[r]["gpio"])
        relays[r]["state"] = relays[r]["object"].get_state()


def get_all_relays():
    relays_dict = __get_relay_dict()
    return json.dumps(relays_dict, indent=4)


def get_relay(relay_name):
    if relay_name not in relays:
        return None
    relay_dict = __get_relay_dict(relay_name)
    return json.dumps(relay_dict, indent=4)


def __get_relay_dict(relay_name=None):
    if relay_name:
        relay_dict = dict.copy(relays["relay_name"])
        del(relay_dict["object"])
        return relay_dict
    relays_dict = dict.copy(relays)
    for r in relays_dict:
        del(relays_dict[r]["object"])
    return relays_dict
