import warnings


def calc_dimless_tes_th_flex(sh_dem, dhw_dem, en_av_tes):
    """
    Calculate dimensionless thermal storage flexibility beta_th

    Parameters
    ----------
    sh_dem : float
        Annual space heating demand in kWh
    dhw_dem : float
        Annual hot water demand in kWh
    en_av_tes : float
        Average stored usable amount of thermal energy within TES for a
        whole year in kWh

    Returns
    -------
    beta_th : float
        Dimensionless thermal storage flexibility
    """
    assert sh_dem >= 0
    assert dhw_dem >= 0
    assert en_av_tes >= 0

    if sh_dem + dhw_dem == 0:
        msg = 'Cannot calculate beta_th, as thermal demands are zero!' \
              ' Going to return None.'
        warnings.warn(msg)
        beta_th = None
    else:
        #  Calculate beta_th
        beta_th = en_av_tes / ((sh_dem + dhw_dem) / 365)

    return beta_th