CA Civ Pro Code § 1174.2 (2021)
2021 California Code|Code of Civil Procedure - CCP|PART 3 - OF SPECIAL PROCEEDINGS OF A CIVIL NATURE|TITLE 3 - OF SUMMARY PROCEEDINGS|CHAPTER 4 - Summary Proceedings for Obtaining Possession of Real Property in Certain Cases|Section 1174.2.

1174.2.  (a) In an unlawful detainer proceeding involving residential premises after default in payment of rent and in which the tenant has raised as an affirmative defense a breach of the landlord’s obligations under Section 1941 of the Civil Code or of any warranty of habitability, the court shall determine whether a substantial breach of these obligations has occurred. If the court finds that a substantial breach has occurred, the court (1) shall determine the reasonable rental value of the premises in its untenantable state to the date of trial, (2) shall deny possession to the landlord and adjudge the tenant to be the prevailing party, conditioned upon the payment by the tenant of the rent that has accrued to the date of the trial as adjusted pursuant to this subdivision within a reasonable period of time not exceeding five days, from the date of the court’s judgment or, if service of the court’s judgment is made by mail, the payment shall be made within the time set forth in Section 1013, (3) may order the landlord to make repairs and correct the conditions which constitute a breach of the landlord’s obligations, (4) shall order that the monthly rent be limited to the reasonable rental value of the premises as determined pursuant to this subdivision until repairs are completed, and (5) except as otherwise provided in subdivision (b), shall award the tenant costs and attorneys’ fees if provided by, and pursuant to, any statute or the contract of the parties. If the court orders repairs or corrections, or both, pursuant to paragraph (3), the court’s jurisdiction continues over the matter for the purpose of ensuring compliance. The court shall, however, award possession of the premises to the landlord if the tenant fails to pay all rent accrued to the date of trial, as determined due in the judgment, within the period prescribed by the court pursuant to this subdivision. The tenant shall, however, retain any rights conferred by Section 1174.(b) If the court determines that there has been no substantial breach of Section 1941 of the Civil Code or of any warranty of habitability by the landlord or if the tenant fails to pay all rent accrued to the date of trial, as required by the court pursuant to subdivision (a), then judgment shall be entered in favor of the landlord, and the landlord shall be the prevailing party for the purposes of awarding costs or attorneys’ fees pursuant to any statute or the contract of the parties.(c) As used in this section, “substantial breach” means the failure of the landlord to comply with applicable building and housing code standards which materially affect health and safety.(d) Nothing in this section is intended to deny the tenant the right to a trial by jury. Nothing in this section shall limit or supersede any provision of Chapter 12.75 (commencing with Section 7060) of Division 7 of Title 1 of the Government Code.(Amended by Stats. 1993, Ch. 589, Sec. 28. Effective January 1, 1994.)