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

import json
import copy
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 = copy.deepcopy(relays[relay_name])
        del(relay_dict["object"])
        return relay_dict
    relays_dict = copy.deepcopy(relays)
    for r in relays_dict:
        del(relays_dict[r]["object"])
    return relays_dict

Use deppcopy to copy dicts
Use deppcopy to copy dicts
