import asyncio from app.auto.controller import AutoController class FakeTionController: def __init__(self): self.calls = [] async def heater_on(self): self.calls.append( ("heater_on", None) ) async def heater_off(self): self.calls.append( ("heater_off", None) ) class FakeTionService: def __init__(self): self.controller = ( FakeTionController() ) async def execute( self, operation, ): return await operation( self.controller ) def make_controller(): tion = FakeTionService() controller = AutoController( schedule_service=None, qingping_service=None, tion_service=tion, ) return controller, tion async def test_heater_on(): controller, tion = ( make_controller() ) await controller._set_heater( True ) assert tion.controller.calls == [ ("heater_on", None) ] assert ( controller._target_heater is True ) async def test_duplicate_heater_on(): controller, tion = ( make_controller() ) await controller._set_heater( True ) await controller._set_heater( True ) assert tion.controller.calls == [ ("heater_on", None) ] async def test_heater_off_after_on(): controller, tion = ( make_controller() ) await controller._set_heater( True ) await controller._set_heater( False ) assert tion.controller.calls == [ ("heater_on", None), ("heater_off", None), ] assert ( controller._target_heater is False ) async def test_duplicate_heater_off(): controller, tion = ( make_controller() ) await controller._set_heater( False ) await controller._set_heater( False ) assert tion.controller.calls == [ ("heater_off", None) ] async def main(): await test_heater_on() await test_duplicate_heater_on() await test_heater_off_after_on() await test_duplicate_heater_off() print() print("=" * 70) print( "ALL AUTO HEATER COMMAND " "TESTS PASSED" ) print("=" * 70) if __name__ == "__main__": asyncio.run(main())