@@ -851,3 +851,56 @@ async def test_settings_api(api):
851851 await api .fs .delete ('sfile' )
852852
853853 await api .print ('Test finished successfully' )
854+
855+
856+ async def test_redstone_api (api ):
857+ tbl = await get_object_table (api , 'redstone' )
858+
859+ # remove British method names to make API lighter
860+ del tbl ['function' ]['getAnalogueInput' ]
861+ del tbl ['function' ]['getAnalogueOutput' ]
862+ del tbl ['function' ]['setAnalogueOutput' ]
863+
864+ assert get_class_table (api .redstone .__class__ ) == tbl
865+
866+ assert set (await api .redstone .getSides ()) == {'top' , 'bottom' , 'front' , 'back' , 'left' , 'right' }
867+
868+ await step (api , 'Remove all the redstone from sides of computer' )
869+
870+ side = 'top'
871+
872+ assert await api .redstone .setOutput (side , True ) is None
873+ assert await api .redstone .getOutput (side ) is True
874+ assert await api .redstone .getAnalogOutput (side ) == 15
875+ assert await api .redstone .setOutput (side , False ) is None
876+ assert await api .redstone .getOutput (side ) is False
877+ assert await api .redstone .getAnalogOutput (side ) == 0
878+
879+ assert await api .redstone .setAnalogOutput (side , 7 ) is None
880+ assert await api .redstone .getAnalogOutput (side ) == 7
881+ assert await api .redstone .getOutput (side ) is True
882+ assert await api .redstone .setAnalogOutput (side , 15 ) is None
883+ assert await api .redstone .getAnalogOutput (side ) == 15
884+ assert await api .redstone .setAnalogOutput (side , 0 ) is None
885+ assert await api .redstone .getAnalogOutput (side ) == 0
886+ assert await api .redstone .getOutput (side ) is False
887+
888+ assert await api .redstone .getInput (side ) is False
889+ assert await api .redstone .getAnalogInput (side ) == 0
890+
891+ await step (api , f'Put redstone block on { side } side of computer' )
892+
893+ assert await api .redstone .getInput (side ) is True
894+ assert await api .redstone .getAnalogInput (side ) > 0
895+
896+ await step (api , f'Remove redstone block\n Put piston on { side } side of computer' )
897+
898+ assert await api .redstone .getInput (side ) is False
899+ assert await api .redstone .getAnalogInput (side ) == 0
900+ assert await api .redstone .setOutput (side , True ) is None
901+ await asyncio .sleep (2 )
902+ assert await api .redstone .setOutput (side , False ) is None
903+
904+ await api .print ('Piston must have been activated\n Remove piston' )
905+
906+ await api .print ('Test finished successfully' )
0 commit comments